Defined Type: service_autorestart::windows

Defined in:
manifests/windows.pp

Summary

Manages the auto-restart (aka service recovery) for a Windows service.

Overview

Examples:

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"',
}

Parameters:

  • action (Enum['noop', 'reboot', 'restart', 'run_command']) (defaults to: 'restart')
    • ‘noop’ = take no action.

    • ‘reboot’ = reboot the computer, displaying ‘reboot_message` before rebooting.

    • ‘restart’ = restart the service.

    • ‘run_command` = executes the `command` when the service fails

  • delay (Integer[0]) (defaults to: 1000)

    Number of millisecondsseconds (positive number) to wait before restarting the service.

  • reset_period (Integer[0]) (defaults to: 86400)

    Number of seconds to wait before resetting the “failed” count. Default: 86,400 = 1 day (Windows default).

  • reboot_message (Optional[String]) (defaults to: undef)

    Message to display before rebooting the computer. This is only used when specifying ‘action => ’reboot’‘

  • command (Optional[String]) (defaults to: undef)

    Command to run on failure. This is only used when specifying an ‘action => ’command’.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'manifests/windows.pp', line 42

define service_autorestart::windows (
  Enum['noop', 'reboot', 'restart', 'run_command'] $action = 'restart',
  Integer[0] $delay                = 1000,
  Integer[0] $reset_period         = 86400,
  Optional[String] $reboot_message = undef,
  Optional[String] $command        = undef,
) {
  service_recovery { $title:
    reset_period    => $reset_period,
    reboot_message  => $reboot_message,
    command         => $command,
    failure_actions => [
      {
        action => $action,
        delay  => $delay,
      },
      {
        action => $action,
        delay  => $delay,
      },
      {
        action => $action,
        delay  => $delay,
      },
    ],
  }
}