Woof.ServiceInstaller
5.2.6
Prefix Reserved
See the version list below for details.
dotnet add package Woof.ServiceInstaller --version 5.2.6
NuGet\Install-Package Woof.ServiceInstaller -Version 5.2.6
<PackageReference Include="Woof.ServiceInstaller" Version="5.2.6" />
paket add Woof.ServiceInstaller --version 5.2.6
#r "nuget: Woof.ServiceInstaller, 5.2.6"
// Install Woof.ServiceInstaller as a Cake Addin #addin nuget:?package=Woof.ServiceInstaller&version=5.2.6 // Install Woof.ServiceInstaller as a Cake Tool #tool nuget:?package=Woof.ServiceInstaller&version=5.2.6
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)
- Woof.LinuxAdmin (>= 5.0.2)
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 | 259 | 8/6/2023 | |
6.2.0 | 543 | 2/20/2022 | |
6.1.4 | 1,411 | 11/28/2021 | |
6.1.3 | 290 | 11/27/2021 | |
6.1.2 | 1,867 | 11/26/2021 | |
6.0.5 | 2,383 | 11/25/2021 | |
6.0.4 | 293 | 11/17/2021 | |
6.0.3 | 296 | 11/15/2021 | |
6.0.2 | 410 | 11/12/2021 | |
6.0.1 | 376 | 11/11/2021 | |
5.2.7 | 422 | 11/1/2021 | |
5.2.6 | 472 | 10/30/2021 | |
5.2.5 | 436 | 10/20/2021 | |
5.2.4 | 437 | 10/20/2021 | |
5.2.3 | 384 | 10/20/2021 | |
5.2.2 | 393 | 10/15/2021 | |
5.2.1 | 378 | 10/14/2021 | |
5.2.0 | 457 | 10/14/2021 | |
5.1.1 | 431 | 10/13/2021 | |
5.1.0 | 429 | 10/12/2021 | |
5.0.3 | 406 | 8/27/2021 | |
5.0.2 | 444 | 8/27/2021 | |
5.0.1 | 429 | 8/20/2021 | |
5.0.0 | 400 | 8/19/2021 |
Major performance and stability optimization.