Rychusoft.PidFileManager 2.2.0

.NET 5.0 .NET Core 3.1
Install-Package Rychusoft.PidFileManager -Version 2.2.0
dotnet add package Rychusoft.PidFileManager --version 2.2.0
<PackageReference Include="Rychusoft.PidFileManager" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rychusoft.PidFileManager --version 2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Rychusoft.PidFileManager, 2.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rychusoft.PidFileManager as a Cake Addin
#addin nuget:?package=Rychusoft.PidFileManager&version=2.2.0

// Install Rychusoft.PidFileManager as a Cake Tool
#tool nuget:?package=Rychusoft.PidFileManager&version=2.2.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

PID file manager

Takes care of creating and deleting PID file in ASP.Net Core applications. Mechanics on which the library is based are described in this article. You can also find there information on how to create a systemd service that creates /var/run/yourapp/ directory with necessary write permissions for you.

Usage

  1. Install nuget package:
dotnet add package Rychusoft.PidFileManager
  1. In the Startup.cs add services.AddPidFileHostedService(Configuration.GetSection("PidFileOptions")); to the ConfigureServices() method:
public class Startup
{
    [...]

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddPidFileHostedService(Configuration.GetSection("PidFileOptions"));

        [...]
    }

    [...]
}
  1. In the appsettings.json add new section - note that the user under which your app is run need to have a privilages to write to this path:
"PidFileOptions": {
  "PidFilePath": "/var/run/yourapp/yourapp.pid"
}
  1. In the appsettings.Development.json add new section that will disable creating PID file when running in development environment (e.g., from Visual Studio):
"PidFileOptions": {
  "IsDisabled": true
}

Configuration

  1. You can configure the service as shown above, in the Usage section, by calling services.AddPidFileHostedService(Configuration.GetSection("PidFileOptions"));. Possible appsettings properties:
  • PidFilePath - string - full file path where the PID file will be created
  • IsDisabled - bool - if set to true then service will not create a PID file. Useful for disabling the service in development environment.
  1. You can configure the service by providing a lambda expression that yields an instance of the options class:
services.AddPidFileHostedService(options =>
{
    options.PidFilePath = "/var/run/yourapp/yourapp.pid";
    options.IsDisabled = false;
});
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp3.1
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 84 2/27/2022
2.1.0 61 2/27/2022
2.0.4 61 2/20/2022
2.0.3 56 2/20/2022
2.0.2 56 2/20/2022
2.0.1 61 2/20/2022
1.0.0 71 2/20/2022