amqp-daemon-kit 0.1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Configuration.txt +110 -0
- data/Deployment.txt +113 -0
- data/History.txt +131 -0
- data/Logging.txt +96 -0
- data/PostInstall.txt +6 -0
- data/README.rdoc +132 -0
- data/Rakefile +29 -0
- data/RuoteParticipants.txt +113 -0
- data/TODO.txt +27 -0
- data/bin/daemon-kit +18 -0
- data/config/website.yml +2 -0
- data/daemon-kit.gemspec +265 -0
- data/lib/daemon_kit.rb +60 -0
- data/lib/daemon_kit/abstract_logger.rb +249 -0
- data/lib/daemon_kit/application.rb +230 -0
- data/lib/daemon_kit/arguments.rb +165 -0
- data/lib/daemon_kit/commands/console.rb +38 -0
- data/lib/daemon_kit/commands/destroy.rb +10 -0
- data/lib/daemon_kit/commands/generate.rb +10 -0
- data/lib/daemon_kit/config.rb +113 -0
- data/lib/daemon_kit/console_daemon.rb +2 -0
- data/lib/daemon_kit/core_ext.rb +1 -0
- data/lib/daemon_kit/core_ext/configurable.rb +96 -0
- data/lib/daemon_kit/core_ext/string.rb +22 -0
- data/lib/daemon_kit/cron.rb +67 -0
- data/lib/daemon_kit/cucumber/world.rb +38 -0
- data/lib/daemon_kit/deployment/capistrano.rb +516 -0
- data/lib/daemon_kit/dk_amqp.rb +39 -0
- data/lib/daemon_kit/em.rb +43 -0
- data/lib/daemon_kit/error_handlers/base.rb +32 -0
- data/lib/daemon_kit/error_handlers/hoptoad.rb +180 -0
- data/lib/daemon_kit/exceptions.rb +15 -0
- data/lib/daemon_kit/generators.rb +67 -0
- data/lib/daemon_kit/generators/base.rb +60 -0
- data/lib/daemon_kit/initializer.rb +449 -0
- data/lib/daemon_kit/jabber.rb +171 -0
- data/lib/daemon_kit/nanite.rb +7 -0
- data/lib/daemon_kit/nanite/agent.rb +77 -0
- data/lib/daemon_kit/pid_file.rb +61 -0
- data/lib/daemon_kit/ruote_participants.rb +125 -0
- data/lib/daemon_kit/ruote_pseudo_participant.rb +68 -0
- data/lib/daemon_kit/ruote_workitem.rb +187 -0
- data/lib/daemon_kit/safety.rb +84 -0
- data/lib/daemon_kit/tasks.rb +2 -0
- data/lib/daemon_kit/tasks/environment.rake +11 -0
- data/lib/daemon_kit/tasks/framework.rake +123 -0
- data/lib/daemon_kit/tasks/god.rake +62 -0
- data/lib/daemon_kit/tasks/log.rake +8 -0
- data/lib/daemon_kit/tasks/monit.rake +29 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/CHANGELOG.rdoc +89 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/LICENSE +20 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/README.rdoc +297 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/Thorfile +69 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor.rb +244 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions.rb +296 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/create_file.rb +103 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/directory.rb +91 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/empty_directory.rb +134 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/file_manipulation.rb +223 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/actions/inject_into_file.rb +104 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/base.rb +540 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/file_binary_read.rb +9 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/hash_with_indifferent_access.rb +75 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/core_ext/ordered_hash.rb +100 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/error.rb +30 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/group.rb +271 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/invocation.rb +180 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser.rb +4 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/argument.rb +67 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/arguments.rb +150 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/option.rb +128 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/parser/options.rb +169 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/rake_compat.rb +66 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/runner.rb +314 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell.rb +83 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/basic.rb +239 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/shell/color.rb +108 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/task.rb +102 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/util.rb +224 -0
- data/lib/daemon_kit/vendor/thor-0.13.6/lib/thor/version.rb +3 -0
- data/lib/daemon_kit/xmpp.rb +100 -0
- data/lib/generators/daemon_kit/amqp/USAGE +5 -0
- data/lib/generators/daemon_kit/amqp/amqp_generator.rb +24 -0
- data/lib/generators/daemon_kit/amqp/templates/config/amqp.yml +28 -0
- data/lib/generators/daemon_kit/amqp/templates/config/pre-daemonize/amqp.rb +7 -0
- data/lib/generators/daemon_kit/amqp/templates/libexec/%app_name%-daemon.rb +37 -0
- data/lib/generators/daemon_kit/app/USAGE +7 -0
- data/lib/generators/daemon_kit/app/app_generator.rb +140 -0
- data/lib/generators/daemon_kit/app/templates/Gemfile +12 -0
- data/lib/generators/daemon_kit/app/templates/README.tt +58 -0
- data/lib/generators/daemon_kit/app/templates/Rakefile +6 -0
- data/lib/generators/daemon_kit/app/templates/bin/daemon.tt +7 -0
- data/lib/generators/daemon_kit/app/templates/config/arguments.rb +12 -0
- data/lib/generators/daemon_kit/app/templates/config/boot.rb +70 -0
- data/lib/generators/daemon_kit/app/templates/config/environment.rb.tt +26 -0
- data/lib/generators/daemon_kit/app/templates/config/environments/development.rb +2 -0
- data/lib/generators/daemon_kit/app/templates/config/environments/production.rb +5 -0
- data/lib/generators/daemon_kit/app/templates/config/environments/test.rb +2 -0
- data/lib/generators/daemon_kit/app/templates/config/post-daemonize/readme +5 -0
- data/lib/generators/daemon_kit/app/templates/config/pre-daemonize/readme +12 -0
- data/lib/generators/daemon_kit/app/templates/lib/%app_name%.rb +2 -0
- data/lib/generators/daemon_kit/app/templates/libexec/%app_name%-daemon.rb +18 -0
- data/lib/generators/daemon_kit/app/templates/script/console +3 -0
- data/lib/generators/daemon_kit/app/templates/script/destroy +3 -0
- data/lib/generators/daemon_kit/app/templates/script/generate +3 -0
- data/lib/generators/daemon_kit/capistrano/capistrano_generator.rb +26 -0
- data/lib/generators/daemon_kit/capistrano/templates/Capfile +10 -0
- data/lib/generators/daemon_kit/capistrano/templates/USAGE +10 -0
- data/lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt +67 -0
- data/lib/generators/daemon_kit/capistrano/templates/config/deploy/logrotate.erb +13 -0
- data/lib/generators/daemon_kit/capistrano/templates/config/deploy/production.rb.tt +6 -0
- data/lib/generators/daemon_kit/capistrano/templates/config/deploy/staging.rb.tt +6 -0
- data/lib/generators/daemon_kit/capistrano/templates/config/environments/staging.rb +0 -0
- data/lib/generators/daemon_kit/cron/USAGE +5 -0
- data/lib/generators/daemon_kit/cron/cron_generator.rb +24 -0
- data/lib/generators/daemon_kit/cron/templates/config/pre-daemonize/cron.rb +11 -0
- data/lib/generators/daemon_kit/cron/templates/libexec/%app_name%-daemon.rb +48 -0
- data/lib/generators/daemon_kit/cucumber/USAGE +11 -0
- data/lib/generators/daemon_kit/cucumber/cucumber_generator.rb +45 -0
- data/lib/generators/daemon_kit/cucumber/templates/config/environments/cucumber.rb +2 -0
- data/lib/generators/daemon_kit/cucumber/templates/features/step_definitions/.empty_directory +0 -0
- data/lib/generators/daemon_kit/cucumber/templates/features/support/env.rb +7 -0
- data/lib/generators/daemon_kit/cucumber/templates/script/cucumber +7 -0
- data/lib/generators/daemon_kit/cucumber/templates/tasks/cucumber.rake +13 -0
- data/lib/generators/daemon_kit/nanite_agent/USAGE +5 -0
- data/lib/generators/daemon_kit/nanite_agent/nanite_agent_generator.rb +29 -0
- data/lib/generators/daemon_kit/nanite_agent/templates/config/nanite.yml +35 -0
- data/lib/generators/daemon_kit/nanite_agent/templates/config/pre-daemonize/nanite_agent.rb +6 -0
- data/lib/generators/daemon_kit/nanite_agent/templates/lib/actors/sample.rb +11 -0
- data/lib/generators/daemon_kit/nanite_agent/templates/libexec/%app_name%-daemon.rb +31 -0
- data/lib/generators/daemon_kit/rspec/USAGE +5 -0
- data/lib/generators/daemon_kit/rspec/rspec_generator.rb +20 -0
- data/lib/generators/daemon_kit/rspec/templates/spec/%app_name%_spec.rb +11 -0
- data/lib/generators/daemon_kit/rspec/templates/spec/spec.opts +1 -0
- data/lib/generators/daemon_kit/rspec/templates/spec/spec_helper.rb +23 -0
- data/lib/generators/daemon_kit/rspec/templates/tasks/rspec.rake +21 -0
- data/lib/generators/daemon_kit/ruote/USAGE +5 -0
- data/lib/generators/daemon_kit/ruote/ruote_generator.rb +29 -0
- data/lib/generators/daemon_kit/ruote/templates/config/amqp.yml +30 -0
- data/lib/generators/daemon_kit/ruote/templates/config/pre-daemonize/ruote.rb +13 -0
- data/lib/generators/daemon_kit/ruote/templates/config/ruote.yml +23 -0
- data/lib/generators/daemon_kit/ruote/templates/lib/%app_name%.rb +4 -0
- data/lib/generators/daemon_kit/ruote/templates/lib/sample.rb +26 -0
- data/lib/generators/daemon_kit/ruote/templates/libexec/%app_name%-daemon.rb +33 -0
- data/lib/generators/daemon_kit/test_unit/USAGE +5 -0
- data/lib/generators/daemon_kit/test_unit/templates/tasks/test_unit.rake +7 -0
- data/lib/generators/daemon_kit/test_unit/templates/test/%app_name%_test.rb.tt +9 -0
- data/lib/generators/daemon_kit/test_unit/templates/test/test_helper.rb +6 -0
- data/lib/generators/daemon_kit/test_unit/test_unit_generator.rb +20 -0
- data/lib/generators/daemon_kit/xmpp/templates/config/pre-daemonize/xmpp.rb +6 -0
- data/lib/generators/daemon_kit/xmpp/templates/config/xmpp.yml +29 -0
- data/lib/generators/daemon_kit/xmpp/templates/libexec/%app_name%-daemon.rb +27 -0
- data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +24 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/spec/abstract_logger_spec.rb +126 -0
- data/spec/argument_spec.rb +70 -0
- data/spec/config_spec.rb +83 -0
- data/spec/configurable_spec.rb +56 -0
- data/spec/daemon_kit_spec.rb +7 -0
- data/spec/error_handlers_spec.rb +23 -0
- data/spec/fixtures/env.yml +15 -0
- data/spec/fixtures/noenv.yml +4 -0
- data/spec/initializer_spec.rb +26 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +27 -0
- data/tasks/cucumber.rake +13 -0
- data/tasks/rspec.rake +20 -0
- data/tasks/tests.rake +6 -0
- data/templates/god/god.erb +69 -0
- data/templates/monit/monit.erb +14 -0
- data/test/test_amqp_generator.rb +48 -0
- data/test/test_cron_generator.rb +45 -0
- data/test/test_daemon-kit_generator.rb +84 -0
- data/test/test_daemon_kit_config.rb +28 -0
- data/test/test_deploy_capistrano_generator.rb +48 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +7 -0
- data/test/test_nanite_agent_generator.rb +49 -0
- data/test/test_ruote_generator.rb +51 -0
- data/test/test_test_unit_generator.rb +46 -0
- metadata +302 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe DaemonKit::Arguments do
|
4
|
+
|
5
|
+
describe "parsing ARGV" do
|
6
|
+
|
7
|
+
it "should extract the given command" do
|
8
|
+
argv = [ 'start', '-f', 'foo' ]
|
9
|
+
res = DaemonKit::Arguments.parse( argv )
|
10
|
+
|
11
|
+
res.first.should == :start
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have a default command if missing" do
|
15
|
+
argv = [ '-h' ]
|
16
|
+
res = DaemonKit::Arguments.parse( argv )
|
17
|
+
|
18
|
+
res.first.should == :run
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should extract explicit configuration options" do
|
22
|
+
argv = [ 'start', '--config', 'environment=development' ]
|
23
|
+
res = DaemonKit::Arguments.parse( argv )
|
24
|
+
|
25
|
+
res.shift
|
26
|
+
res.first.should == [ 'environment=development' ]
|
27
|
+
|
28
|
+
res.last.should == []
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should extract implicit configuration options" do
|
32
|
+
argv = [ '-e', 'production' ]
|
33
|
+
res = DaemonKit::Arguments.parse( argv )
|
34
|
+
|
35
|
+
res.shift
|
36
|
+
res.first.should == ['environment=production']
|
37
|
+
|
38
|
+
res.last.should == []
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should extract daemon options" do
|
42
|
+
argv = [ 'start', '-h' ]
|
43
|
+
res = DaemonKit::Arguments.parse( argv )
|
44
|
+
|
45
|
+
res.shift
|
46
|
+
res.first.should == []
|
47
|
+
|
48
|
+
res.last.should == [ '-h' ]
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should handle different ordered configurations easily" do
|
52
|
+
argv = [ '--pidfile', '/tmp/piddy', '--log', '/tmp/loggy' ]
|
53
|
+
res = DaemonKit::Arguments.configuration( argv )
|
54
|
+
|
55
|
+
# No additional args
|
56
|
+
res.last.should be_empty
|
57
|
+
|
58
|
+
res.first[0].should == "pid_file=/tmp/piddy"
|
59
|
+
res.first[1].should == "log_path=/tmp/loggy"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should handle mixed configurations easily" do
|
63
|
+
argv = [ '--rest', 'yes', '-l', '/tmp/loggy', '-f', 'bar' ]
|
64
|
+
res = DaemonKit::Arguments.configuration( argv )
|
65
|
+
|
66
|
+
res.first.should == [ 'log_path=/tmp/loggy' ]
|
67
|
+
res.last.should == [ '--rest', 'yes', '-f', 'bar' ]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe DaemonKit::Config do
|
4
|
+
|
5
|
+
describe "working with config data" do
|
6
|
+
before(:each) do
|
7
|
+
@config = DaemonKit::Config.new('foo' => 'bar', 'nes' => { 'ted' => 'value' }, 'dash-ed' => 'keys')
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should have string key access to values" do
|
11
|
+
@config['foo'].should == 'bar'
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have symbol key access to values" do
|
15
|
+
@config[:foo].should == 'bar'
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should have instance accessors to values" do
|
19
|
+
@config.foo.should == 'bar'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should have nested instance accessors to values" do
|
23
|
+
@config.nes.ted.should == 'value'
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return the config as a hash" do
|
27
|
+
@config.to_h.should == { 'foo' => 'bar', 'nes' => { 'ted' => 'value' }, 'dash-ed' => 'keys' }
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to symbolize keys in returned hash" do
|
31
|
+
@config.to_h(true).should == { :foo => 'bar', :nes => { :ted => 'value' }, :'dash-ed' => 'keys' }
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be able to handle dashed keys via accessors" do
|
35
|
+
@config.dash_ed.should == 'keys'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "parsing files" do
|
40
|
+
before(:all) do
|
41
|
+
FileUtils.mkdir_p( DAEMON_ROOT + "/config" )
|
42
|
+
FileUtils.cp( File.dirname(__FILE__) + '/fixtures/env.yml', DAEMON_ROOT + '/config/' )
|
43
|
+
FileUtils.cp( File.dirname(__FILE__) + '/fixtures/noenv.yml', DAEMON_ROOT + '/config/' )
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should parse env keys correctly" do
|
47
|
+
config = DaemonKit::Config.load('env')
|
48
|
+
|
49
|
+
config.test.should == 'yes!'
|
50
|
+
config.array.should_not be_empty
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should not be worried about missing env keys" do
|
54
|
+
config = DaemonKit::Config.load('noenv')
|
55
|
+
|
56
|
+
config.string.should == 'value'
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should accept symbol file names" do
|
60
|
+
config = DaemonKit::Config.load(:env)
|
61
|
+
config.test.should == 'yes!'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should bail on missing files" do
|
65
|
+
lambda {
|
66
|
+
DaemonKit::Config.load('missing')
|
67
|
+
}.should raise_error(ArgumentError)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should give direct hash access to a config" do
|
71
|
+
config = DaemonKit::Config.hash(:env)
|
72
|
+
|
73
|
+
config.should be_a_kind_of(Hash)
|
74
|
+
config.keys.should include('test')
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should give direct symbolized hash access to a config" do
|
78
|
+
config = DaemonKit::Config.hash(:env, true)
|
79
|
+
|
80
|
+
config.keys.should include(:test)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
class FooConfig
|
4
|
+
include DaemonKit::Configurable
|
5
|
+
|
6
|
+
configurable :has_default, true
|
7
|
+
configurable :no_default
|
8
|
+
configurable :has_lock, :locked => true
|
9
|
+
end
|
10
|
+
|
11
|
+
describe DaemonKit::Configurable do
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@foo = FooConfig.new
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should support default values" do
|
18
|
+
lambda {
|
19
|
+
@foo.has_default.should be_true
|
20
|
+
}.should_not raise_error( NoMethodError )
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should support overwriting unlocked defaults" do
|
24
|
+
lambda {
|
25
|
+
@foo.has_default = false
|
26
|
+
@foo.has_default.should be_false
|
27
|
+
}.should_not raise_error
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should support no default values" do
|
31
|
+
lambda {
|
32
|
+
@foo.no_default.should be_nil
|
33
|
+
}.should_not raise_error( NoMethodError )
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should allow setting locked values once" do
|
37
|
+
lambda {
|
38
|
+
@foo.has_lock = 1
|
39
|
+
@foo.has_lock.should == 1
|
40
|
+
|
41
|
+
@foo.has_lock = 2
|
42
|
+
@foo.has_lock.should == 1
|
43
|
+
}.should_not raise_error
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should allow bypassing the lock explicitly" do
|
47
|
+
lambda {
|
48
|
+
@foo.has_lock = 1
|
49
|
+
@foo.has_lock.should == 1
|
50
|
+
|
51
|
+
@foo.set(:has_lock, 2)
|
52
|
+
@foo.has_lock.should == 2
|
53
|
+
}.should_not raise_error
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe DaemonKit::Safety do
|
4
|
+
end
|
5
|
+
|
6
|
+
describe DaemonKit::ErrorHandlers::Mail do
|
7
|
+
it "should send an email report" do
|
8
|
+
conf = Object.new
|
9
|
+
conf.stubs(:daemon_name).returns('test')
|
10
|
+
DaemonKit.stubs(:configuration).returns(conf)
|
11
|
+
|
12
|
+
fake_smtp = Object.new
|
13
|
+
fake_smtp.expects(:start).with('localhost.localdomain', nil, nil, nil)
|
14
|
+
Net::SMTP.expects(:new).with('localhost', 25).returns(fake_smtp)
|
15
|
+
|
16
|
+
begin
|
17
|
+
raise RuntimeError, "specs don't fail :)"
|
18
|
+
rescue => e
|
19
|
+
handler = DaemonKit::ErrorHandlers::Mail.instance
|
20
|
+
handler.handle_exception( e )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
require 'daemon_kit/initializer'
|
3
|
+
|
4
|
+
describe DaemonKit::Configuration do
|
5
|
+
before(:each) do
|
6
|
+
@configuration = DaemonKit::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should know our environment" do
|
10
|
+
@configuration.environment.should_not be_nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should have a default log path" do
|
14
|
+
@configuration.log_path.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have a default log level" do
|
18
|
+
@configuration.log_level.should_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should set a default umask" do
|
22
|
+
File.umask.should_not be(0)
|
23
|
+
File.umask.should be(18)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rspec'
|
3
|
+
require 'spec'
|
4
|
+
|
5
|
+
require 'mocha'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
DAEMON_ENV = "test"
|
9
|
+
DAEMON_ROOT = "#{File.dirname(__FILE__)}/../tmp"
|
10
|
+
|
11
|
+
$:.unshift( File.dirname(__FILE__) + '/../lib' )
|
12
|
+
require 'daemon_kit'
|
13
|
+
|
14
|
+
Spec::Runner.configure do |config|
|
15
|
+
# == Mock Framework
|
16
|
+
#
|
17
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
18
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
19
|
+
#
|
20
|
+
config.mock_with :mocha
|
21
|
+
# config.mock_with :flexmock
|
22
|
+
# config.mock_with :rr
|
23
|
+
|
24
|
+
# setup a fake daemon_root
|
25
|
+
config.before(:all) { File.directory?( DAEMON_ROOT ) ? FileUtils.rm_rf("#{DAEMON_ROOT}/*") : FileUtils.mkdir_p( DAEMON_ROOT ) }
|
26
|
+
config.after(:all) { FileUtils.rm_rf("#{DAEMON_ROOT}/*") }
|
27
|
+
end
|
data/tasks/cucumber.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
begin
|
2
|
+
require 'cucumber/rake/task'
|
3
|
+
|
4
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
5
|
+
t.fork = true
|
6
|
+
t.cucumber_opts = ['--format', (ENV['CUCUMBER_FORMAT'] || 'pretty')]
|
7
|
+
end
|
8
|
+
rescue LoadError
|
9
|
+
desc 'Cucumber rake task not available'
|
10
|
+
task :features do
|
11
|
+
abort 'Cucumber rake task is not available. Be sure to install cucumber as a gem or plugin'
|
12
|
+
end
|
13
|
+
end
|
data/tasks/rspec.rake
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'spec'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'spec/rake/spectask'
|
9
|
+
|
10
|
+
desc "Run the specs under spec/models"
|
11
|
+
Spec::Rake::SpecTask.new do |t|
|
12
|
+
t.spec_opts = ['--options', "spec/spec.opts"]
|
13
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts <<-EOS
|
17
|
+
To use rspec for testing you must install rspec gem:
|
18
|
+
gem install rspec
|
19
|
+
EOS
|
20
|
+
end
|
data/tasks/tests.rake
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# This is a configuration template for 'god' process monitoring.
|
3
|
+
#
|
4
|
+
# More information can be found at http://god.rubyforge.org/
|
5
|
+
#
|
6
|
+
|
7
|
+
DAEMON_ROOT = "<%= DaemonKit.root %>"
|
8
|
+
|
9
|
+
God.watch do |w|
|
10
|
+
w.name = '<%= DaemonKit.configuration.daemon_name %>'
|
11
|
+
w.interval = 30.seconds
|
12
|
+
w.start = "/usr/bin/env DAEMON_ENV=<%= DaemonKit.env %> #{DAEMON_ROOT}/bin/<%= DaemonKit.configuration.daemon_name %> start"
|
13
|
+
w.stop = "/usr/bin/env DAEMON_ENV=<%= DaemonKit.env %> #{DAEMON_ROOT}/bin/<%= DaemonKit.configuration.daemon_name %> stop"
|
14
|
+
w.start_grace = 10.seconds
|
15
|
+
w.stop_grace = 10.seconds
|
16
|
+
w.pid_file = "<%= DaemonKit.configuration.pid_file %>"
|
17
|
+
w.behavior(:clean_pid_file)
|
18
|
+
#w.uid = 'nobody'
|
19
|
+
#w.gid = 'nobody'
|
20
|
+
|
21
|
+
w.start_if do |start|
|
22
|
+
start.condition(:process_running) do |c|
|
23
|
+
c.interval = 30.seconds
|
24
|
+
c.running = false
|
25
|
+
c.notify = 'sysadmin'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
w.restart_if do |restart|
|
30
|
+
restart.condition(:memory_usage) do |c|
|
31
|
+
c.above = 250.megabytes
|
32
|
+
c.times = [3, 5] # 3 out of 5 intervals
|
33
|
+
c.notify = 'sysadmin'
|
34
|
+
end
|
35
|
+
|
36
|
+
restart.condition(:cpu_usage) do |c|
|
37
|
+
c.above = 50.percent
|
38
|
+
c.times = 5
|
39
|
+
c.notify = 'sysadmin'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
w.lifecycle do |on|
|
44
|
+
on.condition(:flapping) do |c|
|
45
|
+
c.to_state = [:start, :restart]
|
46
|
+
c.times = 5
|
47
|
+
c.within = 5.minute
|
48
|
+
c.transition = :unmonitored
|
49
|
+
c.retry_in = 10.minutes
|
50
|
+
c.retry_times = 5
|
51
|
+
c.retry_within = 2.hours
|
52
|
+
c.notify = 'sysadmin'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
God::Contacts::Email.server_settings = {
|
58
|
+
:address => "smtp.gmail.com",
|
59
|
+
:port => 587,
|
60
|
+
:domain => "localhost",
|
61
|
+
:authentication => :plain,
|
62
|
+
:user_name => "you@gmail.com",
|
63
|
+
:password => "secret"
|
64
|
+
}
|
65
|
+
|
66
|
+
God.contact(:email) do |c|
|
67
|
+
c.name = 'sysadmin'
|
68
|
+
c.email = 'you@gmail.com'
|
69
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
#
|
2
|
+
# This monit configuration file is built from the monit wiki with some
|
3
|
+
# very basic checks on memory and CPU usage.
|
4
|
+
#
|
5
|
+
# See the man page at http://mmonit.com/monit/documentation/monit.html
|
6
|
+
# for more information.
|
7
|
+
#
|
8
|
+
check process <%= DaemonKit.configuration.daemon_name %> with pidfile <%= DaemonKit.configuration.pid_file %>
|
9
|
+
group daemons
|
10
|
+
start program = "/usr/bin/env DAEMON_ENV=<%= DaemonKit.env %> <%= DaemonKit.root %>/bin/<%= DaemonKit.configuration.daemon_name %> start"
|
11
|
+
stop program = "/usr/bin/env DAEMON_ENV=<%= DaemonKit.env %> <%= DaemonKit.root %>/bin/<%= DaemonKit.configuration.daemon_name %> stop"
|
12
|
+
if 5 restarts within 5 cycles then timeout
|
13
|
+
if cpu usage > 99% for 5 cycles then alert
|
14
|
+
if mem usage > 99% for 5 cycles then alert
|