Forge Home

service_autorestart

Puppet module to manage auto-restarting services (Windows and SystemD), and Windows Service Recovery options

2,943 downloads

954 latest version

5.0 quality score

Version information

  • 0.1.4 (latest)
  • 0.1.3
  • 0.1.2
  • 0.1.1
  • 0.1.0
released Apr 30th 2021
This version is compatible with:
  • Puppet Enterprise 2019.8.x, 2019.7.x, 2019.5.x, 2019.4.x, 2019.3.x, 2019.2.x, 2019.1.x, 2019.0.x, 2018.1.x, 2017.3.x, 2017.2.x, 2016.4.x
  • Puppet >= 4.10.0 < 7.0.0
  • , , , , , ,

Start using this module

  • r10k or Code Manager
  • Bolt
  • Manual installation
  • Direct download

Add this module to your Puppetfile:

mod 'encore-service_autorestart', '0.1.4'
Learn more about managing modules with a Puppetfile

Add this module to your Bolt project:

bolt module add encore-service_autorestart
Learn more about using this module with an existing project

Manually install this module globally with Puppet module tool:

puppet module install encore-service_autorestart --version 0.1.4

Direct download is not typically how you would use a Puppet module to manage your infrastructure, but you may want to download the module in order to inspect the code.

Download

Documentation

encore/service_autorestart — version 0.1.4 Apr 30th 2021

service_autorestart

Build Status Puppet Forge Version Puppet Forge Downloads Puppet Forge Score Puppet PDK Version puppetmodule.info docs

Table of Contents

  1. Description
  2. Setup
  3. Usage

Description

This module solves the problem of configuring a service to automatically restart itself in case the service fails or dies. In Windows this is called "Service Recovery" or "Service Failure" and can be found in the Service configuration dialog under the "Recovery" tab. On Linux systems this is simply a parameter on the service unit file in SystemD.

Setup

What service_autorestart affects

On Linux, this module changes the SystemD unit file for the service specified, adding the Restart= and RestartSec= parameters.

On Windows, this module configures the Service Recovery (Service Failure) options using the CLI command sc.exe.

Setup Requirements

This module uses the new Puppet Resource API.

In Puppet >= 6 the Resource API is included with the agent and server installations.

If you're running Puppet <= 5 then you'll need to install the Resource API using the puppetlabs/resource_api module on the forge.

Beginning with service_autorestart

Basic usage to enable automatic restarts of a service in a cross-plaform way (works for SystemD and Windows):

service_autorestart::generic { 'myservice': }

This will declare the appropriate resources to configure service autorestart depending on your OS. It will also automatically declare the correct notify and require relationships depending on the OS so that things happen in the right order. Example: on Windows the service resource must exist. On Linux the SystemD unit file must exist and we must then invoke systemctl daemon-reload after making our change (requires the use of camptocamp/sytemd module by default).

Usage

Cross-platform autorestart

The service_autorestart::generic resource provides basic configuration for enabling the automatic restart capability of a service when it fails. It is intentionally limited on options. If you need to tweak settings, please declare one of the OS specific resources.

service_autorestart::generic { 'myservice': }

SystemD autorestart

Basic usage, configure auto-restart for the Puppet service

service_autorestart::systemd { 'puppet': }

Customize the delay between restarts

service_autorestart::systemd { 'myservice':
  delay => '90s',
}

Customize the path and when action restarts

service_autorestart::systemd { nginx':
  path  => '/usr/local/lib/systemd/system/nginx.service',
  value => 'on-abort',
  delay => '90s',
}

Disable auto-notify relationships

service_autorestart::systemd { 'puppet':
  autonotify_path                    => false,
  autonotify_systemctl_daemon_reload => false,
}

Windows autorestart

Basic usage, auto-restart the Puppet service

service_autorestart::windows { 'puppet': }

Delay restarting the service for 60 seconds.

service_autorestart::windows { 'puppet':
  delay => 60000,  # delay is in milliseconds
}

Reboot the computer when the service fails

service_autorestart::windows { 'myservice':
  action         => 'reboot',
  reboot_message => 'service "myservice" failed, rebooting',
}

Run a command when the service fails

service_autorestart::windows { 'myservice':
  action  => 'run_command',
  command => 'msg "myservice failed, showing a popup so you know"',
}

Windows Low-level Service Recovery management

Apart from the high-level defines for Windows auto-restarts, we also provide a resource service_recovery to control all aspects of Windows Service Recovery in a fine-grained way:

service_recovery { 'myservice':
  reboot_message  => "Rebooting because 'myservice' failed",
  command         => 'msg "myservice failed, showing a popup so you know"',
  failure_actions => [
    {
      action => 'restart',
      delay  => 60000,
    },
    {
      action => 'reboot',
      delay  => 120000,
    },
    {
      action => 'run_command',
      delay  => 180000,
    },
  ],
}

For more details on this resource and the options see REFERENCE.md.