public static ServiceControllerStatus GetStatus(this LsbLinuxServiceController target) { var monoProcesses = LinuxProcess.GetProcessesByName("mono"); foreach (var monoProcess in monoProcesses) { var arguments = monoProcess.CommandLine; if (!string.IsNullOrWhiteSpace(arguments)) { var argumentValues = ParseCommandLine(arguments); object name; argumentValues.TryGetValue("servicename", out name); object instance; argumentValues.TryGetValue("instance", out instance); if (!string.IsNullOrEmpty(name as string)) { var serviceName = string.IsNullOrEmpty(instance as string) ? (string)name : $"{name}@{instance}"; if (string.Equals(target.ServiceName, serviceName, StringComparison.OrdinalIgnoreCase)) { return(ServiceControllerStatus.Running); } } } } return(ServiceControllerStatus.Stopped); }
public void StopService(string serviceName, TimeSpan timeout) { var service = LsbLinuxServiceController.GetService(serviceName); if (service == null) { throw new InvalidOperationException(string.Format(Resources.ServiceHasntInstalled, serviceName)); } try { service.Stop(timeout); } catch (Exception error) { _logWriter.Error(error.Message, error); } }
public bool IsServiceStopped(string serviceName) { var service = LsbLinuxServiceController.GetService(serviceName); return(service == null || service.GetStatus() == ServiceControllerStatus.Stopped); }
public bool IsServiceInstalled(string serviceName) { var service = LsbLinuxServiceController.GetService(serviceName); return(service != null); }