diff options
author | Markus Strauss <Markus@ITstrauss.eu> | 2011-11-01 11:46:42 -0400 |
---|---|---|
committer | Markus Strauss <Markus@ITstrauss.eu> | 2011-11-01 11:46:42 -0400 |
commit | 19187e304fa6eec4a37ae776f177289800cfa490 (patch) | |
tree | 7e464db04a597dd753e45cab194b802c72d6f5a0 | |
parent | 384137fe6814498e87a07cc5b74ae2bcb59f895b (diff) | |
download | puppet-runit-19187e304fa6eec4a37ae776f177289800cfa490.tar.gz puppet-runit-19187e304fa6eec4a37ae776f177289800cfa490.tar.bz2 |
* modified the way the restart is done: force-restart instead of restart
* added the ability to disable the service
* added service restart/shutdown timeout parameter
* add require service restart for all users/groups
-rw-r--r-- | manifests/service.pp | 3 | ||||
-rw-r--r-- | manifests/service/enabled.pp | 29 |
2 files changed, 28 insertions, 4 deletions
diff --git a/manifests/service.pp b/manifests/service.pp index 0fed6d9..c5311fa 100644 --- a/manifests/service.pp +++ b/manifests/service.pp @@ -14,7 +14,8 @@ define runit::service ( # 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 diff --git a/manifests/service/enabled.pp b/manifests/service/enabled.pp index d750914..1897e69 100644 --- a/manifests/service/enabled.pp +++ b/manifests/service/enabled.pp @@ -1,4 +1,4 @@ -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}": @@ -21,11 +21,34 @@ define runit::service::enabled( $ensure = present ) { 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}"] } } |