apphunkd 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/Rakefile +78 -0
- data/TODO +1 -0
- data/VERSION +1 -0
- data/apphunkd.gemspec +258 -0
- data/bin/apphunkd +4 -0
- data/config/arguments.rb +12 -0
- data/config/boot.rb +68 -0
- data/config/environment.rb +23 -0
- data/config/environments/development.rb +2 -0
- data/config/environments/production.rb +2 -0
- data/config/environments/test.rb +2 -0
- data/config/post-daemonize/readme +5 -0
- data/config/pre-daemonize/readme +12 -0
- data/config/pre-daemonize/requires.rb +2 -0
- data/lib/apphunkd.rb +25 -0
- data/lib/apphunkd/api.rb +5 -0
- data/lib/apphunkd/api/service.rb +27 -0
- data/lib/apphunkd/queue.rb +96 -0
- data/lib/apphunkd/remote.rb +29 -0
- data/lib/apphunkd/remote/result.rb +15 -0
- data/libexec/apphunkd-daemon.rb +13 -0
- data/script/console +3 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/lib/apphunkd/api/service_spec.rb +47 -0
- data/spec/lib/apphunkd/queue_spec.rb +129 -0
- data/spec/lib/apphunkd/remote_spec.rb +61 -0
- data/spec/lib/apphunkd_spec.rb +50 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +13 -0
- data/support/apphunkd.initd +47 -0
- data/support/apphunkd.monitrc +3 -0
- data/tasks/rspec.rake +21 -0
- data/vendor/daemon-kit/Configuration.txt +102 -0
- data/vendor/daemon-kit/Deployment.txt +113 -0
- data/vendor/daemon-kit/History.txt +97 -0
- data/vendor/daemon-kit/Logging.txt +92 -0
- data/vendor/daemon-kit/Manifest.txt +166 -0
- data/vendor/daemon-kit/PostInstall.txt +6 -0
- data/vendor/daemon-kit/README.rdoc +130 -0
- data/vendor/daemon-kit/Rakefile +37 -0
- data/vendor/daemon-kit/RuoteParticipants.txt +113 -0
- data/vendor/daemon-kit/TODO.txt +37 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/USAGE +7 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/daemon_kit_generator.rb +161 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/README +48 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/Rakefile +6 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/bin/daemon.erb +7 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/boot.rb +68 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environment.rb +23 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environments/development.rb +2 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environments/production.rb +2 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/environments/test.rb +2 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/post-daemonize/readme +5 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/config/pre-daemonize/readme +12 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/lib/daemon.rb +2 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/libexec/daemon.erb +18 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/script/console +3 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/script/destroy +14 -0
- data/vendor/daemon-kit/app_generators/daemon_kit/templates/script/generate +14 -0
- data/vendor/daemon-kit/bin/daemon_kit +18 -0
- data/vendor/daemon-kit/daemon_generators/amqp/USAGE +5 -0
- data/vendor/daemon-kit/daemon_generators/amqp/amqp_generator.rb +65 -0
- data/vendor/daemon-kit/daemon_generators/amqp/templates/config/amqp.yml +28 -0
- data/vendor/daemon-kit/daemon_generators/amqp/templates/config/initializers/amqp.rb +7 -0
- data/vendor/daemon-kit/daemon_generators/amqp/templates/libexec/daemon.rb +37 -0
- data/vendor/daemon-kit/daemon_generators/cron/USAGE +5 -0
- data/vendor/daemon-kit/daemon_generators/cron/cron_generator.rb +64 -0
- data/vendor/daemon-kit/daemon_generators/cron/templates/config/initializers/cron.rb +11 -0
- data/vendor/daemon-kit/daemon_generators/cron/templates/libexec/daemon.rb +43 -0
- data/vendor/daemon-kit/daemon_generators/cucumber/USAGE +11 -0
- data/vendor/daemon-kit/daemon_generators/cucumber/cucumber_generator.rb +38 -0
- data/vendor/daemon-kit/daemon_generators/cucumber/templates/cucumber +8 -0
- data/vendor/daemon-kit/daemon_generators/cucumber/templates/cucumber.rake +13 -0
- data/vendor/daemon-kit/daemon_generators/cucumber/templates/cucumber_environment.rb +2 -0
- data/vendor/daemon-kit/daemon_generators/cucumber/templates/env.rb +7 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy.rb +53 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
- data/vendor/daemon-kit/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
- data/vendor/daemon-kit/daemon_generators/jabber/USAGE +5 -0
- data/vendor/daemon-kit/daemon_generators/jabber/jabber_generator.rb +65 -0
- data/vendor/daemon-kit/daemon_generators/jabber/templates/config/initializers/jabber.rb +7 -0
- data/vendor/daemon-kit/daemon_generators/jabber/templates/config/jabber.yml +26 -0
- data/vendor/daemon-kit/daemon_generators/jabber/templates/libexec/daemon.rb +27 -0
- data/vendor/daemon-kit/daemon_generators/nanite_agent/USAGE +5 -0
- data/vendor/daemon-kit/daemon_generators/nanite_agent/nanite_agent_generator.rb +68 -0
- data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/config/initializers/nanite_agent.rb +6 -0
- data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/config/nanite.yml +35 -0
- data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/lib/actors/sample.rb +11 -0
- data/vendor/daemon-kit/daemon_generators/nanite_agent/templates/libexec/daemon.rb +31 -0
- data/vendor/daemon-kit/daemon_generators/rspec/USAGE +5 -0
- data/vendor/daemon-kit/daemon_generators/rspec/rspec_generator.rb +55 -0
- data/vendor/daemon-kit/daemon_generators/rspec/templates/spec.rb +11 -0
- data/vendor/daemon-kit/daemon_generators/rspec/templates/spec/spec.opts +1 -0
- data/vendor/daemon-kit/daemon_generators/rspec/templates/spec/spec_helper.rb +21 -0
- data/vendor/daemon-kit/daemon_generators/rspec/templates/tasks/rspec.rake +21 -0
- data/vendor/daemon-kit/daemon_generators/ruote/USAGE +5 -0
- data/vendor/daemon-kit/daemon_generators/ruote/ruote_generator.rb +67 -0
- data/vendor/daemon-kit/daemon_generators/ruote/templates/config/amqp.yml +30 -0
- data/vendor/daemon-kit/daemon_generators/ruote/templates/config/initializers/ruote.rb +13 -0
- data/vendor/daemon-kit/daemon_generators/ruote/templates/config/ruote.yml +23 -0
- data/vendor/daemon-kit/daemon_generators/ruote/templates/lib/daemon.rb +4 -0
- data/vendor/daemon-kit/daemon_generators/ruote/templates/lib/sample.rb +26 -0
- data/vendor/daemon-kit/daemon_generators/ruote/templates/libexec/daemon.rb +33 -0
- data/vendor/daemon-kit/lib/daemon_kit.rb +54 -0
- data/vendor/daemon-kit/lib/daemon_kit/abstract_logger.rb +235 -0
- data/vendor/daemon-kit/lib/daemon_kit/amqp.rb +38 -0
- data/vendor/daemon-kit/lib/daemon_kit/application.rb +187 -0
- data/vendor/daemon-kit/lib/daemon_kit/arguments.rb +165 -0
- data/vendor/daemon-kit/lib/daemon_kit/commands/console.rb +38 -0
- data/vendor/daemon-kit/lib/daemon_kit/config.rb +108 -0
- data/vendor/daemon-kit/lib/daemon_kit/console_daemon.rb +2 -0
- data/vendor/daemon-kit/lib/daemon_kit/core_ext.rb +1 -0
- data/vendor/daemon-kit/lib/daemon_kit/core_ext/configurable.rb +96 -0
- data/vendor/daemon-kit/lib/daemon_kit/core_ext/string.rb +22 -0
- data/vendor/daemon-kit/lib/daemon_kit/cron.rb +48 -0
- data/vendor/daemon-kit/lib/daemon_kit/cucumber/world.rb +38 -0
- data/vendor/daemon-kit/lib/daemon_kit/deployment/capistrano.rb +482 -0
- data/vendor/daemon-kit/lib/daemon_kit/em.rb +43 -0
- data/vendor/daemon-kit/lib/daemon_kit/error_handlers/base.rb +32 -0
- data/vendor/daemon-kit/lib/daemon_kit/error_handlers/hoptoad.rb +61 -0
- data/vendor/daemon-kit/lib/daemon_kit/error_handlers/mail.rb +85 -0
- data/vendor/daemon-kit/lib/daemon_kit/exceptions.rb +8 -0
- data/vendor/daemon-kit/lib/daemon_kit/initializer.rb +438 -0
- data/vendor/daemon-kit/lib/daemon_kit/jabber.rb +170 -0
- data/vendor/daemon-kit/lib/daemon_kit/nanite.rb +7 -0
- data/vendor/daemon-kit/lib/daemon_kit/nanite/agent.rb +56 -0
- data/vendor/daemon-kit/lib/daemon_kit/pid_file.rb +61 -0
- data/vendor/daemon-kit/lib/daemon_kit/ruote_participants.rb +119 -0
- data/vendor/daemon-kit/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
- data/vendor/daemon-kit/lib/daemon_kit/ruote_workitem.rb +169 -0
- data/vendor/daemon-kit/lib/daemon_kit/safety.rb +85 -0
- data/vendor/daemon-kit/lib/daemon_kit/tasks.rb +2 -0
- data/vendor/daemon-kit/lib/daemon_kit/tasks/environment.rake +10 -0
- data/vendor/daemon-kit/lib/daemon_kit/tasks/framework.rake +120 -0
- data/vendor/daemon-kit/lib/daemon_kit/tasks/god.rake +62 -0
- data/vendor/daemon-kit/lib/daemon_kit/tasks/log.rake +8 -0
- data/vendor/daemon-kit/lib/daemon_kit/tasks/monit.rake +29 -0
- data/vendor/daemon-kit/script/console +10 -0
- data/vendor/daemon-kit/script/destroy +14 -0
- data/vendor/daemon-kit/script/generate +14 -0
- data/vendor/daemon-kit/script/txt2html +71 -0
- data/vendor/daemon-kit/spec/abstract_logger_spec.rb +126 -0
- data/vendor/daemon-kit/spec/argument_spec.rb +70 -0
- data/vendor/daemon-kit/spec/config_spec.rb +79 -0
- data/vendor/daemon-kit/spec/configurable_spec.rb +56 -0
- data/vendor/daemon-kit/spec/daemon_kit_spec.rb +7 -0
- data/vendor/daemon-kit/spec/error_handlers_spec.rb +23 -0
- data/vendor/daemon-kit/spec/fixtures/env.yml +15 -0
- data/vendor/daemon-kit/spec/fixtures/noenv.yml +4 -0
- data/vendor/daemon-kit/spec/initializer_spec.rb +26 -0
- data/vendor/daemon-kit/spec/spec.opts +1 -0
- data/vendor/daemon-kit/spec/spec_helper.rb +27 -0
- data/vendor/daemon-kit/tasks/rspec.rake +21 -0
- data/vendor/daemon-kit/templates/god/god.erb +69 -0
- data/vendor/daemon-kit/templates/monit/monit.erb +14 -0
- data/vendor/daemon-kit/test/test_amqp_generator.rb +48 -0
- data/vendor/daemon-kit/test/test_cron_generator.rb +45 -0
- data/vendor/daemon-kit/test/test_daemon-kit_generator.rb +84 -0
- data/vendor/daemon-kit/test/test_daemon_kit_config.rb +28 -0
- data/vendor/daemon-kit/test/test_deploy_capistrano_generator.rb +48 -0
- data/vendor/daemon-kit/test/test_generator_helper.rb +29 -0
- data/vendor/daemon-kit/test/test_helper.rb +7 -0
- data/vendor/daemon-kit/test/test_jabber_generator.rb +49 -0
- data/vendor/daemon-kit/test/test_nanite_agent_generator.rb +49 -0
- data/vendor/daemon-kit/test/test_ruote_generator.rb +45 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail.rb +5 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/address.rb +426 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/config.rb +67 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/header.rb +960 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/index.rb +9 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/main.rb +6 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/net.rb +248 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/port.rb +379 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
- data/vendor/daemon-kit/vendor/tmail-1.2.3/tmail/version.rb +39 -0
- data/vendor/daemon-kit/vendor/tmail.rb +13 -0
- metadata +281 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
= DaemonKit TODO List
|
2
|
+
|
3
|
+
This is purely a drop in the bucket of what has to come...
|
4
|
+
|
5
|
+
== Eye on 0.2
|
6
|
+
|
7
|
+
* Support for dropping privileges
|
8
|
+
* Support for chroot'ing
|
9
|
+
* Altering process names (fully and temporary appending)
|
10
|
+
* bleak_house support
|
11
|
+
* Support for tweaking REE environment variables prior to launch (bash wrapper)
|
12
|
+
* Clustering support (run multiple workers out of same project)
|
13
|
+
* Full 1.9 support in the framework
|
14
|
+
|
15
|
+
== Later
|
16
|
+
|
17
|
+
* [IN PROGRESS] Error handling to the degree Rails does
|
18
|
+
* Easy configuration of an ORM of choice, including patching it if needed (ActiveRecord *cough*)
|
19
|
+
* Improved generators for creating skeleton daemons:
|
20
|
+
* Evented jabber bot
|
21
|
+
* Empty periodic event loop
|
22
|
+
* Empty periodic loop (non-evented)
|
23
|
+
* Queue (SQS, AMQP, etc) pollers
|
24
|
+
* Rake tasks for generating:
|
25
|
+
* Sys-V style init scripts
|
26
|
+
* Plenty of docs, seriously a lot of docs
|
27
|
+
* Specs & features, tons of them too
|
28
|
+
* Integration tests for the specific daemons
|
29
|
+
* Some level of thread safety, or mechanisms to ease thread safety
|
30
|
+
* Built in utilities:
|
31
|
+
* Thread pool for 1.8
|
32
|
+
* Fibre pool for 1.9
|
33
|
+
* Some activesupport-esque functions until activesupport 3.0 hits the streets
|
34
|
+
* DRY up the following:
|
35
|
+
* Loading configuration files for the daemons
|
36
|
+
|
37
|
+
* DON'T FORGET 1.9 SUPPORT
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Description:
|
2
|
+
This generator creates a new skeleton project suitable for easy
|
3
|
+
Ruby daemon development. The generated project is preconfigured
|
4
|
+
and just requires your task specific code.
|
5
|
+
|
6
|
+
Use one of the provided generators to stub out even more
|
7
|
+
functionality for common daemon patterns.
|
@@ -0,0 +1,161 @@
|
|
1
|
+
class DaemonKitGenerator < RubiGen::Base
|
2
|
+
|
3
|
+
DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
|
4
|
+
Config::CONFIG['ruby_install_name'])
|
5
|
+
|
6
|
+
VALID_GENERATORS = ['default', 'jabber', 'cron', 'amqp', 'nanite_agent', 'ruote']
|
7
|
+
|
8
|
+
DEPLOYERS = ['none', 'capistrano']
|
9
|
+
|
10
|
+
default_options :shebang => DEFAULT_SHEBANG, :author => nil
|
11
|
+
|
12
|
+
attr_reader :daemon_name
|
13
|
+
attr_reader :installer
|
14
|
+
attr_reader :deployer
|
15
|
+
attr_reader :cucumber
|
16
|
+
|
17
|
+
def initialize(runtime_args, runtime_options = {})
|
18
|
+
super
|
19
|
+
usage if args.empty?
|
20
|
+
@destination_root = File.expand_path(args.shift)
|
21
|
+
@daemon_name = base_name
|
22
|
+
extract_options
|
23
|
+
end
|
24
|
+
|
25
|
+
def manifest
|
26
|
+
# ensure some sanity
|
27
|
+
unless VALID_GENERATORS.include?( installer )
|
28
|
+
$stderr.puts "Invalid generator: '#{installer}'."
|
29
|
+
$stderr.puts "Valid generators are: #{VALID_GENERATORS.join(', ')}"
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
|
33
|
+
unless DEPLOYERS.include?( deployer )
|
34
|
+
$stderr.puts "Invalid deployment mechanism: '#{deployer}'."
|
35
|
+
$stderr.puts "Valid deployers are: #{DEPLOYERS.join(', ')}"
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
|
39
|
+
script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
|
40
|
+
|
41
|
+
record do |m|
|
42
|
+
# Ensure appropriate folder(s) exists
|
43
|
+
m.directory ''
|
44
|
+
|
45
|
+
# Create stubs
|
46
|
+
# m.template "template.rb", "some_file_after_erb.rb"
|
47
|
+
# m.template_copy_each ["template.rb", "template2.rb"]
|
48
|
+
# m.file "file", "some_file_copied"
|
49
|
+
# m.file_copy_each ["path/to/file", "path/to/file2"]
|
50
|
+
|
51
|
+
# Readme
|
52
|
+
m.template "README", "README"
|
53
|
+
m.template "Rakefile", "Rakefile"
|
54
|
+
|
55
|
+
# Executable
|
56
|
+
m.directory "bin"
|
57
|
+
m.template "bin/daemon.erb", "bin/#{daemon_name}", script_options
|
58
|
+
|
59
|
+
# Generator
|
60
|
+
if installer == "default"
|
61
|
+
m.directory "libexec"
|
62
|
+
m.template "libexec/daemon.erb", "libexec/#{daemon_name}-daemon.rb"
|
63
|
+
else
|
64
|
+
m.dependency installer, [daemon_name], :destination => destination_root, :collision => :force
|
65
|
+
end
|
66
|
+
|
67
|
+
# Config/Environment
|
68
|
+
m.directory "config"
|
69
|
+
m.file "config/arguments.rb", "config/arguments.rb"
|
70
|
+
m.file "config/boot.rb", "config/boot.rb"
|
71
|
+
m.template "config/environment.rb", "config/environment.rb"
|
72
|
+
m.directory "config/environments"
|
73
|
+
%w{ development test production }.each { |f| m.file "config/environments/#{f}.rb", "config/environments/#{f}.rb" }
|
74
|
+
m.directory "config/pre-daemonize"
|
75
|
+
m.file "config/pre-daemonize/readme", "config/pre-daemonize/readme"
|
76
|
+
m.directory "config/post-daemonize"
|
77
|
+
m.file "config/post-daemonize/readme", "config/post-daemonize/readme"
|
78
|
+
m.directory "script"
|
79
|
+
m.file "script/destroy", "script/destroy", script_options
|
80
|
+
m.file "script/console", "script/console", script_options
|
81
|
+
m.file "script/generate", "script/generate", script_options
|
82
|
+
|
83
|
+
# Libraries
|
84
|
+
m.directory "lib"
|
85
|
+
m.file "lib/daemon.rb", "lib/#{daemon_name}.rb", :collision => :skip
|
86
|
+
|
87
|
+
# Tasks
|
88
|
+
m.directory "tasks"
|
89
|
+
|
90
|
+
# Tests
|
91
|
+
m.dependency "rspec", [daemon_name], :destination => destination_root, :collision => :force
|
92
|
+
if cucumber
|
93
|
+
m.dependency "cucumber", [], :destination => destination_root, :collision => :force
|
94
|
+
end
|
95
|
+
|
96
|
+
# Deployers
|
97
|
+
unless deployer == 'none'
|
98
|
+
m.dependency "deploy_#{deployer}", [daemon_name], :destination => destination_root, :collision => :force
|
99
|
+
end
|
100
|
+
|
101
|
+
# Others
|
102
|
+
m.directory "log"
|
103
|
+
m.directory "tmp"
|
104
|
+
m.directory "vendor"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
protected
|
109
|
+
def banner
|
110
|
+
<<-EOS
|
111
|
+
Creates a preconfigured environment for writing Ruby daemon processes.
|
112
|
+
|
113
|
+
USAGE: #{spec.name} /path/to/your/daemon [options]
|
114
|
+
EOS
|
115
|
+
end
|
116
|
+
|
117
|
+
def add_options!(opts)
|
118
|
+
opts.separator ''
|
119
|
+
opts.separator 'Options:'
|
120
|
+
# For each option below, place the default
|
121
|
+
# at the top of the file next to "default_options"
|
122
|
+
# opts.on("-a", "--author=\"Your Name\"", String,
|
123
|
+
# "Some comment about this option",
|
124
|
+
# "Default: none") { |o| options[:author] = o }
|
125
|
+
|
126
|
+
opts.on("-i", "--install=generator", String,
|
127
|
+
"Select a generator to use (other than the default).",
|
128
|
+
"Available generators: #{VALID_GENERATORS.join(', ')}",
|
129
|
+
"Defaults to: default") do |installer|
|
130
|
+
options[:installer] = installer
|
131
|
+
end
|
132
|
+
|
133
|
+
opts.on("-d", "--deploy-with=config", String,
|
134
|
+
"Select an optional deployment mechanism.",
|
135
|
+
"Available deployers: #{DEPLOYERS.join(', ')}",
|
136
|
+
"Defaults to: none") do |deploy|
|
137
|
+
options[:deployer] = deploy
|
138
|
+
end
|
139
|
+
|
140
|
+
opts.on("--cucumber",
|
141
|
+
"Install cucumber.") do
|
142
|
+
options[:cucumber] = true
|
143
|
+
end
|
144
|
+
|
145
|
+
opts.on("-r", "--ruby=path", String,
|
146
|
+
"Path to the Ruby binary of your choice (otherwise scripts use env, dispatchers current path).",
|
147
|
+
"Default: #{DEFAULT_SHEBANG}") { |x| options[:shebang] = x }
|
148
|
+
opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
|
149
|
+
end
|
150
|
+
|
151
|
+
def extract_options
|
152
|
+
# for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
|
153
|
+
# Templates can access these value via the attr_reader-generated methods, but not the
|
154
|
+
# raw instance variable value.
|
155
|
+
# @author = options[:author]
|
156
|
+
@installer = options[:installer] || 'default'
|
157
|
+
@deployer = (options[:deployer] || 'none').strip
|
158
|
+
@cucumber = options[:cucumber] || false
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
DaemonKit README
|
2
|
+
================
|
3
|
+
|
4
|
+
DaemonKit has generated a skeleton Ruby daemon for you to build on. Please read
|
5
|
+
through this file to ensure you get going quickly.
|
6
|
+
|
7
|
+
Directories
|
8
|
+
===========
|
9
|
+
|
10
|
+
bin/
|
11
|
+
<%= daemon_name %> - Stub executable to control your daemon with
|
12
|
+
|
13
|
+
config/
|
14
|
+
Environment configuration files
|
15
|
+
|
16
|
+
lib/
|
17
|
+
Place for your libraries
|
18
|
+
|
19
|
+
libexec/
|
20
|
+
<%= daemon_name %>.rb - Your daemon code
|
21
|
+
|
22
|
+
log/
|
23
|
+
Log files based on the environment name
|
24
|
+
|
25
|
+
spec/
|
26
|
+
rspec's home
|
27
|
+
|
28
|
+
tasks/
|
29
|
+
Place for rake tasks
|
30
|
+
|
31
|
+
vendor/
|
32
|
+
Place for unpacked gems and DaemonKit
|
33
|
+
|
34
|
+
tmp/
|
35
|
+
Scratch folder
|
36
|
+
|
37
|
+
|
38
|
+
Logging
|
39
|
+
=======
|
40
|
+
|
41
|
+
One of the biggest issues with writing daemons are gettign insight into what your
|
42
|
+
daemons are doing. Logging with DaemonKit is simplified as DaemonKit creates log
|
43
|
+
files per environment in log.
|
44
|
+
|
45
|
+
On all environments except production the log level is set to DEBUG, but you can
|
46
|
+
toggle the log level by sending the running daemon SIGUSR1 and SIGUSR2 signals.
|
47
|
+
SIGUSR1 will toggle between DEBUG and INFO levels, SIGUSR2 will blatantly set the
|
48
|
+
level to DEBUG.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# Argument handling for your daemon is configured here.
|
2
|
+
#
|
3
|
+
# You have access to two variables when this file is
|
4
|
+
# parsed. The first is +opts+, which is the object yielded from
|
5
|
+
# +OptionParser.new+, the second is +@options+ which is a standard
|
6
|
+
# Ruby hash that is later accessible through
|
7
|
+
# DaemonKit.arguments.options and can be used in your daemon process.
|
8
|
+
|
9
|
+
# Here is an example:
|
10
|
+
# opts.on('-f', '--foo FOO', 'Set foo') do |foo|
|
11
|
+
# @options[:foo] = foo
|
12
|
+
# end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Don't change this file!
|
2
|
+
# Configure your daemon in config/environment.rb
|
3
|
+
|
4
|
+
DAEMON_ROOT = "#{File.expand_path(File.dirname(__FILE__))}/.." unless defined?( DAEMON_ROOT )
|
5
|
+
|
6
|
+
module DaemonKit
|
7
|
+
class << self
|
8
|
+
def boot!
|
9
|
+
unless booted?
|
10
|
+
pick_boot.run
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def booted?
|
15
|
+
defined? DaemonKit::Initializer
|
16
|
+
end
|
17
|
+
|
18
|
+
def pick_boot
|
19
|
+
(vendor_kit? ? VendorBoot : GemBoot).new
|
20
|
+
end
|
21
|
+
|
22
|
+
def vendor_kit?
|
23
|
+
File.exists?( "#{DAEMON_ROOT}/vendor/daemon_kit" )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Boot
|
28
|
+
def run
|
29
|
+
load_initializer
|
30
|
+
DaemonKit::Initializer.run
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class VendorBoot < Boot
|
35
|
+
def load_initializer
|
36
|
+
require "#{DAEMON_ROOT}/vendor/daemon_kit/lib/daemon_kit/initializer"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class GemBoot < Boot
|
41
|
+
def load_initializer
|
42
|
+
begin
|
43
|
+
require 'rubygems'
|
44
|
+
gem 'kennethkalmer-daemon-kit'
|
45
|
+
require 'daemon_kit/initializer'
|
46
|
+
rescue Gem::LoadError
|
47
|
+
begin
|
48
|
+
gem 'daemon-kit'
|
49
|
+
require 'daemon_kit/initializer'
|
50
|
+
rescue Gem::LoadError => e
|
51
|
+
msg = <<EOF
|
52
|
+
You are missing the daemon-kit gem. Please install one of the following gems:
|
53
|
+
|
54
|
+
* Unstable - sudo gem install kennethkalmer-daemon-kit -s http://gems.github.com/
|
55
|
+
* Stable - sudo gem install daemon-kit
|
56
|
+
|
57
|
+
NOTE: The 'unstable' gem is loaded first, before falling back to the stable gem!
|
58
|
+
|
59
|
+
EOF
|
60
|
+
$stderr.puts msg
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
DaemonKit.boot!
|
@@ -0,0 +1,23 @@
|
|
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
|
+
# Force the daemon to be killed after X seconds from asking it to
|
15
|
+
# config.force_kill_wait = 30
|
16
|
+
|
17
|
+
# Log backraces when a thread/daemon dies (Recommended)
|
18
|
+
# config.backtraces = true
|
19
|
+
|
20
|
+
# Configure the safety net (see DaemonKit::Safety)
|
21
|
+
# config.safety_net.handler = :mail # (or :hoptoad )
|
22
|
+
# config.safety_net.mail.host = 'localhost'
|
23
|
+
end
|
@@ -0,0 +1,12 @@
|
|
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 first, and inside a DaemonKit::Initializer block. The
|
5
|
+
# remaning files then simply required into the running process.
|
6
|
+
#
|
7
|
+
# These files are mostly useful for operations that should fail blatantly
|
8
|
+
# before daemonizing, like loading gems.
|
9
|
+
#
|
10
|
+
# Be careful not to open any form of IO in here and expecting it to be
|
11
|
+
# open inside the running daemon since all IO instances are closed when
|
12
|
+
# 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
|