1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 04:22:30 +01:00

New: Write PID file to AppData directory on Linux/OS X

This commit is contained in:
Mark McDowall 2014-04-27 22:14:31 -07:00
parent 9c0fb34864
commit 2dbc038d17
5 changed files with 46 additions and 6 deletions

View File

@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Text;
using NLog;
using NzbDrone.Common.Disk;
using NzbDrone.Common.Instrumentation;

View File

@ -103,6 +103,7 @@
<Compile Include="Messaging\IMessage.cs" />
<Compile Include="PathEqualityComparer.cs" />
<Compile Include="Processes\INzbDroneProcessProvider.cs" />
<Compile Include="Processes\PidFileProvider.cs" />
<Compile Include="Processes\ProcessOutput.cs" />
<Compile Include="RateGate.cs" />
<Compile Include="Serializer\IntConverter.cs" />

View 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;
}
}
}
}
}

View File

@ -24,7 +24,6 @@ public class NzbDroneServiceFactory : ServiceBase, INzbDroneServiceFactory, IHan
private readonly PriorityMonitor _priorityMonitor;
private readonly IStartupContext _startupContext;
private readonly IBrowserService _browserService;
private readonly IProcessProvider _processProvider;
private readonly Logger _logger;
public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
@ -33,7 +32,6 @@ public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
PriorityMonitor priorityMonitor,
IStartupContext startupContext,
IBrowserService browserService,
IProcessProvider processProvider,
Logger logger)
{
_configFileProvider = configFileProvider;
@ -42,7 +40,6 @@ public NzbDroneServiceFactory(IConfigFileProvider configFileProvider,
_priorityMonitor = priorityMonitor;
_startupContext = startupContext;
_browserService = browserService;
_processProvider = processProvider;
_logger = logger;
}

View File

@ -34,6 +34,7 @@ public static void Start(StartupContext startupContext, IUserAlert userAlert, Ac
_container = MainAppContainerBuilder.BuildContainer(startupContext);
_container.Resolve<IAppFolderFactory>().Register();
_container.Resolve<IProvidePidFile>().Write();
var appMode = GetApplicationMode(startupContext);