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:
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" />
|
||||
|
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 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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user