1 Puppet::Type.type(:service).provide(:s6) 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)
65 # returns the daemon dir on this node
71 attr_writer :servicedir
73 # find the service dir on this node
76 ["/etc/s6-scandir"].each do |path|
77 if Puppet::FileSystem.exist?(path) && FileTest.directory?(path)
82 raise "Could not find service scan directory" unless @servicedir
87 # returns the full path of this service when enabled
88 # (ie in the service directory)
90 File.join(self.servicedir, resource[:name])
93 # returns the full path to the current daemon directory
94 # note that this path can be overridden in the resource
97 path = resource[:path]
98 raise Puppet::Error.new("#{self.class.name} must specify a path for daemon directory") unless path
99 File.join(path, resource[:name])
104 output = s6_svstat "-u", self.service
105 if output.chomp == 'true'
108 rescue Puppet::ExecutionFailure => detail
109 unless detail.message =~ /(warning: |s6-supervise not running$)/
110 raise Puppet::Error.new( "Could not get status for service #{resource.ref}: #{detail}", detail )
117 # the service is enabled if it is linked
118 case Puppet::FileSystem.symlink?(self.service) ? :true : :false
124 raise Puppet::Error.new( "Received unknown state for #{self.service}", $!)
129 if ! FileTest.directory?(self.daemon)
130 Puppet.notice "No daemon dir, calling setupservice for #{resource[:name]}"
133 if ! Puppet::FileSystem.symlink?(self.service)
134 Puppet.notice "Enabling #{self.service}: linking #{self.daemon} -> #{self.service}"
135 Puppet::FileSystem.symlink(self.daemon, self.service)
138 s6_svscanctl "-a", self.servicedir
139 rescue Puppet::ExecutionFailure
140 raise Puppet::Error.new( "No daemon directory found for #{self.service}", $!)
144 # unlink the daemon symlink to disable it
145 Puppet::FileSystem.unlink(self.service) if Puppet::FileSystem.symlink?(self.service)
146 s6_svscanctl "-n", self.servicedir
150 s6_svc "-r", self.service
157 s6_svc "-u", self.service
161 s6_svc "-d", self.service