Skip to content

criteo-cookbooks/nssm

Repository files navigation

NSSM Cookbook

Cookbook Version Build Status

This cookbook installs the Non-Sucking Service Manager (http://nssm.cc), and exposes resources to install and remove Windows services.

Requirements

  • Chef 12.7+

Platform

  • Windows

Usage

Add recipe[nssm] to run list.

Quick Start

To install a Windows service:

nssm 'service name' do
  program 'C:\Windows\System32\java.exe'
  args '-jar C:/path/to/my-executable.jar'
  action :install
end

To remove a Windows service:

nssm 'service name' do
  action :remove
end

Using Parameters

A parameter is a hash key representing the same name as the registry entry which controls the associated functionality. So, for example, the following sets the Startup directory, I/O redirection, and File rotation for a service:

nssm 'service name' do
  program 'C:\Windows\System32\java.exe'
  args '-jar C:/path/to/my-executable.jar'
  parameters(
    AppDirectory: 'C:/path/to',
    AppStdout: 'C:/path/to/log/service.log',
    AppStderr: 'C:/path/to/log/error.log',
    AppRotateFiles: 1
  )
  action %i[install start]
end

Attributes

  • node['nssm']['src'] - This can either be a URI or a local path to nssm zip.
  • node['nssm']['sha256'] - SHA-256 checksum of the file. Chef will not download it if the local file matches the checksum.

Resource/Provider

Actions

  • install - Install a Windows service, and update it accordingly. (Note: it will NOT automatically restart the service, make sure to notify the according service to restart)
  • install_if_missing - Install a Windows service, but do not update it if present (old behaviour)
  • remove - Remove Windows service.
  • start - Start the Windows service.
  • stop - Stop the Windows service.

Attribute Parameters

  • servicename - Name attribute. The name of the Windows service.
  • program - The program to be run as a service.
  • args - String of arguments for the program. Optional
  • parameters - Hash of key value pairs where key represents associated registry entry. Optional
  • start - Start service after installing. Default - true
  • nssm_binary - Path to nssm binary. Default - node['nssm']['install_location']\nssm.exe

Getting Help

Contributing

Please refer to CONTRIBUTING.

License

MIT - see the accompanying LICENSE file for details.