2011-12-07 22:59:34 +00:00
|
|
|
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
|
2011-12-07 22:59:34 +00:00
|
|
|
|
|
|
|
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 }
|
2011-12-07 22:59:34 +00:00
|
|
|
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)
|
2011-12-07 22:59:34 +00:00
|
|
|
end
|
|
|
|
|
2012-07-10 20:03:16 +00:00
|
|
|
def_resources :start, :group, :name, :dir
|
2011-12-07 22:59:34 +00:00
|
|
|
|
2012-07-10 20:03:16 +00:00
|
|
|
def interval
|
|
|
|
@resource[:interval] || 30
|
2011-12-07 22:59:34 +00:00
|
|
|
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
|
|
|
|
|
2011-12-07 22:59:34 +00:00
|
|
|
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
|
2011-12-07 22:59:34 +00:00
|
|
|
end
|
|
|
|
GOD
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|