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

pull/3113/head
Mark McDowall 11 years ago
parent 9c0fb34864
commit 2dbc038d17

@ -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;

@ -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" />

@ -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 @@ namespace NzbDrone.Host
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 @@ namespace NzbDrone.Host
PriorityMonitor priorityMonitor,
IStartupContext startupContext,
IBrowserService browserService,
IProcessProvider processProvider,
Logger logger)
{
_configFileProvider = configFileProvider;
@ -42,7 +40,6 @@ namespace NzbDrone.Host
_priorityMonitor = priorityMonitor;
_startupContext = startupContext;
_browserService = browserService;
_processProvider = processProvider;
_logger = logger;
}

@ -34,6 +34,7 @@ namespace NzbDrone.Host
_container = MainAppContainerBuilder.BuildContainer(startupContext);
_container.Resolve<IAppFolderFactory>().Register();
_container.Resolve<IProvidePidFile>().Write();
var appMode = GetApplicationMode(startupContext);

Loading…
Cancel
Save