Woof.ServiceInstaller
5.2.3
Prefix Reserved
See the version list below for details.
dotnet add package Woof.ServiceInstaller --version 5.2.3
NuGet\Install-Package Woof.ServiceInstaller -Version 5.2.3
<PackageReference Include="Woof.ServiceInstaller" Version="5.2.3" />
paket add Woof.ServiceInstaller --version 5.2.3
#r "nuget: Woof.ServiceInstaller, 5.2.3"
// Install Woof.ServiceInstaller as a Cake Addin #addin nuget:?package=Woof.ServiceInstaller&version=5.2.3 // Install Woof.ServiceInstaller as a Cake Tool #tool nuget:?package=Woof.ServiceInstaller&version=5.2.3
Woof.ServiceInstaller
.NET extension created by CodeDog
Distributed under MIT License. (c)2021 by CodeDog, All rights reserved.
About
Installs and runs systems services. Works both on Windows and Linux. On Linux uses systemd.
For help use dotnet {command} --help. To install: sudo dotnet {command} --install To uninstall: sudo dotnet {command} --uninstall To delete Windows Event Log: {command} --delete-log (administrator required)
This package uses Woof.CommandLine package to handle the command line arguments with POSIX syntax guidelines.
Usage
Given:
ClientService
is your service class implementingIHostedService
,Config.Data
contains your service metadata class instance implementingIConfiguration
Here's example Main
mehtod:
private async static Task<int> Main(string[] args) {
var commandLine = CommandLine.Default; // default CommandLine instance
ServiceInstaller.Configure<ClientService>(Config.Data); // required
if (ServiceInstaller.ServiceMetadata is null) throw new NullReferenceException();
if (args?.Length > 0) { // run only when arguments present (not as service)
commandLine.Map<Options>(); // optional additional options
commandLine.Delegates.Add(Options.Help, Help); // optional additional delegates
commandLine.Parse(args); // required
var errors = CommandLine.ValidationErrors;
if (errors is not null) Error(errors); // optionally show errors if any
else await commandLine.RunDelegatesAsync(); // required
}
else
await ServiceController
.RunHostAsync<ClientService>(ServiceInstaller.ServiceMetadata!);
// required
return 0;
}
To execute code before or after installation / uninstallation simply check
if the install/uninstall options are present before and/or after RunDelegatesAsync
like this:
if (commandLine.HasOption(ServiceInstaller.Options.Install)) {
// code to execute
}
The installed service is started with
ServiceController.RunHostAsync<ClientService>(ServiceInstaller.ServiceMetadata!);
If executing of some external commands is needed before or after the installation,
ServiceController.ExecAsync
method can be used for that.
If the command executed that way fails, the method will throw an InvalidOperationException
with the error message obtained from the command output.
For more information see the included example project.
Compatibility
The package is compatible with .NET 5.0 or newer. The .NET Standard 2.1 support is dropped for increased simplicity and decreased size. The applications using the module can run both on Windows and Linux.
Disclaimer
Please report any issues to the toolkit developer.
Woof Toolkit is a work in progress in constant development, however it's carefully maintained with production code quality.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Extensions.Hosting.Systemd (>= 5.0.1)
- Microsoft.Extensions.Hosting.WindowsServices (>= 5.0.1)
- Woof.CommandLine (>= 5.4.0)
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 | |
---|---|---|---|
7.0.0 | 261 | 8/6/2023 | |
6.2.0 | 545 | 2/20/2022 | |
6.1.4 | 1,413 | 11/28/2021 | |
6.1.3 | 292 | 11/27/2021 | |
6.1.2 | 1,869 | 11/26/2021 | |
6.0.5 | 2,385 | 11/25/2021 | |
6.0.4 | 295 | 11/17/2021 | |
6.0.3 | 298 | 11/15/2021 | |
6.0.2 | 412 | 11/12/2021 | |
6.0.1 | 378 | 11/11/2021 | |
5.2.7 | 424 | 11/1/2021 | |
5.2.6 | 474 | 10/30/2021 | |
5.2.5 | 438 | 10/20/2021 | |
5.2.4 | 439 | 10/20/2021 | |
5.2.3 | 386 | 10/20/2021 | |
5.2.2 | 395 | 10/15/2021 | |
5.2.1 | 380 | 10/14/2021 | |
5.2.0 | 459 | 10/14/2021 | |
5.1.1 | 433 | 10/13/2021 | |
5.1.0 | 431 | 10/12/2021 | |
5.0.3 | 408 | 8/27/2021 | |
5.0.2 | 446 | 8/27/2021 | |
5.0.1 | 431 | 8/20/2021 | |
5.0.0 | 404 | 8/19/2021 |
FIX: Single file Linux releases: https://github.com/dotnet/runtime/issues/53346