Import the daemon generator as the SVN external never works.
authorTom Hughes <tom@compton.nu>
Thu, 7 Aug 2008 17:46:34 +0000 (17:46 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 7 Aug 2008 17:46:34 +0000 (17:46 +0000)
vendor/generators/daemon/daemon_generator.rb [new file with mode: 0644]
vendor/generators/daemon/templates/daemons [new file with mode: 0644]
vendor/generators/daemon/templates/daemons.yml [new file with mode: 0644]
vendor/generators/daemon/templates/script.rb [new file with mode: 0755]
vendor/generators/daemon/templates/script_ctl [new file with mode: 0755]

diff --git a/vendor/generators/daemon/daemon_generator.rb b/vendor/generators/daemon/daemon_generator.rb
new file mode 100644 (file)
index 0000000..83e3bab
--- /dev/null
@@ -0,0 +1,11 @@
+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
diff --git a/vendor/generators/daemon/templates/daemons b/vendor/generators/daemon/templates/daemons
new file mode 100644 (file)
index 0000000..feb98b6
--- /dev/null
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `#{f} #{ARGV.first}`}
\ No newline at end of file
diff --git a/vendor/generators/daemon/templates/daemons.yml b/vendor/generators/daemon/templates/daemons.yml
new file mode 100644 (file)
index 0000000..c9f78f5
--- /dev/null
@@ -0,0 +1,5 @@
+dir_mode: script
+dir: ../../log
+multiple: false
+backtrace: true
+monitor: true
\ No newline at end of file
diff --git a/vendor/generators/daemon/templates/script.rb b/vendor/generators/daemon/templates/script.rb
new file mode 100755 (executable)
index 0000000..c3cd9b0
--- /dev/null
@@ -0,0 +1,19 @@
+#!/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
diff --git a/vendor/generators/daemon/templates/script_ctl b/vendor/generators/daemon/templates/script_ctl
new file mode 100755 (executable)
index 0000000..058f618
--- /dev/null
@@ -0,0 +1,20 @@
+#!/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