mirror of
https://github.com/Jackett/Jackett.git
synced 2025-09-17 17:34:09 +02:00
Add back Windows Service functionality
This commit is contained in:
@@ -1,28 +1,27 @@
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration.Install;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.ServiceProcess;
|
||||
using Jackett.Common.Services.Interfaces;
|
||||
|
||||
namespace Jackett.Services
|
||||
namespace Jackett.Server.Services
|
||||
{
|
||||
|
||||
public class ServiceConfigService : IServiceConfigService
|
||||
{
|
||||
private const string NAME = "Jackett";
|
||||
private const string DESCRIPTION = "Additional indexers for Sonarr";
|
||||
private const string DESCRIPTION = "API Support for your favorite torrent trackers";
|
||||
private const string SERVICEEXE = "JackettService.exe";
|
||||
|
||||
private IConfigurationService configService;
|
||||
private IProcessService processService;
|
||||
private Logger logger;
|
||||
|
||||
public ServiceConfigService(IConfigurationService c, Logger l)
|
||||
public ServiceConfigService(IConfigurationService c, IProcessService p, Logger l)
|
||||
{
|
||||
configService = c;
|
||||
processService = p;
|
||||
logger = l;
|
||||
}
|
||||
|
||||
@@ -65,30 +64,17 @@ namespace Jackett.Services
|
||||
}
|
||||
else
|
||||
{
|
||||
var installer = new ServiceProcessInstaller
|
||||
{
|
||||
Account = ServiceAccount.LocalSystem
|
||||
};
|
||||
|
||||
var serviceInstaller = new ServiceInstaller();
|
||||
|
||||
var exePath = Path.Combine(configService.ApplicationFolder(), SERVICEEXE);
|
||||
if (!File.Exists(exePath) && Debugger.IsAttached)
|
||||
{
|
||||
exePath = Path.Combine(configService.ApplicationFolder(), "..\\..\\..\\Jackett.Service\\bin\\Debug", SERVICEEXE);
|
||||
}
|
||||
|
||||
string[] cmdline = { @"/assemblypath=" + exePath};
|
||||
string arg = $"create {NAME} start= auto binpath= \"{exePath}\" DisplayName= {NAME}";
|
||||
|
||||
var context = new InstallContext("jackettservice_install.log", cmdline);
|
||||
serviceInstaller.Context = context;
|
||||
serviceInstaller.DisplayName = NAME;
|
||||
serviceInstaller.ServiceName = NAME;
|
||||
serviceInstaller.Description = DESCRIPTION;
|
||||
serviceInstaller.StartType = ServiceStartMode.Automatic;
|
||||
serviceInstaller.Parent = installer;
|
||||
processService.StartProcessAndLog("sc.exe", arg, true);
|
||||
|
||||
serviceInstaller.Install(new ListDictionary());
|
||||
processService.StartProcessAndLog("sc.exe", $"description {NAME} \"{DESCRIPTION}\"", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +82,7 @@ namespace Jackett.Services
|
||||
{
|
||||
RemoveService();
|
||||
|
||||
var serviceInstaller = new ServiceInstaller();
|
||||
var context = new InstallContext("jackettservice_uninstall.log", null);
|
||||
serviceInstaller.Context = context;
|
||||
serviceInstaller.ServiceName = NAME;
|
||||
serviceInstaller.Uninstall(null);
|
||||
processService.StartProcessAndLog("sc.exe", $"delete {NAME}", true);
|
||||
|
||||
logger.Info("The service was uninstalled.");
|
||||
}
|
||||
@@ -120,12 +102,18 @@ namespace Jackett.Services
|
||||
|
||||
service.Refresh();
|
||||
if (service.Status == ServiceControllerStatus.Stopped)
|
||||
{
|
||||
logger.Info("Service stopped.");
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Error("Failed to stop the service");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.Warn("The service was already stopped");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user