# logging stuff
$logger = true, # shall we setup an logging service; if you use 'command' before,
# all output from command will be logged automatically to $logdir/current
- $logdir = "${rundir}/log"
+ $logdir = "${rundir}/log",
+ $timeout = 7 # service restart/stop timeouts (only relevant for 'enabled' services)
) {
# FixMe: Validate parameters
-define runit::service::enabled( $ensure = present ) {
+define runit::service::enabled( $ensure = present, $timeout ) {
# enabling the service by creating a symlink in /etc/service
file { "/etc/service/${name}":
exec { "sv restart ${name}":
subscribe => File["/etc/service/${name}"],
+ # last command is true, so this resource never fails
+ command => "/usr/bin/sv -w ${timeout} force-restart /etc/sv/${name}; true",
+ # we desperately need the supervise directory to restart a service
+ onlyif => "test -d '/etc/sv/${name}'/supervise",
+ refreshonly => true,
+ }
+
+ } else {
+
+ # Stop the service in THIS sequence:
+ # 1. remove /etc/services link
+ # 2. force-shutdown /etc/sv/*
+ # 3. remove /etc/sv stuff
+ # 4. manage users, groups, whatever
+
+ exec { "sv exit ${name}":
+ require => File["/etc/service/${name}"],
+ before => File["/etc/sv/${name}"],
# we wait a few seconds just in case this is the firstmost service activation
# then the supervise directory need to be created (automically) by runit
- command => "/bin/sleep 3; /usr/bin/sv -w 60 restart /etc/sv/${name}",
- refreshonly => true,
+ command => "/usr/bin/sv -w ${timeout} force-shutdown /etc/sv/${name}; true",
+ # when "/etc/sv/${name}" is not there, do not exec
+ onlyif => "test -d '/etc/sv/${name}'",
}
+
+ # if we have users/groups, we need to remove them AFTER stopping the server
+ User <||> { require +> Exec["sv exit ${name}"] }
+ Group <||> { require +> Exec["sv exit ${name}"] }
}