This solution contains a .NET 6 console application Lifeguard that monitors specified Windows services and processes and restarts them if they stop unexpectedly. It also contains two additional console applications, InstallApp and UninstallApp, to install and uninstall Windows services.
- Lifeguard : This is the main application that monitors the specified Windows services and restarts them if they stop. The list of services to monitor is read from the
appsettings.jsonfile at startup. - InstallApp : This application prompts the user for a service name and attempts to install and start a Windows service with that name.
- UninstallApp : This application prompts the user for a service name and attempts to uninstall a Windows service with that name.
All projects are built into a single output directory, Net6Publish.
Before beginning, please ensure that the .Net 6 runtime is installed on the target machine. You can download it from here.
-
Build the solution: Open the solution in Visual Studio, and build it by clicking
Build -> Build Solution. All projects are built into theNet6Publishdirectory at the solution root. -
Run the Lifeguard: Open a command prompt or terminal, navigate to the
Net6Publishdirectory, and rundotnet Lifeguard.dll. -
Install a service: Run the
InstallAppby executingdotnet Install.exein your command prompt or terminal. It will prompt for the service name. Enter the name of the Windows service to install and press enter (you can give this any name you like). -
Uninstall a service: Run the
UninstallAppby executingdotnet Uninstall.exein your command prompt or terminal. It will prompt for the service name. Enter the name of the Windows service to uninstall and press enter.
Remember that to install and uninstall services, you need administrator privileges.
Hint: To run multiple instances of the Lifeguard, you can copy the Net6Publish directory to another location and run the Lifeguard from there. Remember to give the service a unique name when running dotnet Install.exe.
The appsettings.json file, used by the Lifeguard, should be in the same directory as the Lifeguard.dll file. It contains an array of strings with the names of the services and processes to monitor. Here's an example:
{
"ServicesToMonitor": ["Service1","Service2","Service3"],
"ProcessesToMonitor": ["C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe"],
"RefreshIntervalInSeconds": 30
}
Contributions, issues, and feature requests are welcome!
This project is MIT licensed.