mirror of
https://github.com/Radarr/Radarr
synced 2025-02-26 08:02:56 +00:00
New: Write PID file to AppData directory on Linux/OS X
This commit is contained in:
parent
9c0fb34864
commit
2dbc038d17
5 changed files with 46 additions and 6 deletions
|
@ -1,9 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using System.Text;
|
|
||||||
using NLog;
|
using NLog;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
|
|
|
@ -103,6 +103,7 @@
|
||||||
<Compile Include="Messaging\IMessage.cs" />
|
<Compile Include="Messaging\IMessage.cs" />
|
||||||
<Compile Include="PathEqualityComparer.cs" />
|
<Compile Include="PathEqualityComparer.cs" />
|
||||||
<Compile Include="Processes\INzbDroneProcessProvider.cs" />
|
<Compile Include="Processes\INzbDroneProcessProvider.cs" />
|
||||||
|
<Compile Include="Processes\PidFileProvider.cs" />
|
||||||
<Compile Include="Processes\ProcessOutput.cs" />
|
<Compile Include="Processes\ProcessOutput.cs" />
|
||||||
<Compile Include="RateGate.cs" />
|
<Compile Include="RateGate.cs" />
|
||||||
<Compile Include="Serializer\IntConverter.cs" />
|
<Compile Include="Serializer\IntConverter.cs" />
|
||||||
|
|
44
src/NzbDrone.Common/Processes/PidFileProvider.cs
Normal file
44
src/NzbDrone.Common/Processes/PidFileProvider.cs
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using NLog;
|
||||||
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
|
|
||||||
|
namespace NzbDrone.Common.Processes
|
||||||
|
{
|
||||||
|
public interface IProvidePidFile
|
||||||
|
{
|
||||||
|
void Write();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PidFileProvider : IProvidePidFile
|
||||||
|
{
|
||||||
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
|
private readonly IProcessProvider _processProvider;
|
||||||
|
private readonly Logger _logger;
|
||||||
|
|
||||||
|
public PidFileProvider(IAppFolderInfo appFolderInfo, IProcessProvider processProvider, Logger logger)
|
||||||
|
{
|
||||||
|
_appFolderInfo = appFolderInfo;
|
||||||
|
_processProvider = processProvider;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Write()
|
||||||
|
{
|
||||||
|
var filename = Path.Combine(_appFolderInfo.AppDataFolder, "nzbdrone.pid");
|
||||||
|
|
||||||
|
if (OsInfo.IsMono)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(filename, _processProvider.GetCurrentProcess().Id.ToString());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.Error("Unable to write PID file: " + filename, ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,6 @@ public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory, IHan
|
||||||
private readonly PriorityMonitor _priorityMonitor;
|
private readonly PriorityMonitor _priorityMonitor;
|
||||||
private readonly IStartupContext _startupContext;
|
private readonly IStartupContext _startupContext;
|
||||||
private readonly IBrowserService _browserService;
|
private readonly IBrowserService _browserService;
|
||||||
private readonly IProcessProvider _processProvider;
|
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
|
|
||||||
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
|
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
|
||||||
|
@ -33,7 +32,6 @@ public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
|
||||||
PriorityMonitor priorityMonitor,
|
PriorityMonitor priorityMonitor,
|
||||||
IStartupContext startupContext,
|
IStartupContext startupContext,
|
||||||
IBrowserService browserService,
|
IBrowserService browserService,
|
||||||
IProcessProvider processProvider,
|
|
||||||
Logger logger)
|
Logger logger)
|
||||||
{
|
{
|
||||||
_configFileProvider = configFileProvider;
|
_configFileProvider = configFileProvider;
|
||||||
|
@ -42,7 +40,6 @@ public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
|
||||||
_priorityMonitor = priorityMonitor;
|
_priorityMonitor = priorityMonitor;
|
||||||
_startupContext = startupContext;
|
_startupContext = startupContext;
|
||||||
_browserService = browserService;
|
_browserService = browserService;
|
||||||
_processProvider = processProvider;
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ public static void Start(StartupContext startupContext, IUserAlert userAlert, Ac
|
||||||
|
|
||||||
_container = MainAppContainerBuilder.BuildContainer(startupContext);
|
_container = MainAppContainerBuilder.BuildContainer(startupContext);
|
||||||
_container.Resolve<IAppFolderFactory>().Register();
|
_container.Resolve<IAppFolderFactory>().Register();
|
||||||
|
_container.Resolve<IProvidePidFile>().Write();
|
||||||
|
|
||||||
var appMode = GetApplicationMode(startupContext);
|
var appMode = GetApplicationMode(startupContext);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue