private void ReloadDaemon() { var output = terminal.Execute(new ProcessInput { ShellName = "/bin/bash", Command = $"systemctl daemon-reload" }); if (output.ExitCode != 0) { throw new SystemManagerException(string.Join(Environment.NewLine, output.StandardError)); } }
public void Restart() { if (systemInformation.GetOSInfo().Platform == OSPlatformType.Windows) { terminal.Execute(new ProcessInput { Command = "shutdown -r -f -t 0", ShellName = "cmd" }); } else if (systemInformation.GetOSInfo().Platform == OSPlatformType.Linux) { terminal.Execute(new ProcessInput { Command = "systemctl reboot", ShellName = "/bin/bash" }); } else { throw new Exception("Cannot restart for this OS"); } }
private string OSPrettyName() { if (!string.IsNullOrEmpty(_OSPrettyName?.Trim())) { return(_OSPrettyName); } string mbInfo = string.Empty; ProcessOutput result = null; if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return(RuntimeInformation.OSDescription); } //Raspberry, Linux (Fedora Tested, Debian) else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { // Act result = ioTerminal.Execute(new ProcessInput { Command = @"cat /etc/os-release | grep PRETTY_NAME | cut -d ""="" -f2 | tail -c +2 | head -c -2", ShellName = "/bin/bash", Arguments = "" }); result.StandardOutput = result.StandardOutput.Where(o => o?.Trim()?.Equals("") != true).ToArray(); // Assert } string osPretyName = string.Join("", result?.StandardOutput)?.Trim(); if (!string.IsNullOrEmpty(osPretyName)) { this._OSPrettyName = osPretyName; return(osPretyName); } else { return(null); } }
private ServiceState GetServiceState(string serviceName) { serviceName = serviceName?.EndsWith(".service") == true ? serviceName : serviceName + ".service"; ProcessOutput output = terminal.Execute(new ProcessInput { Command = $"systemctl status '{serviceName}'", ShellName = "/bin/bash", }); if (output.StandardOutput.Count() > 1) { var outLine = output.StandardOutput.LastOrDefault(o => o.ToLower().Contains("failed") || o.ToLower().Contains("(failed)") ); if (outLine != null) { return(ServiceState.Failed); } outLine = output.StandardOutput.LastOrDefault(o => o.ToLower().Contains("(running)")); if (outLine != null) { return(ServiceState.Running); } outLine = output.StandardOutput.LastOrDefault(o => o.ToLower().Contains("(exited)")); if (outLine != null) { return(ServiceState.Stopped); } return(ServiceState.Unknown); } else { return(ServiceState.Unknown); } }
public void NC_IOTerminal_Execute() { // Arrange var systemInformation = container.Resolve <NetStandard.SystemInformation.ISystemInformation>(); ProcessOutput result = null; if (systemInformation.GetOSInfo().Platform == SystemInformation.OSPlatformType.Windows) { // Act IIOTerminal iOTerminal = this.CreateIOTerminal(); result = iOTerminal.Execute(new ProcessInput { Command = "Get-WmiObject Win32_BaseBoard | Format-Wide -Property SerialNumber", ShellName = "powershell", Arguments = "-OutputFormat Text -InputFormat Text -File -" }); result.StandardOutput = result.StandardOutput.Skip(1).SkipLast(1) .Where(o => o?.Trim()?.Equals("") != true).ToArray(); // Assert } else if (systemInformation.GetOSInfo().Platform == SystemInformation.OSPlatformType.Linux) { // Act IIOTerminal iOTerminal = this.CreateIOTerminal(); result = iOTerminal.Execute(new ProcessInput { Command = "/sys/devices/virtual/dmi/id/board_serial", ShellName = "/bin/bash", Arguments = "" }); result.StandardOutput = result.StandardOutput.Skip(1).SkipLast(1) .Where(o => o?.Trim()?.Equals("") != true).ToArray(); // Assert } Console.WriteLine(string.Join(",", result.StandardOutput)); Assert.AreNotEqual(result.StandardOutput, 0); }