Пример #1
0
        public void Route(ApplicationModes applicationModes)
        {
            _logger.Info("Application mode: {0}", applicationModes);

            switch (applicationModes)
            {
            case ApplicationModes.InstallService:
            {
                _logger.Debug("Install Service selected");
                if (_serviceProvider.ServiceExist(ServiceProvider.SERVICE_NAME))
                {
                    _consoleService.PrintServiceAlreadyExist();
                }
                else
                {
                    _remoteAccessAdapter.MakeAccessible(true);
                    _serviceProvider.Install(ServiceProvider.SERVICE_NAME);
                    _serviceProvider.SetPermissions(ServiceProvider.SERVICE_NAME);

                    // Start the service and exit.
                    // Ensures that there isn't an instance of Readarr already running that the service account cannot stop.
                    _processProvider.SpawnNewProcess("sc.exe", $"start {ServiceProvider.SERVICE_NAME}", null, true);
                }

                break;
            }

            case ApplicationModes.UninstallService:
            {
                _logger.Debug("Uninstall Service selected");
                if (!_serviceProvider.ServiceExist(ServiceProvider.SERVICE_NAME))
                {
                    _consoleService.PrintServiceDoesNotExist();
                }
                else
                {
                    _serviceProvider.Uninstall(ServiceProvider.SERVICE_NAME);
                }

                break;
            }

            case ApplicationModes.RegisterUrl:
            {
                _logger.Debug("Regiser URL selected");
                _remoteAccessAdapter.MakeAccessible(false);

                break;
            }

            default:
            {
                _consoleService.PrintHelp();
                break;
            }
            }
        }
Пример #2
0
        public void Terminate(int processId)
        {
            if (OsInfo.IsWindows)
            {
                _logger.Info("Stopping all running services");

                if (_serviceProvider.ServiceExist(ServiceProvider.SERVICE_NAME) &&
                    _serviceProvider.IsServiceRunning(ServiceProvider.SERVICE_NAME))
                {
                    try
                    {
                        _logger.Info("NzbDrone Service is installed and running");
                        _serviceProvider.Stop(ServiceProvider.SERVICE_NAME);
                    }
                    catch (Exception e)
                    {
                        _logger.Error(e, "couldn't stop service");
                    }
                }

                _logger.Info("Killing all running processes");

                _processProvider.KillAll(ProcessProvider.LIDARR_CONSOLE_PROCESS_NAME);
                _processProvider.KillAll(ProcessProvider.LIDARR_PROCESS_NAME);
            }
            else
            {
                _logger.Info("Killing all running processes");

                _processProvider.KillAll(ProcessProvider.LIDARR_CONSOLE_PROCESS_NAME);
                _processProvider.KillAll(ProcessProvider.LIDARR_PROCESS_NAME);

                _processProvider.Kill(processId);
            }
        }
Пример #3
0
        public void Terminate(int processId)
        {
            if (OsInfo.IsMono)
            {
                _logger.Info("Stopping all instances");
                _processProvider.Kill(processId);
                _processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
                _processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME);

                return;
            }

            _logger.Info("Stopping all running services");

            if (_serviceProvider.ServiceExist(ServiceProvider.NZBDRONE_SERVICE_NAME) &&
                _serviceProvider.IsServiceRunning(ServiceProvider.NZBDRONE_SERVICE_NAME))
            {
                try
                {
                    _logger.Info("NzbDrone Service is installed and running");
                    _serviceProvider.Stop(ServiceProvider.NZBDRONE_SERVICE_NAME);
                }
                catch (Exception e)
                {
                    _logger.ErrorException("couldn't stop service", e);
                }
            }

            _logger.Info("Killing all running processes");

            _processProvider.KillAll(ProcessProvider.NZB_DRONE_CONSOLE_PROCESS_NAME);
            _processProvider.KillAll(ProcessProvider.NZB_DRONE_PROCESS_NAME);
        }