]> gitweb.fluxo.info Git - puppet-runit.git/commitdiff
* modified the way the restart is done: force-restart instead of restart
authorMarkus Strauss <Markus@ITstrauss.eu>
Tue, 1 Nov 2011 15:46:42 +0000 (11:46 -0400)
committerMarkus Strauss <Markus@ITstrauss.eu>
Tue, 1 Nov 2011 15:46:42 +0000 (11:46 -0400)
* added the ability to disable the service
* added service restart/shutdown timeout parameter
* add require service restart for all users/groups

manifests/service.pp
manifests/service/enabled.pp

index 0fed6d99d5d5eed1bee85b17557dbe9770979950..c5311fa3f64ceea78a1f709f99207424076fc6ff 100644 (file)
@@ -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
index d750914ceb87e1983254640e2899726a6619a7bc..1897e6947a44808758a2c6cfc5948855d253ccbe 100644 (file)
@@ -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}"] }
 
   }