mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-24 22:35:39 -04:00
Shutdown! Restart working for services
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using NLog;
|
||||
using NzbDrone.Common.Instrumentation;
|
||||
using NzbDrone.Common.Processes;
|
||||
|
||||
namespace NzbDrone.Common
|
||||
{
|
||||
@@ -20,14 +21,22 @@ namespace NzbDrone.Common
|
||||
void Stop(string serviceName);
|
||||
void Start(string serviceName);
|
||||
ServiceControllerStatus GetStatus(string serviceName);
|
||||
void Restart(string serviceName);
|
||||
}
|
||||
|
||||
public class ServiceProvider : IServiceProvider
|
||||
{
|
||||
public const string NZBDRONE_SERVICE_NAME = "NzbDrone";
|
||||
|
||||
private readonly IProcessProvider _processProvider;
|
||||
|
||||
private static readonly Logger Logger = NzbDroneLogger.GetLogger();
|
||||
|
||||
public ServiceProvider(IProcessProvider processProvider)
|
||||
{
|
||||
_processProvider = processProvider;
|
||||
}
|
||||
|
||||
public virtual bool ServiceExist(string name)
|
||||
{
|
||||
Logger.Debug("Checking if service {0} exists.", name);
|
||||
@@ -173,5 +182,12 @@ namespace NzbDrone.Common
|
||||
Logger.Error("Service start request has timed out. {0}", service.Status);
|
||||
}
|
||||
}
|
||||
|
||||
public void Restart(string serviceName)
|
||||
{
|
||||
var args = String.Format("/C net.exe stop \"{0}\" && net.exe start \"{0}\"", serviceName);
|
||||
|
||||
_processProvider.Start("cmd.exe", args);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user