1 Puppet::Type.type(:service).provide(:s6, :parent => :daemontools) do
3 skarnet.org's small and secure supervision software suite
5 The scan directory is the first one found of:
8 The first matching service definition found in the following directories
13 This provider supports:
21 commands :s6_svscan => 's6-svscan'
22 commands :s6_svscanctl => 's6-svscanctl'
23 commands :s6_svc => 's6-svc'
24 commands :s6_svstat => 's6-svstat'
33 # this is necessary to autodetect a valid resource
34 # default path, since there is no standard for such directory.
36 @defpath ||= ["/etc/s6-services"].find do |path|
37 Puppet::FileSystem.exist?(path) && FileTest.directory?(path)
42 # returns all providers for all existing services in @defpath
47 Puppet.info("#{self.name} is unsuitable because service directory is nil")
50 unless FileTest.directory?(path)
51 Puppet.notice "Service path #{path} does not exist"
55 # reject entries that aren't either a directory
56 # or don't contain an executable run file
57 Dir.entries(path).reject { |e|
58 fullpath = File.join(path, e)
59 e =~ /^\./ or ! FileTest.directory?(fullpath) or ! Puppet::FileSystem.executable?(File.join(fullpath,"run"))
61 new(:name => name, :path => path)
67 attr_writer :servicedir
69 # find the service dir on this node
72 ["/etc/s6-scandir"].each do |path|
73 if Puppet::FileSystem.exist?(path) && FileTest.directory?(path)
78 raise "Could not find service scan directory" unless @servicedir
85 output = s6_svstat "-u", self.service
86 if output.chomp == 'true'
89 rescue Puppet::ExecutionFailure => detail
90 unless detail.message =~ /(warning: |s6-supervise not running$)/
91 raise Puppet::Error.new( "Could not get status for service #{resource.ref}: #{detail}", detail )
98 # the service is enabled if it is linked
99 case Puppet::FileSystem.symlink?(self.service) ? :true : :false
105 raise Puppet::Error.new( "Received unknown state for #{self.service}", $!)
110 if ! FileTest.directory?(self.daemon)
111 Puppet.notice "No daemon dir, calling setupservice for #{resource[:name]}"
114 if ! Puppet::FileSystem.symlink?(self.service)
115 Puppet.notice "Enabling #{self.service}: linking #{self.daemon} -> #{self.service}"
116 Puppet::FileSystem.symlink(self.daemon, self.service)
119 s6_svscanctl "-a", self.servicedir
120 rescue Puppet::ExecutionFailure
121 raise Puppet::Error.new( "No daemon directory found for #{self.service}", $!)
125 # unlink the daemon symlink to disable it
126 Puppet::FileSystem.unlink(self.service) if Puppet::FileSystem.symlink?(self.service)
127 s6_svscanctl "-n", self.servicedir
131 s6_svc "-r", self.service
138 s6_svc "-u", self.service
142 s6_svc "-d", self.service