daemon-kit 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +17 -0
- data/Manifest.txt +62 -0
- data/PostInstall.txt +6 -0
- data/README.textile +94 -0
- data/Rakefile +31 -0
- data/TODO.txt +24 -0
- data/app_generators/daemon_kit/USAGE +7 -0
- data/app_generators/daemon_kit/daemon_kit_generator.rb +120 -0
- data/app_generators/daemon_kit/templates/README +48 -0
- data/app_generators/daemon_kit/templates/Rakefile +4 -0
- data/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
- data/app_generators/daemon_kit/templates/config/boot.rb +68 -0
- data/app_generators/daemon_kit/templates/config/environment.rb +19 -0
- data/app_generators/daemon_kit/templates/config/environments/development.rb +0 -0
- data/app_generators/daemon_kit/templates/config/environments/production.rb +0 -0
- data/app_generators/daemon_kit/templates/config/environments/test.rb +0 -0
- data/app_generators/daemon_kit/templates/config/initializers/readme +11 -0
- data/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
- data/bin/daemon_kit +19 -0
- data/daemon_generators/amqp/USAGE +5 -0
- data/daemon_generators/amqp/amqp_generator.rb +65 -0
- data/daemon_generators/amqp/templates/config/amqp.yml +28 -0
- data/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
- data/daemon_generators/amqp/templates/libexec/daemon.rb +29 -0
- data/daemon_generators/cron/USAGE +5 -0
- data/daemon_generators/cron/cron_generator.rb +64 -0
- data/daemon_generators/cron/templates/config/initializers/cron.rb +7 -0
- data/daemon_generators/cron/templates/libexec/daemon.rb +39 -0
- data/daemon_generators/jabber/USAGE +5 -0
- data/daemon_generators/jabber/jabber_generator.rb +65 -0
- data/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
- data/daemon_generators/jabber/templates/config/jabber.yml +26 -0
- data/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
- data/lib/daemon_kit.rb +14 -0
- data/lib/daemon_kit/amqp.rb +41 -0
- data/lib/daemon_kit/application.rb +34 -0
- data/lib/daemon_kit/cron.rb +38 -0
- data/lib/daemon_kit/initializer.rb +255 -0
- data/lib/daemon_kit/jabber.rb +172 -0
- data/lib/daemon_kit/patches/force_kill_wait.rb +120 -0
- data/lib/daemon_kit/tasks.rb +2 -0
- data/lib/daemon_kit/tasks/framework.rake +75 -0
- data/rubygems_generators/install_rspec/USAGE +5 -0
- data/rubygems_generators/install_rspec/install_rspec_generator.rb +57 -0
- data/rubygems_generators/install_rspec/templates/spec.rb +11 -0
- data/rubygems_generators/install_rspec/templates/spec/spec.opts +1 -0
- data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +10 -0
- data/rubygems_generators/install_rspec/templates/tasks/rspec.rake +21 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/spec/daemon_kit_spec.rb +7 -0
- data/spec/initializer_spec.rb +31 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +30 -0
- data/tasks/rspec.rake +21 -0
- data/test/test_amqp_generator.rb +48 -0
- data/test/test_cron_generator.rb +45 -0
- data/test/test_daemon-kit_generator.rb +67 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_jabber_generator.rb +49 -0
- metadata +168 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
# Be sure to restart your daemon when you modify this file
|
2
|
+
|
3
|
+
# Uncomment below to force your daemon into production mode
|
4
|
+
#ENV['DAEMON_ENV'] ||= 'production'
|
5
|
+
|
6
|
+
# Boot up
|
7
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
8
|
+
|
9
|
+
DaemonKit::Initializer.run do |config|
|
10
|
+
|
11
|
+
# The name of the daemon as reported by process monitoring tools
|
12
|
+
config.daemon_name = '<%= daemon_name %>'
|
13
|
+
|
14
|
+
# Uncomment to allow multiple instances to run
|
15
|
+
# config.mulitple = true
|
16
|
+
|
17
|
+
# Force the daemon to be killed after X seconds from asking it to
|
18
|
+
# config.force_kill_wait = 30
|
19
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# You can place files in here to be loaded before the code is daemonized.
|
2
|
+
#
|
3
|
+
# DaemonKit looks for a file named '<config.daemon_name>.rb' and loads
|
4
|
+
# that file with as if inside a DaemonKit::Initializer block.
|
5
|
+
#
|
6
|
+
# These files are mostly useful for operations that should fail blatantly
|
7
|
+
# before daemonizing, like loading gems.
|
8
|
+
#
|
9
|
+
# Be careful not to open any form of IO in here and expecting it to be
|
10
|
+
# open inside the running daemon since all IO instances are closed when
|
11
|
+
# daemonizing (including STDIN, STDOUT & STDERR).
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Change this file to be a wrapper around your daemon code.
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# Sample loop to show process
|
15
|
+
loop do
|
16
|
+
DaemonKit.logger.info "I'm running"
|
17
|
+
sleep 60
|
18
|
+
end
|
data/bin/daemon_kit
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rubigen'
|
5
|
+
|
6
|
+
if %w(-v --version).include? ARGV.first
|
7
|
+
require 'daemon_kit'
|
8
|
+
puts "#{File.basename($0)} #{DaemonKit::VERSION}"
|
9
|
+
exit(0)
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rubigen/scripts/generate'
|
13
|
+
RubiGen::Base.use_application_sources! :rubygems
|
14
|
+
RubiGen::Base.prepend_sources(*[
|
15
|
+
RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "app_generators")),
|
16
|
+
RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "daemon_generators")),
|
17
|
+
RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "rubygems_generators"))
|
18
|
+
])
|
19
|
+
RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'daemon_kit')
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class AmqpGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory ''
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb.erb", "some_file_after_erb.rb"
|
21
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
22
|
+
# m.template_copy_each ["template.rb", "template2.rb"], "some/path"
|
23
|
+
# m.file "file", "some_file_copied"
|
24
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
25
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
|
26
|
+
|
27
|
+
# Copy over our configs
|
28
|
+
m.directory 'config'
|
29
|
+
m.template 'config/amqp.yml', 'config/amqp.yml'
|
30
|
+
m.directory 'config/initializers'
|
31
|
+
m.template 'config/initializers/amqp.rb', "config/initializers/#{name}.rb"
|
32
|
+
|
33
|
+
# Copy over our daemon
|
34
|
+
m.directory 'libexec'
|
35
|
+
m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def banner
|
41
|
+
<<-EOS
|
42
|
+
Creates a ...
|
43
|
+
|
44
|
+
USAGE: #{$0} #{spec.name} name
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_options!(opts)
|
49
|
+
# opts.separator ''
|
50
|
+
# opts.separator 'Options:'
|
51
|
+
# For each option below, place the default
|
52
|
+
# at the top of the file next to "default_options"
|
53
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
54
|
+
# "Some comment about this option",
|
55
|
+
# "Default: none") { |o| options[:author] = o }
|
56
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_options
|
60
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
61
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
62
|
+
# raw instance variable value.
|
63
|
+
# @author = options[:author]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# AMQP client configuration file
|
2
|
+
|
3
|
+
# These values will be used to configure the ampq gem, any values
|
4
|
+
# omitted will let the gem use it's own defaults.
|
5
|
+
|
6
|
+
# The configuration specifies the following keys:
|
7
|
+
# * username - Username for the broker
|
8
|
+
# * password - Password for the broker
|
9
|
+
# * host - Hostname where the broker is running
|
10
|
+
# * vhost - Vhost to connect to
|
11
|
+
# * port - Port where the broker is running
|
12
|
+
# * ssl - Use ssl or not
|
13
|
+
# * timeout - Timeout
|
14
|
+
|
15
|
+
defaults: &defaults
|
16
|
+
username: guest
|
17
|
+
password: guest
|
18
|
+
host: localhost
|
19
|
+
vhost: /
|
20
|
+
|
21
|
+
development:
|
22
|
+
<<: *defaults
|
23
|
+
|
24
|
+
test:
|
25
|
+
<<: *defaults
|
26
|
+
|
27
|
+
production:
|
28
|
+
<<: *defaults
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Generated amqp daemon
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# IMPORTANT CONFIGURATION NOTE
|
15
|
+
#
|
16
|
+
# Please review and update 'config/amqp.yml' accordingly or this
|
17
|
+
# daemon won't work as advertised.
|
18
|
+
|
19
|
+
# Run an event-loop for processing
|
20
|
+
DaemonKit::AMQP.run do
|
21
|
+
# Inside this block we're running inside the reactor setup by the
|
22
|
+
# amqp gem. Any code in the examples (from the gem) would work just
|
23
|
+
# fine here.
|
24
|
+
|
25
|
+
amq = ::MQ.new
|
26
|
+
amq.queue('test').subscribe do |msg|
|
27
|
+
DaemonKit.logger.debug "Received message: #{msg.inspect}"
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class CronGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory ''
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb.erb", "some_file_after_erb.rb"
|
21
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
22
|
+
# m.template_copy_each ["template.rb", "template2.rb"], "some/path"
|
23
|
+
# m.file "file", "some_file_copied"
|
24
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
25
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
|
26
|
+
|
27
|
+
# Copy over configs
|
28
|
+
m.directory 'config'
|
29
|
+
m.directory 'config/initializers'
|
30
|
+
m.template 'config/initializers/cron.rb', "config/initializers/#{name}.rb"
|
31
|
+
|
32
|
+
# Copy over our daemon
|
33
|
+
m.directory 'libexec'
|
34
|
+
m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
protected
|
39
|
+
def banner
|
40
|
+
<<-EOS
|
41
|
+
Creates a ...
|
42
|
+
|
43
|
+
USAGE: #{$0} #{spec.name} name
|
44
|
+
EOS
|
45
|
+
end
|
46
|
+
|
47
|
+
def add_options!(opts)
|
48
|
+
# opts.separator ''
|
49
|
+
# opts.separator 'Options:'
|
50
|
+
# For each option below, place the default
|
51
|
+
# at the top of the file next to "default_options"
|
52
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
53
|
+
# "Some comment about this option",
|
54
|
+
# "Default: none") { |o| options[:author] = o }
|
55
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
56
|
+
end
|
57
|
+
|
58
|
+
def extract_options
|
59
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
60
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
61
|
+
# raw instance variable value.
|
62
|
+
# @author = options[:author]
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Generated cron daemon
|
2
|
+
|
3
|
+
# Do your post daemonization configuration here
|
4
|
+
# At minimum you need just the first line (without the block), or a lot
|
5
|
+
# of strange things might start happening...
|
6
|
+
DaemonKit::Application.running! do |config|
|
7
|
+
# Trap signals with blocks or procs
|
8
|
+
# config.trap( 'INT' ) do
|
9
|
+
# # do something clever
|
10
|
+
# end
|
11
|
+
# config.trap( 'TERM', Proc.new { puts 'Going down' } )
|
12
|
+
end
|
13
|
+
|
14
|
+
# Configuration documentation available at http://rufus.rubyforge.org/rufus-scheduler/
|
15
|
+
# An instance of the scheduler is available through
|
16
|
+
# DaemonKit::Cron.scheduler
|
17
|
+
|
18
|
+
# Some samples to get you going:
|
19
|
+
|
20
|
+
# Will call #regenerate_monthly_report in 3 days from starting up
|
21
|
+
#DaemonKit::Cron.scheduler.in("3d") do
|
22
|
+
# regenerate_monthly_report()
|
23
|
+
#end
|
24
|
+
#
|
25
|
+
#DaemonKit::Cron.scheduler.every "10m10s" do
|
26
|
+
# check_score(favourite_team) # every 10 minutes and 10 seconds
|
27
|
+
#end
|
28
|
+
#
|
29
|
+
#DaemonKit::Cron.scheduler.cron "0 22 * * 1-5" do
|
30
|
+
# log.info "activating security system..."
|
31
|
+
# activate_security_system()
|
32
|
+
#end
|
33
|
+
|
34
|
+
DaemonKit::Cron.scheduler.every("1m") do
|
35
|
+
DaemonKit.logger.debug "Scheduled task completed at #{Time.now}"
|
36
|
+
end
|
37
|
+
|
38
|
+
# Run our 'cron' daeon
|
39
|
+
DaemonKit::Cron.run
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class JabberGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
default_options :author => nil
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
|
7
|
+
def initialize(runtime_args, runtime_options = {})
|
8
|
+
super
|
9
|
+
usage if args.empty?
|
10
|
+
@name = args.shift
|
11
|
+
extract_options
|
12
|
+
end
|
13
|
+
|
14
|
+
def manifest
|
15
|
+
record do |m|
|
16
|
+
# Ensure appropriate folder(s) exists
|
17
|
+
m.directory ''
|
18
|
+
|
19
|
+
# Create stubs
|
20
|
+
# m.template "template.rb.erb", "some_file_after_erb.rb"
|
21
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
22
|
+
# m.template_copy_each ["template.rb", "template2.rb"], "some/path"
|
23
|
+
# m.file "file", "some_file_copied"
|
24
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
25
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"], "some/path"
|
26
|
+
|
27
|
+
# Copy over our configs
|
28
|
+
m.directory 'config'
|
29
|
+
m.template 'config/jabber.yml', 'config/jabber.yml'
|
30
|
+
m.directory 'config/initializers'
|
31
|
+
m.template 'config/initializers/jabber.rb', "config/initializers/#{name}.rb"
|
32
|
+
|
33
|
+
# Copy over our daemon
|
34
|
+
m.directory 'libexec'
|
35
|
+
m.template 'libexec/daemon.rb', "libexec/#{name}.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
def banner
|
41
|
+
<<-EOS
|
42
|
+
Creates a ...
|
43
|
+
|
44
|
+
USAGE: #{$0} #{spec.name} name
|
45
|
+
EOS
|
46
|
+
end
|
47
|
+
|
48
|
+
def add_options!(opts)
|
49
|
+
# opts.separator ''
|
50
|
+
# opts.separator 'Options:'
|
51
|
+
# For each option below, place the default
|
52
|
+
# at the top of the file next to "default_options"
|
53
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
54
|
+
# "Some comment about this option",
|
55
|
+
# "Default: none") { |o| options[:author] = o }
|
56
|
+
# opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
57
|
+
end
|
58
|
+
|
59
|
+
def extract_options
|
60
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
61
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
62
|
+
# raw instance variable value.
|
63
|
+
# @author = options[:author]
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Jabber configuration file
|
2
|
+
|
3
|
+
# The configuration specifies the following keys:
|
4
|
+
# * jabber_id - Identidy (username) of the user
|
5
|
+
# * password - Password used to authenticate
|
6
|
+
# * resource - Multiple connections can be made with the same credentials and different resources
|
7
|
+
# * masters - Array of Jabber ID's whose messages will be processed
|
8
|
+
# * supporters - Additional 'buddies' to keep on roster, but messages won't be processed
|
9
|
+
|
10
|
+
defaults: &defaults
|
11
|
+
jabber_id: <%= name %>@gmail.com
|
12
|
+
password: secret
|
13
|
+
resource: daemon_kit
|
14
|
+
masters:
|
15
|
+
- you@gmail.com
|
16
|
+
supporters:
|
17
|
+
- someone@gmail.com
|
18
|
+
|
19
|
+
development:
|
20
|
+
<<: *defaults
|
21
|
+
|
22
|
+
test:
|
23
|
+
<<: *defaults
|
24
|
+
|
25
|
+
production:
|
26
|
+
<<: *defaults
|