puppet-standalone-mashup/shared/lib/puppet/provider/god_init/install.rb

80 lines
1.3 KiB
Ruby
Raw Normal View History

require 'erb'
Puppet::Type.type(:god_init).provide(:install) do
desc "Install a God script"
def create
2012-02-28 20:07:55 +00:00
File.open(file, 'wb') { |fh| fh.print processed_config }
end
def destroy
File.unlink file
end
def exists?
2012-02-28 20:07:55 +00:00
File.file?(file) && File.read(file) == processed_config
end
def processed_config
ERB.new(config).result(binding)
end
private
def file
"/etc/god.d/#{@resource[:name]}.god"
end
def start
@resource[:start] || ''
end
def stop
@resource[:stop] || ''
end
2012-02-28 20:07:55 +00:00
def restart
@resource[:restart] || ''
end
def name
@resource[:name] || ''
end
def pid_file
@resource[:pid_file] || ''
end
def config
<<-GOD
God.watch do |w|
w.name = "<%= name %>"
2012-02-28 20:07:55 +00:00
w.interval = 5.seconds
w.start = lambda { system("<%= start %>") }
<% if !stop.empty? %>
2012-04-25 22:14:41 +00:00
w.stop = lambda { system("<%= stop %>") ; system("killall -9 <%= name %>") }
2012-02-28 20:07:55 +00:00
<% end %>
<% if !restart.empty? %>
w.restart = lambda { system("<%= restart %>") }
<% end %>
<% if pid_file %>
w.pid_file = "<%= pid_file %>";
<% else %>
w.behavior(:clean_pid_file)
<% end %>
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
end
end
end
GOD
end
end