Skip to content

nikhilagrawaldotnet/Cake.Services

 
 

Repository files navigation

Cake.Services

Cake-Build addin that extends Cake with windows service commands

Build status

cakebuild.net

Join the chat at https://gitter.im/cake-build/cake

Table of contents

  1. Implemented functionality
  2. Referencing
  3. Usage
  4. Example
  5. Plays well with
  6. License
  7. Share the love

Implemented functionality

  • Start
  • Stop
  • Restart
  • Pause
  • Continue
  • Execute Command
  • Get Service
  • Get Status
  • Install
  • Uninstall
  • Manage remote services

Referencing

NuGet Version NuGet Downloads

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"

Usage

#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");

Example

A complete Cake example can be found here.

TroubleShooting

  • 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.

Plays well with

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.

License

Copyright (c) 2015 - 2016 Phillip Sharpe

Cake.Services is provided as-is under the MIT license. For more information see LICENSE.

Share the love

If this project helps you in anyway then please ⭐ the repository.

About

Windows Services addin for Cake

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 90.2%
  • PowerShell 9.5%
  • Batchfile 0.3%