public ServiceInformation GetService(string serviceName) { ServiceInformation si = null; var osInfo = systemInformation.GetOSInfo(); //Window if (osInfo.Platform == OSPlatformType.Windows) { var service = new ServiceController(serviceName); if (ExistsService(service)) { si = GetService(service); } } else if (osInfo.Platform == OSPlatformType.Linux) { si = GetServiceWithListUnits(serviceName); if (si == null) { si = GetServiceWithListUnitsFile(serviceName); if (si != null) { si.Description = "Not available"; si.State = GetServiceState(serviceName); } } } return(si); }
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"); } }
public void Create(string serviceName, string binPath, ServiceCreateOptions serviceCreateOptions) { serviceManagerFactory .Create(systemInformation.GetOSInfo().Platform) .Create(serviceName, binPath, serviceCreateOptions); }