Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public bool IsServiceStopped(string serviceName)
        {
            var service = LsbLinuxServiceController.GetService(serviceName);

            return(service == null || service.GetStatus() == ServiceControllerStatus.Stopped);
        }
Пример #4
0
        public bool IsServiceInstalled(string serviceName)
        {
            var service = LsbLinuxServiceController.GetService(serviceName);

            return(service != null);
        }