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

61 lines
998 B
Ruby
Raw Normal View History

require 'erb'
Puppet::Type.type(:god_init).provide(:install) do
2012-07-10 20:03:16 +00:00
desc "Install a God script for a non-daemonized process"
def self.def_resources(*args)
args.each do |arg|
class_eval <<-RB
def #{arg}
@resource[:#{arg}] || ''
end
RB
end
end
def create
2012-06-01 18:24:53 +00:00
FileUtils.mkdir_p File.dirname(file)
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
2012-07-10 20:03:16 +00:00
def_resources :start, :group, :name, :dir
2012-07-10 20:03:16 +00:00
def interval
@resource[:interval] || 30
end
2012-07-10 20:03:16 +00:00
private
def file
File.join(dir, "#{name}.god")
2012-04-30 16:02:19 +00:00
end
def config
<<-GOD
God.watch do |w|
w.name = "<%= name %>"
2012-07-10 20:03:16 +00:00
<% if !group.empty? %>
w.group = "<%= group %>"
2012-02-28 20:07:55 +00:00
<% end %>
2012-07-10 20:03:16 +00:00
w.interval = <%= interval %>.seconds
w.start = %{<%= start %>}
2012-07-20 14:49:47 +00:00
w.keepalive
end
GOD
end
end