lib/kuzushi.rb in kuzushi-0.0.16 vs lib/kuzushi.rb in kuzushi-0.0.17
- old
+ new
@@ -61,10 +61,11 @@
process :local_packages
process :gems
process :volumes
process :files
process :users
+ process :crontab
script get("after")
script get("init") if init?
end
@@ -189,9 +190,36 @@
def write_file(src, dest, &blk)
fetch(src) do |file|
FileUtils.mkdir_p(File.dirname(dest))
File.open(dest,"w") { |f| f.write(blk.call(file)) }
+ end
+ end
+
+ def handle_crontab(src, user = "root", &blk)
+ ## FIXME - this is getting a little silly calling tmpfile twice - should be able to pass erb to fetch as an opton...
+ ## unify code for process crontabs + process files
+ fetch(src) do |file|
+ tmpfile(blk.call) do |tmp|
+ task "process crontab for #{user}" do
+ shell "crontab -u #{user} #{tmp}"
+ end
+ end
+ end
+ end
+
+ def process_crontab(cron)
+ if cron.template
+ handle_crontab("/templates/#{cron.template}", cron.user) do |file|
+ @system = system
+ t = ERB.new File.read(file), 0, '<>'
+ t.result(binding)
+ end
+ else
+ src = cron.source || File.basename(cron.file)
+ handle_crontab("/files/#{src}", cron.user) do |file|
+ File.read(file)
+ end
end
end
def process_users(user)
(user.authorized_keys || []).each do |key|