Woof.ServiceInstaller
9.0.0
Prefix Reserved
dotnet add package Woof.ServiceInstaller --version 9.0.0
NuGet\Install-Package Woof.ServiceInstaller -Version 9.0.0
<PackageReference Include="Woof.ServiceInstaller" Version="9.0.0" />
<PackageVersion Include="Woof.ServiceInstaller" Version="9.0.0" />
<PackageReference Include="Woof.ServiceInstaller" />
paket add Woof.ServiceInstaller --version 9.0.0
#r "nuget: Woof.ServiceInstaller, 9.0.0"
#:package Woof.ServiceInstaller@9.0.0
#addin nuget:?package=Woof.ServiceInstaller&version=9.0.0
#tool nuget:?package=Woof.ServiceInstaller&version=9.0.0
Woof.ServiceInstaller
A part of the Woof Tookit by CodeDog.
Distributed under MIT License. (c)2021 by CodeDog, All rights reserved.
About
Installs and runs system services on Linux and Windows.
When {command} is your compiled service as one file native executable:
- For help use
{command} --help. - To install:
sudo {command} --install - To uninstall:
sudo {command} --uninstall - To delete Windows Event Log:
{command} --delete-log
Windows
Install your executable with a Microsoft Installer first.
For protected configurations use DataProtectionScope.LocalSystem.
The service will be registered in the location it was run with the --install option.
On Windows, Windows Installer (MSI) is the default way to install applications, so the service installer does not copy the files elsewhere.
To check if the service is running use either Services panel,
or type sc query {serviceName} in cmd.
You can also use Windows Event Log to look for entries from the service.
The service runs in LocalSystem user context.
The account can be changed to NetworkService via the Account property
of the service configuration metadata. However - the data protection feature
will work ONLY with LocalSystem. This applies to Woof.Settings.Protected and
Woof.Settings.AKV packages.
When the service is uninstalled with --uninstal option it will be automatically stopped,
then unregistered. The logs will stay until deleted with --delete-log option.
Linux
When run with sudo and --install option, the service will be copied
to the /srv/{serviceName} directory and the permission for the directory
will be set to user service (the user account set in configuration).
If the system user service does not exist it will be created.
The service will be run in service user context.
The service can be configured to use any system user and group.
Both user and group will be created if they don't exist.
(See the ServiceMetadata XML documentation.)
Linux system services are meant to be installed from a console as root user.
To check if the service is running type service {serviceName} status.
The logging events from the service will go to the main system log.
When the service is uninstalled with --uninstall option
the service installed files will be deleted but the service user will stay.
Also the Linux logs are not cleared.
Usage
- Create a console project.
- Add
Woof.Settings/Woof.Settings.AKV/Woof.Settings.Protectedpackage reference. - Optionally, if data protection is used and the service supports Linux systems,
add
Woof.DataProtection.Linuxpackage reference. - Create a service configuration JSON file like:
{ "windowsService": { "name": "testsvc", "displayName": "Woof Service Installer Test", "description": "Tests the Woof.ServiceInstaller.", "eventLogName": "Woof.ServiceInstaller", "eventSourceName": "Woof.ServiceInstaller.Test", "eventLogLevelMinimal": "debug" }, "systemDaemon": { "name": "testsvc", "displayName": "Woof Service Installer Test", "eventLogLevelMinimal": "debug", "user": "service", "group": "service" } } - Create settings class like:
public class Settings : JsonSettingsAkv<Settings> { private Settings() : base(DataProtectionScope.LocalSystem) { } public static Settings Default { get; } = new Settings(); public ServiceMetadataWindows WindowsService { get; } = new(); public ServiceMetadataSystemd SystemDaemon { get; } = new(); } - Save the file with the name matching the assembly name with
.jsonextension. - Set the
Copy to Output Directoryproperty toCopy if newer. - Optionally create a corresponding
.access.jsonfile as described inWoof.Settings.AKVdocumentation. - Create
Program.cslike:ServiceInstaller.AssertAdmin(args); await Settings.Default.LoadAsync(); ServiceMetadata serviceSettings = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Settings.Default.WindowsService : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? Settings.Default.SystemDaemon : throw new PlatformNotSupportedException(); await ServiceInstaller.ConfigureAndRunAsync<TestService>(serviceSettings, args);
The service can be tested, installed and uninstalled with admin access only.
Run without parameters to test the service operation.
Run with -? switch to display installer help.
Operation / Design
Both Windows Service and Linux systemd use the IHostedService interface.
It allows the service to be started and stopped.
The service executable is a normal executable that starts the service if run
without parameters. The process never exists unless it receives the stop signal
from the host. The services should use the CancellationToken provided with
Start() and Stop() methods.
The services will restart after the host is restarted.
The command line interface
The service installer uses the Woof.CommandLine to provide a unified, POSIX type command line interface.
By default the service installer automatically binds the
--install|-i, --uninstall|-u and --delete-log|-d options
to its internal handlers.
Disclaimer
Woof Toolkit is a work in progress in constant development, however it's carefully maintained with production code quality.
PLEASE report all issues on GitHub!
Describe how to reproduce an issue. Also feel free to suggest new features or improvements.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Hosting.Systemd (>= 9.0.2)
- Microsoft.Extensions.Hosting.WindowsServices (>= 9.0.2)
- Woof.CommandLine (>= 9.0.0)
- Woof.LinuxAdmin (>= 9.0.0)
-
net9.0
- Microsoft.Extensions.Hosting.Systemd (>= 9.0.2)
- Microsoft.Extensions.Hosting.WindowsServices (>= 9.0.2)
- Woof.CommandLine (>= 9.0.0)
- Woof.LinuxAdmin (>= 9.0.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 | |
|---|---|---|---|
| 9.0.0 | 214 | 2/21/2025 | |
| 7.0.0 | 348 | 8/6/2023 | |
| 6.2.0 | 667 | 2/20/2022 | |
| 6.1.4 | 1,534 | 11/28/2021 | |
| 6.1.3 | 411 | 11/27/2021 | |
| 6.1.2 | 1,992 | 11/26/2021 | |
| 6.0.5 | 2,509 | 11/25/2021 | |
| 6.0.4 | 461 | 11/17/2021 | |
| 6.0.3 | 422 | 11/15/2021 | |
| 6.0.2 | 646 | 11/12/2021 | |
| 6.0.1 | 603 | 11/11/2021 | |
| 5.2.7 | 626 | 11/1/2021 | |
| 5.2.6 | 681 | 10/30/2021 | |
| 5.2.5 | 637 | 10/20/2021 | |
| 5.2.4 | 644 | 10/20/2021 | |
| 5.2.3 | 592 | 10/20/2021 | |
| 5.2.2 | 599 | 10/15/2021 | |
| 5.2.1 | 603 | 10/14/2021 | |
| 5.2.0 | 662 | 10/14/2021 | |
| 5.1.1 | 633 | 10/13/2021 | |
| 5.1.0 | 640 | 10/12/2021 | |
| 5.0.3 | 607 | 8/27/2021 | |
| 5.0.2 | 653 | 8/27/2021 | |
| 5.0.1 | 637 | 8/20/2021 | |
| 5.0.0 | 605 | 8/19/2021 |
Major update for .NET 9.0.