--- /dev/null
+class DaemonGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ m.directory "lib/daemons"
+ m.file "daemons", "script/daemons", :chmod => 0755
+ m.template "script.rb", "lib/daemons/#{file_name}.rb", :chmod => 0755
+ m.template "script_ctl", "lib/daemons/#{file_name}_ctl", :chmod => 0755
+ m.file "daemons.yml", "config/daemons.yml"
+ end
+ end
+end
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env ruby
+Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `#{f} #{ARGV.first}`}
\ No newline at end of file
--- /dev/null
+dir_mode: script
+dir: ../../log
+multiple: false
+backtrace: true
+monitor: true
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env ruby
+
+#You might want to change this
+ENV["RAILS_ENV"] ||= "production"
+
+require File.dirname(__FILE__) + "/../../config/environment"
+
+$running = true;
+Signal.trap("TERM") do
+ $running = false
+end
+
+while($running) do
+
+ # Replace this with your code
+ ActiveRecord::Base.logger << "This daemon is still running at #{Time.now}.\n"
+
+ sleep 10
+end
\ No newline at end of file
--- /dev/null
+#!/usr/bin/env ruby
+require 'rubygems'
+require "daemons"
+require 'yaml'
+require 'erb'
+
+class Hash
+ def with_symbols!
+ self.keys.each{|key| self[key.to_s.to_sym] = self[key] }; self
+ end
+end
+
+options = YAML.load(
+ ERB.new(
+ IO.read(
+ File.dirname(__FILE__) + "/../../config/daemons.yml"
+ )).result).with_symbols!
+options[:dir_mode] = options[:dir_mode].to_sym
+
+Daemons.run File.dirname(__FILE__) + '/<%=file_name%>.rb', options
\ No newline at end of file