Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 72a059fbcd15730cb0c7a14ac0c61690a36148db @dougal committed Apr 10, 2008
14 README
@@ -0,0 +1,14 @@
+Daemon Generator
+================
+
+To get yourself rolling:
+> sudo gem install daemons
+> ./script/generate daemon <name>
+
+Then insert your code in the lib/daemons/<name>.rb stub. All pid's and logs will live in the normal log/ folder. This helps to make things Capistrano friendly.
+
+Individual control script:
+> ./lib/daemons/<name>_ctl [start|stop|restart]
+
+App-wide control script (I add this to my capistrano recipe's after_restart task):
+> ./script/daemons [start|stop|restart]
@@ -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
@@ -0,0 +1,2 @@
+#!/usr/bin/env ruby
+Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `#{f} #{ARGV.first}`}
@@ -0,0 +1,5 @@
+dir_mode: script
+dir: ../../log
+multiple: false
+backtrace: true
+monitor: true
@@ -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
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require "daemons"
+require 'yaml'
+require 'erb'
+require 'active_support'
+
+options = YAML.load(
+ ERB.new(
+ IO.read(
+ File.dirname(__FILE__) + "/../../config/daemons.yml"
+ )).result).with_indifferent_access
+options[:dir_mode] = options[:dir_mode].to_sym
+
+Daemons.run File.dirname(__FILE__) + '/<%=file_name%>.rb', options
@@ -0,0 +1 @@
+puts IO.read(File.join(File.dirname(__FILE__), 'README'))

0 comments on commit 72a059f

Please sign in to comment.