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'
31 # this is necessary to autodetect a valid resource
32 # default path, since there is no standard for such directory.
34 @defpath ||= ["/etc/s6-services"].find do |path|
35 Puppet::FileSystem.exist?(path) && FileTest.directory?(path)
41 # find the service dir on this node
44 ["/etc/s6-scandir"].each do |path|
45 if Puppet::FileSystem.exist?(path) && FileTest.directory?(path)
50 raise "Could not find service scan directory" unless @servicedir
58 Puppet.info("#{self.name} is unsuitable because service directory is nil")
61 unless FileTest.directory?(path)
62 Puppet.notice "Service path #{path} does not exist"
66 # reject entries that aren't either a directory
67 # or don't contain an executable run file
68 Dir.entries(path).reject { |e|
69 fullpath = File.join(path, e)
70 e =~ /^\./ or ! FileTest.directory?(fullpath) or ! Puppet::FileSystem.executable?(File.join(fullpath,"run"))
72 new(:name => name, :path => path)
78 output = s6_svstat "-u", self.service
79 return :running if output.chomp == 'true'
80 rescue Puppet::ExecutionFailure => detail
81 unless detail.message =~ /(warning: |s6-supervise not running$)/
82 raise Puppet::Error.new( "Could not get status for service #{resource.ref}: #{detail}", detail )
89 s6_svc "-d", self.service
93 s6_svc "-r", self.service
100 s6_svc "-u", self.service
104 if ! FileTest.directory?(self.daemon)
105 Puppet.notice "No daemon dir, calling setupservice for #{resource[:name]}"
109 if ! Puppet::FileSystem.symlink?(self.service)
110 Puppet.notice "Enabling #{self.service}: linking #{self.daemon} -> #{self.service}"
111 Puppet::FileSystem.symlink(self.daemon, self.service)
114 s6_svscanctl "-a", self.servicedir
115 rescue Puppet::ExecutionFailure
116 raise Puppet::Error.new( "No daemon directory found for #{self.service}", $!)
120 # unlink the daemon symlink to disable it
121 Puppet::FileSystem.unlink(self.service) if Puppet::FileSystem.symlink?(self.service)
122 s6_svscanctl "-n", self.servicedir