summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/provider/service/s6.rb73
1 files changed, 73 insertions, 0 deletions
diff --git a/lib/puppet/provider/service/s6.rb b/lib/puppet/provider/service/s6.rb
new file mode 100644
index 0000000..7c265b9
--- /dev/null
+++ b/lib/puppet/provider/service/s6.rb
@@ -0,0 +1,73 @@
+Puppet::Type.type(:service).provide(:s6, :parent => :daemontools) do
+ desc <<~EOT
+ Service Management with S6
+ EOT
+
+ commands :s6_svscan => 's6-svscan'
+ commands :s6_svscanctl => 's6-svscanctl'
+ commands :s6_svc => 's6-svc'
+ commands :s6_svstat => 's6-svstat'
+
+ class << self
+ # this is necessary to autodetect a valid resource
+ # default path, since there is no standard for such directory.
+ def defpath
+ @defpath ||= ["/etc/s6-services"].find do |path|
+ Puppet::FileSystem.exist?(path) && FileTest.directory?(path)
+ end
+ @defpath
+ end
+ end
+
+ # find the service dir on this node
+ def servicedir
+ unless @servicedir
+ ["/etc/s6-scandir"].each do |path|
+ if Puppet::FileSystem.exist?(path)
+ @servicedir = path
+ break
+ end
+ end
+ raise "Could not find service directory" unless @servicedir
+ end
+ @servicedir
+ end
+
+ def status
+ begin
+ output = s6_svstat "-u", self.daemon
+ return :running if output == 'true'
+ rescue Puppet::ExecutionFailure => detail
+ unless detail.message =~ /(warning: |runsv not running$)/
+ raise Puppet::Error.new( "Could not get status for service #{resource.ref}: #{detail}", detail )
+ end
+ end
+ :stopped
+ end
+
+ def stop
+ s6_svc "-d", self.service
+ end
+
+ def restart
+ s6_svc "-r", self.service
+ end
+
+ def start
+ if enabled? != :true
+ enable
+ s6_svscanctl "-a", self.servicedir
+ end
+ s6_svc "-u", 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
+ Puppet::FileSystem.unlink(self.service) if Puppet::FileSystem.symlink?(self.service)
+ s6_svscanctl "-n", self.servicedir
+ end
+end