forked from dougal/daemon_generator
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 72a059f
Showing
7 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env ruby | ||
Dir[File.dirname(__FILE__) + "/../lib/daemons/*_ctl"].each {|f| `#{f} #{ARGV.first}`} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dir_mode: script | ||
dir: ../../log | ||
multiple: false | ||
backtrace: true | ||
monitor: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
puts IO.read(File.join(File.dirname(__FILE__), 'README')) |