Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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");
     }
 }
Esempio n. 3
0
 public void Create(string serviceName, string binPath, ServiceCreateOptions serviceCreateOptions)
 {
     serviceManagerFactory
     .Create(systemInformation.GetOSInfo().Platform)
     .Create(serviceName, binPath, serviceCreateOptions);
 }