Cake-Build addin that extends Cake with windows service commands
- Start
- Stop
- Restart
- Pause
- Continue
- Execute Command
- Get Service
- Get Status
- Install
- Uninstall
- Manage remote services
Cake.Services is available as a nuget package from the package manager console:
Install-Package Cake.Services
or directly in your build script via a cake addin directive:
#addin "Cake.Services"
#addin "Cake.Services"
Task("Start-Service")
.Description("Start a stopped windows service")
.Does(() =>
{
StartService("MpsSvc");
});
Task("Stop-Service")
.Description("Stop a running windows service")
.Does(() =>
{
StopService("MpsSvc", "remote-location");
});
Task("Restart-Service")
.Description("Restart a running windows service")
.Does(() =>
{
RestartService("MpsSvc");
});
Task("Pause-Service")
.Description("Pause a running windows service")
.Does(() =>
{
PauseService("MpsSvc");
});
Task("Continue-Service")
.Description("Continue a paused windows service")
.Does(() =>
{
ContinueService("MpsSvc", "remote-location");
});
Task("Execute-Command")
.Description("Execute a command on a running service")
.Does(() =>
{
ExecuteServiceCommand("MyService", 4);
});
Task("Get-Service")
.Description("Get a windows service object installed on a machine")
.Does(() =>
{
ServiceController controller = GetService("MpsSvc", "remote-location");
if (controller != null)
{
controller.Stop();
}
});
Task("Is-Service-Running")
.Description("Check if a windows service is running")
.Does(() =>
{
bool status = IsServiceRunning("MpsSvc");
if (status)
{
Debug("YAY!");
}
});
Task("Is-Service-Stopped")
.Description("Check if a windows service is stopped")
.Does(() =>
{
bool status = IsServiceStopped("MpsSvc");
if (status)
{
Debug("YAY!");
}
});
Task("Install-Service")
.Description("Install a windows service")
.Does(() =>
{
InstallService("remote-location", new InstallSettings()
{
ServiceName = "Popup",
DisplayName = "Annoying popup",
Description = "Displays adds every time you move the mouse",
ExecutablePath = "C:/LOL/Popup.exe",
StartMode = "auto",
Username = "Admin",
Password = "pass1"
});
});
Task("Uninstall-Service")
.Description("Uninstall a windows service")
.Does(() =>
{
UninstallService("Popup", "remote-location");
});
RunTarget("Start-Service");
A complete Cake example can be found here.
- Please be aware of the breaking changes that occurred with the release of Cake v0.22.0, you will need to upgrade Cake in order to use Cake.Services v0.3.0 or above.
If your looking to manage Topshelf windows services its worth checking out Cake.Topshelf.
If your looking for a way to trigger cake tasks based on windows events or at scheduled intervals then check out CakeBoss.
Copyright (c) 2015 - 2016 Phillip Sharpe
Cake.Services is provided as-is under the MIT license. For more information see LICENSE.
If this project helps you in anyway then please ⭐ the repository.