diff options
author | Hendrik Jäger <gitcommit@henk.geekmail.org> | 2022-04-25 23:34:49 +0200 |
---|---|---|
committer | Hendrik Jäger <gitcommit@henk.geekmail.org> | 2022-05-22 19:29:02 +0200 |
commit | 3a3b5bae2e05a9546f6bb32bff21db2bc66e9377 (patch) | |
tree | a33c2581476da61fd1563497daf118ee46345fb6 /lib | |
parent | 4e7e16252670533a7eed9568b660e6fdd574e5e1 (diff) |
feat: act as a provider
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/provider/service/s6.rb | 73 |
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 |