summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-08-27 20:31:38 +0200
committerJames Turnbull <james@lovedthanlost.net>2008-08-29 12:08:59 +1000
commit41dc1fac33cbb3938a5dc5f42f5b841a0a734c27 (patch)
tree9569658f4b56c75f734f23a865f6111f34df5e3e /lib
parentaae0793eb3632c6dea56f5d573d201c475786f8c (diff)
downloadpuppet-41dc1fac33cbb3938a5dc5f42f5b841a0a734c27.tar.gz
puppet-41dc1fac33cbb3938a5dc5f42f5b841a0a734c27.tar.xz
puppet-41dc1fac33cbb3938a5dc5f42f5b841a0a734c27.zip
Runit service provider
This provider manages daemons running supervised by Runit[1]. It tries to detect the service directory, with by order of preference: * /service * /var/service * /etc/service The daemon directory should be placed in a directory that can be by default in: * /etc/sv * /var/lib/service or this can be overriden in the service resource parameters: service { "myservice": provider => "runit", path => "/path/to/daemons"; } This provider supports out of the box: * start/stop * enable/disable * restart * status [1]: http://smarden.sunsite.dk/runit/
Diffstat (limited to 'lib')
-rw-r--r--lib/puppet/provider/service/runit.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/lib/puppet/provider/service/runit.rb b/lib/puppet/provider/service/runit.rb
new file mode 100644
index 000000000..230fa75d9
--- /dev/null
+++ b/lib/puppet/provider/service/runit.rb
@@ -0,0 +1,93 @@
+# Daemontools service management
+#
+# author Brice Figureau <brice-puppet@daysofwonder.com>
+Puppet::Type.type(:service).provide :runit, :parent => :daemontools do
+ desc "Runit service management.
+ This provider manages daemons running supervised by Runit.
+ It tries to detect the service directory, with by order of preference:
+ * /service
+ * /var/service
+ * /etc/service
+ The daemon directory should be placed in a directory that can be
+ by default in:
+ * /etc/sv
+ or this can be overriden in the service resource parameters:
+ service {
+ \"myservice\":
+ provider => \"runit\", path => \"/path/to/daemons\";
+ }
+
+ This provider supports out of the box:
+ * start/stop
+ * enable/disable
+ * restart
+ * status"
+
+ commands :sv => "/usr/bin/sv"
+
+ class << self
+ # this is necessary to autodetect a valid resource
+ # default path, since there is no standard for such directory.
+ def defpath
+ unless defined?(@defpath) and @defpath
+ ["/etc/sv", "/var/lib/service"].each do |path|
+ if FileTest.exist?(path)
+ @defpath = path
+ break
+ end
+ end
+ raise "Could not find the daemon directory (tested [/var/lib/service,/etc])" unless @defpath
+ end
+ @defpath
+ end
+ end
+
+ # find the service dir on this node
+ def servicedir
+ unless defined?(@servicedir) and @servicedir
+ ["/service", "/etc/service","/var/service"].each do |path|
+ if FileTest.exist?(path)
+ @servicedir = path
+ break
+ end
+ end
+ raise "Could not find service directory" unless @servicedir
+ end
+ @servicedir
+ end
+
+ def restartcmd
+ [ command(:sv), "restart", self.service]
+ end
+
+ def status
+ begin
+ output = sv "status", self.daemon
+ return :running if output =~ /^run: /
+ rescue Puppet::ExecutionFailure => detail
+ unless detail.message =~ /(warning: |runsv not running$)/
+ raise Puppet::Error.new( "Could not get status for service %s: %s" % [ resource.ref, detail] )
+ end
+ end
+ return :stopped
+ end
+
+ # relay to the stopcmd
+ def stop
+ ucommand( :stop )
+ end
+
+ def stopcmd
+ [ command(:sv), "stop", self.service]
+ end
+
+ # disable by removing the symlink so that runit
+ # doesn't restart our service behind our back
+ # note that runit doesn't need to perform a stop
+ # before a disable
+ def disable
+ # unlink the daemon symlink to disable it
+ File.unlink(self.service) if FileTest.symlink?(self.service)
+ end
+end
+