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,187 @@
|
|
1
|
+
module DaemonKit
|
2
|
+
|
3
|
+
# Dual purpose class that is a) responsible for parsing incoming workitems and
|
4
|
+
# delegating to the correct RuotePseudoParticipant, and b) wrapping the
|
5
|
+
# workitem hash into something a bit more digestable.
|
6
|
+
class RuoteWorkitem
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# = Process incoming commands via an AMQP queue
|
11
|
+
#
|
12
|
+
# Expects a JSON workitem from ruote that has these fields set in
|
13
|
+
# fields key:
|
14
|
+
#
|
15
|
+
# {
|
16
|
+
# 'reply_queue' => 'queue to send replies to',
|
17
|
+
# 'params' => {
|
18
|
+
# 'command' => '/actor/method'
|
19
|
+
# }
|
20
|
+
# }
|
21
|
+
#
|
22
|
+
# == Notes on the command key:
|
23
|
+
#
|
24
|
+
# It looks like a resource, and will be treated as such. Is should
|
25
|
+
# be in the format of +/class/method+, and it will be passed the
|
26
|
+
# complete workitem as a hash.
|
27
|
+
#
|
28
|
+
# == Notes on replies
|
29
|
+
#
|
30
|
+
# Replies are sent back to the queue specified in the +reply_queue+ key.
|
31
|
+
#
|
32
|
+
# == Notes on errors
|
33
|
+
#
|
34
|
+
# Where daemon-kit detects errors in attempting to parse and delegate the
|
35
|
+
# workitems, it will reply to the engine and set the following field with
|
36
|
+
# the error information:
|
37
|
+
#
|
38
|
+
# daemon_kit.error
|
39
|
+
def process( transport, workitem )
|
40
|
+
# keep it singleton
|
41
|
+
@instance ||= new
|
42
|
+
|
43
|
+
work = parse( workitem )
|
44
|
+
|
45
|
+
# Invalid JSON... mmm
|
46
|
+
return if work.nil?
|
47
|
+
|
48
|
+
DaemonKit.logger.warn "Processing workitem that has timed out!" if work.timed_out?
|
49
|
+
|
50
|
+
target, method = parse_command( work )
|
51
|
+
|
52
|
+
if target.nil? || method.nil?
|
53
|
+
msg = "Missing target/method in command parameter, or command parameter missing"
|
54
|
+
DaemonKit.logger.error( msg )
|
55
|
+
work["__error__"] = msg
|
56
|
+
|
57
|
+
elsif target.public_methods.map { |m| m.to_s }.include?( method ) # 1.8.x => [ 'foo' ]
|
58
|
+
target.perform( method, work ) # 1.9.x => [ :foo ]
|
59
|
+
|
60
|
+
else
|
61
|
+
msg = "Workitem cannot be processes: '#{method}' not exposed by #{target.inspect}"
|
62
|
+
DaemonKit.logger.error( msg )
|
63
|
+
p [ :work, work.inspect ]
|
64
|
+
work["__error__"] = msg
|
65
|
+
end
|
66
|
+
|
67
|
+
reply_to_engine( transport, work )
|
68
|
+
end
|
69
|
+
|
70
|
+
# Extract the class and method name from the workitem, then pick the matching
|
71
|
+
# class from the registered list of participants
|
72
|
+
def parse_command( work )
|
73
|
+
return nil if work['params']['command'].nil?
|
74
|
+
|
75
|
+
_, klass, method = work['params']['command'].split('/')
|
76
|
+
|
77
|
+
instance = RuoteParticipants.instance.participants[ klass ]
|
78
|
+
|
79
|
+
if instance.nil?
|
80
|
+
msg = "No instance registered for #{klass}"
|
81
|
+
DaemonKit.logger.error( msg )
|
82
|
+
raise DaemonKit::MissingParticipant, msg
|
83
|
+
end
|
84
|
+
|
85
|
+
return instance, method
|
86
|
+
end
|
87
|
+
|
88
|
+
def reply_to_engine( transport, response )
|
89
|
+
send( "reply_via_#{transport}", response )
|
90
|
+
end
|
91
|
+
|
92
|
+
def reply_via_amqp( response )
|
93
|
+
DaemonKit.logger.debug("Replying to engine via AMQP with #{response.inspect}")
|
94
|
+
::MQ.queue( response['params']['reply_queue'] ).publish( response.to_json )
|
95
|
+
|
96
|
+
response
|
97
|
+
end
|
98
|
+
|
99
|
+
def parse( workitem )
|
100
|
+
begin
|
101
|
+
return new( JSON.parse( workitem ) )
|
102
|
+
rescue JSON::ParserError => e
|
103
|
+
DaemonKit.logger.error "No valid JSON payload found in #{workitem}"
|
104
|
+
return nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def initialize( workitem = {} )
|
110
|
+
@workitem = workitem
|
111
|
+
end
|
112
|
+
|
113
|
+
def fei
|
114
|
+
@workitem['fei']
|
115
|
+
end
|
116
|
+
|
117
|
+
def short_fei
|
118
|
+
@short_fei ||=
|
119
|
+
'(' + [
|
120
|
+
'fei', self.fei['owfe_version'], self.fei['engine_id'],
|
121
|
+
self.fei['workflow_definition_url'], self.fei['workflow_definition_name'],
|
122
|
+
self.fei['workflow_definition_revision'], self.fei['wfid'],
|
123
|
+
self.fei['expression_name'], self.fei['expid']
|
124
|
+
].join(' ') + ')'
|
125
|
+
end
|
126
|
+
|
127
|
+
def dispatch_time
|
128
|
+
@dispath_time ||= Time.parse( @workitem['dispatch_time'] )
|
129
|
+
end
|
130
|
+
|
131
|
+
def last_modified
|
132
|
+
@last_modified ||= Time.parse( @workitem['last_modified'] )
|
133
|
+
end
|
134
|
+
|
135
|
+
def participant_name
|
136
|
+
@workitem['participant_name']
|
137
|
+
end
|
138
|
+
|
139
|
+
def has_field?(a)
|
140
|
+
self.fields.keys.include?( a )
|
141
|
+
end
|
142
|
+
|
143
|
+
def fields
|
144
|
+
@workitem['fields'] ||= @workitem['attributes']
|
145
|
+
end
|
146
|
+
|
147
|
+
# backwards compatible..
|
148
|
+
|
149
|
+
alias :attributes :fields
|
150
|
+
alias :has_attribute? :has_field?
|
151
|
+
|
152
|
+
|
153
|
+
def []( key )
|
154
|
+
self.fields[ key ]
|
155
|
+
end
|
156
|
+
|
157
|
+
def []=( key, value )
|
158
|
+
self.fields[ key ] = value
|
159
|
+
end
|
160
|
+
|
161
|
+
def to_json
|
162
|
+
@workitem.to_json
|
163
|
+
end
|
164
|
+
|
165
|
+
# Look at the workitem payload and attempt to determine if this workitem
|
166
|
+
# has timed out or not. This method will only ever work if you used the
|
167
|
+
# +:timeout: parameter was set for the expression.
|
168
|
+
def timed_out?
|
169
|
+
key = fei['wfid'] + '__' + fei['expid']
|
170
|
+
|
171
|
+
if self.fields["__timeouts__"] && timeout = self.fields["__timeouts__"][ key ]
|
172
|
+
return Time.at( timeout.last ) < Time.now
|
173
|
+
end
|
174
|
+
|
175
|
+
return false
|
176
|
+
end
|
177
|
+
|
178
|
+
def method_missing( method_name, *args )
|
179
|
+
if self.fields.keys.include?( method_name.to_s )
|
180
|
+
return self.fields[ method_name.to_s ]
|
181
|
+
end
|
182
|
+
|
183
|
+
super
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
187
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module DaemonKit
|
2
|
+
# Provides a wrapper for running code inside a 'safety net' Any
|
3
|
+
# exceptions raised inside a safety net is handled and reported via
|
4
|
+
# loggers, email or Hoptoad.
|
5
|
+
#
|
6
|
+
# The safety net can be configured via DaemonKit.config.safety,
|
7
|
+
# which holds the only instance of the safety net.
|
8
|
+
class Safety
|
9
|
+
|
10
|
+
# Who get's notified.
|
11
|
+
@handler = nil
|
12
|
+
attr_accessor :handler
|
13
|
+
|
14
|
+
# Registered error handlers
|
15
|
+
@error_handlers = {}
|
16
|
+
attr_reader :error_handlers
|
17
|
+
|
18
|
+
class << self
|
19
|
+
|
20
|
+
# Singleton
|
21
|
+
@instance = nil
|
22
|
+
|
23
|
+
def instance
|
24
|
+
@instance ||= new
|
25
|
+
end
|
26
|
+
private :new
|
27
|
+
|
28
|
+
# Run the provided block inside a safety net.
|
29
|
+
def run(&block)
|
30
|
+
self.instance.run(&block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def register_error_handler( klass )
|
34
|
+
name = klass.to_s.split('::').last.downcase
|
35
|
+
|
36
|
+
DaemonKit.logger.debug( "Registering error handler '#{name}' (#{klass})" ) if DaemonKit.logger
|
37
|
+
|
38
|
+
instance.instance_eval( <<-EOF, __FILE__, __LINE__ )
|
39
|
+
def #{name}
|
40
|
+
@#{name} ||= #{klass}.instance
|
41
|
+
end
|
42
|
+
EOF
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Run the provided block inside a safety net.
|
47
|
+
def run(&block)
|
48
|
+
begin
|
49
|
+
block.call
|
50
|
+
rescue => e
|
51
|
+
# Log
|
52
|
+
DaemonKit.logger.fatal "Safety net caught exception: #{e.message}"
|
53
|
+
DaemonKit.logger.fatal "Backtrace: #{e.backtrace.join("\n ")}"
|
54
|
+
|
55
|
+
get_handler.handle_exception( e ) if get_handler
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_handler
|
60
|
+
if @handler && self.respond_to?( @handler )
|
61
|
+
h = send( @handler )
|
62
|
+
return h if h.class.ancestors.include?( DaemonKit::ErrorHandlers::Base )
|
63
|
+
end
|
64
|
+
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Object
|
71
|
+
class << self
|
72
|
+
def safely(&block)
|
73
|
+
DaemonKit::Safety.run(&block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def safely(&block)
|
78
|
+
DaemonKit::Safety.run(&block)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Load our error handlers
|
83
|
+
require 'daemon_kit/error_handlers/base'
|
84
|
+
require 'daemon_kit/error_handlers/hoptoad'
|
@@ -0,0 +1,123 @@
|
|
1
|
+
namespace :daemon_kit do
|
2
|
+
namespace :freeze do
|
3
|
+
desc "Lock this application to the current gem (by unpacking it into vendor/daemon_kit)"
|
4
|
+
task :gems do
|
5
|
+
deps = %w()
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rubygems/gem_runner'
|
8
|
+
|
9
|
+
kit = (version = ENV['VERSION']) ?
|
10
|
+
Gem.cache.find_name('daemon-kit', "= #{version}").first :
|
11
|
+
Gem.cache.find_name('daemon-kit').sort_by { |g| g.version }.last
|
12
|
+
|
13
|
+
version ||= kit.version
|
14
|
+
|
15
|
+
unless kit
|
16
|
+
puts "No daemon_kit gem #{version} is installed. Do 'gem list daemon-kit' to see what you have available."
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
puts "Freezing the gem for DaemonKit #{kit.version}"
|
21
|
+
mkdir_p "vendor"
|
22
|
+
|
23
|
+
begin
|
24
|
+
chdir("vendor") do
|
25
|
+
kit.dependencies.select { |g| deps.include? g.name }.each do |g|
|
26
|
+
Gem::GemRunner.new.run(["unpack", g.name, "--version", g.version_requirements.to_s])
|
27
|
+
mv(Dir.glob("#{g.name}*").first, g.name)
|
28
|
+
end
|
29
|
+
|
30
|
+
Gem::GemRunner.new.run(["unpack", "daemon-kit", "--version", "=#{version}"])
|
31
|
+
FileUtils.mv(Dir.glob("daemon-kit*").first, "daemon-kit")
|
32
|
+
end
|
33
|
+
rescue Exception
|
34
|
+
rm_rf "vendor/daemon-kit"
|
35
|
+
raise
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'Lock to latest edge daemon_kit'
|
40
|
+
task :edge do
|
41
|
+
require 'open-uri'
|
42
|
+
#version = ENV["RELEASE"] || "edge"
|
43
|
+
commits = "http://github.com/api/v1/yaml/kennethkalmer/daemon-kit/commits/master"
|
44
|
+
url = "http://github.com/kennethkalmer/daemon-kit/zipball/master"
|
45
|
+
|
46
|
+
rm_rf "vendor/daemon-kit"
|
47
|
+
|
48
|
+
chdir 'vendor' do
|
49
|
+
latest_revision = YAML.load(open(commits))["commits"].first["id"]
|
50
|
+
|
51
|
+
puts "Downloading DaemonKit from #{url}"
|
52
|
+
File.open('daemon-kit.zip', 'wb') do |dst|
|
53
|
+
open url do |src|
|
54
|
+
while chunk = src.read(4096)
|
55
|
+
dst << chunk
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
puts 'Unpacking DaemonKit'
|
61
|
+
rm_rf 'daemon-kit'
|
62
|
+
`unzip daemon-kit.zip`
|
63
|
+
FileUtils.mv(Dir.glob("kennethkalmer-daemon-kit*").first, "daemon-kit")
|
64
|
+
%w(daemon-kit.zip).each do |goner|
|
65
|
+
rm_f goner
|
66
|
+
end
|
67
|
+
|
68
|
+
touch "REVISION_#{latest_revision}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
desc "Upgrade your local files for a daemon after upgrading daemon-kit"
|
75
|
+
task :upgrade => 'environment' do
|
76
|
+
# Run these
|
77
|
+
%w{ initializers rakefile scripts gemfile }.each do |t|
|
78
|
+
Rake::Task["daemon_kit:upgrade:#{t}"].invoke
|
79
|
+
end
|
80
|
+
|
81
|
+
puts
|
82
|
+
puts "#{DaemonKit.configuration.daemon_name} has been upgraded."
|
83
|
+
end
|
84
|
+
|
85
|
+
namespace :upgrade do
|
86
|
+
# Upgrade the initializers
|
87
|
+
task :initializers do
|
88
|
+
copy_framework_template( 'config', 'boot.rb' )
|
89
|
+
|
90
|
+
if File.directory?( File.join(DaemonKit.root, 'config', 'initializers') )
|
91
|
+
mv File.join(DaemonKit.root, 'config', 'initializers'), File.join(DAEMON_ROOT, 'config', 'pre-daemonize')
|
92
|
+
copy_framework_template( 'config', 'pre-daemonize', 'readme' )
|
93
|
+
end
|
94
|
+
|
95
|
+
unless File.directory?( File.join(DAEMON_ROOT, 'config', 'post-daemonize') )
|
96
|
+
mkdir_p File.join(DAEMON_ROOT, 'config', 'post-daemonize')
|
97
|
+
copy_framework_template( 'config', 'post-daemonize', 'readme' )
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Upgrade the Rakefile
|
102
|
+
task :rakefile do
|
103
|
+
copy_framework_template( 'Rakefile' )
|
104
|
+
end
|
105
|
+
|
106
|
+
# Upgrade the scripts
|
107
|
+
task :scripts do
|
108
|
+
%w{ console destroy generate }.each do |s|
|
109
|
+
copy_framework_template( "script", s )
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
# Upgrade the Gemfile
|
114
|
+
task :gemfile do
|
115
|
+
copy_framework_template( 'Gemfile' )
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def copy_framework_template( *args )
|
121
|
+
src_dir = File.join(DaemonKit.framework_root, 'lib', 'generators', 'daemon_kit', 'app', 'templates')
|
122
|
+
cp File.join( src_dir, *args ), File.join( DaemonKit.root, *args )
|
123
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
namespace :god do
|
4
|
+
desc "Generate a stub god config file template for the daemon"
|
5
|
+
task :template => 'environment' do
|
6
|
+
# Preserve local changes
|
7
|
+
if File.exists?( "#{DaemonKit.root}/config/god.erb" ) && ENV['FORCE'].nil?
|
8
|
+
puts "Template already exists, use FORCE=1 to overwrite."
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
cp "#{DaemonKit.framework_root}/templates/god/god.erb", "#{DaemonKit.root}/config/god.erb"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Parse the god config template into a god config file"
|
16
|
+
task :generate => 'environment' do
|
17
|
+
|
18
|
+
unless File.exists?( "#{DaemonKit.root}/config/god.erb" )
|
19
|
+
Rake::Task["god:template"].invoke
|
20
|
+
end
|
21
|
+
|
22
|
+
name = DaemonKit.configuration.daemon_name
|
23
|
+
|
24
|
+
File.open( "#{DaemonKit.root}/config/#{name}.god", "w+" ) do |f|
|
25
|
+
t = File.read( "#{DaemonKit.root}/config/god.erb" )
|
26
|
+
f.write( ERB.new( t ).result( binding ) )
|
27
|
+
end
|
28
|
+
|
29
|
+
puts "god config generated in config/#{name}.god"
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Load the god file into god"
|
33
|
+
task :load => 'environment' do
|
34
|
+
name = DaemonKit.configuration.daemon_name
|
35
|
+
|
36
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god load #{DaemonKit.root}/config/#{name}.god"
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Refresh the god config file in the running god"
|
40
|
+
task :refresh => 'environment' do
|
41
|
+
name = DaemonKit.configuration.daemon_name
|
42
|
+
|
43
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god unmonitor #{name}"
|
44
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god remove #{name}"
|
45
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god load #{DaemonKit.root}/config/#{name}.god"
|
46
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god monitor #{name}"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Start god monitoring of the config file"
|
50
|
+
task :monitor => 'environment' do
|
51
|
+
name = DaemonKit.configuration.daemon_name
|
52
|
+
|
53
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god monitor #{name}"
|
54
|
+
end
|
55
|
+
|
56
|
+
desc "Stop god monitoring of the config file"
|
57
|
+
task :unmonitor => 'environment' do
|
58
|
+
name = DaemonKit.configuration.daemon_name
|
59
|
+
|
60
|
+
sh "#{$RAKE_USE_SUDO ? 'sudo' : ''} god unmonitor #{name}"
|
61
|
+
end
|
62
|
+
end
|