summaryrefslogtreecommitdiff
path: root/manifests/service/enabled.pp
diff options
context:
space:
mode:
authorMarkus Strauss <Markus@ITstrauss.eu>2011-11-01 11:46:42 -0400
committerMarkus Strauss <Markus@ITstrauss.eu>2011-11-01 11:46:42 -0400
commit19187e304fa6eec4a37ae776f177289800cfa490 (patch)
tree7e464db04a597dd753e45cab194b802c72d6f5a0 /manifests/service/enabled.pp
parent384137fe6814498e87a07cc5b74ae2bcb59f895b (diff)
downloadpuppet-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
Diffstat (limited to 'manifests/service/enabled.pp')
-rw-r--r--manifests/service/enabled.pp29
1 files changed, 26 insertions, 3 deletions
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}"] }
}