daemon-kit 0.3.0.rc1 → 0.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +2 -0
- data/README.md +2 -1
- data/Upgrading.md +11 -0
- data/daemon-kit.gemspec +1 -1
- data/features/app_generator.feature +5 -0
- data/features/step_definitions/daemon_steps.rb +17 -0
- data/features/support/env.rb +10 -0
- data/features/support/fixtures.rb +21 -0
- data/features/upgrades.feature +11 -0
- data/gemfiles/Gemfile.ci +8 -0
- data/lib/daemon_kit/abstract_logger.rb +0 -1
- data/lib/daemon_kit/initializer.rb +21 -11
- data/lib/daemon_kit/ruote_participants.rb +11 -1
- data/lib/daemon_kit/tasks/framework.rake +17 -98
- data/lib/daemon_kit/version.rb +3 -1
- data/lib/daemon_kit/xmpp.rb +14 -5
- data/lib/generators/daemon_kit/app/app_generator.rb +8 -2
- data/lib/generators/daemon_kit/app/templates/Gemfile.tt +25 -0
- data/lib/generators/daemon_kit/app/templates/README.tt +1 -1
- data/lib/generators/daemon_kit/app/templates/config/boot.rb +1 -15
- data/lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt +0 -5
- data/lib/generators/daemon_kit/xmpp/templates/config/xmpp.yml +7 -3
- data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +1 -1
- data/{lib/generators/daemon_kit/app/templates → spec/fixtures/zero_two_three}/Gemfile +4 -0
- data/spec/fixtures/zero_two_three/README +65 -0
- data/spec/fixtures/zero_two_three/Rakefile +6 -0
- data/spec/fixtures/zero_two_three/bin/zero_two_three +8 -0
- data/spec/fixtures/zero_two_three/config/arguments.rb +12 -0
- data/spec/fixtures/zero_two_three/config/boot.rb +64 -0
- data/spec/fixtures/zero_two_three/config/environment.rb +22 -0
- data/spec/fixtures/zero_two_three/config/environments/development.rb +2 -0
- data/spec/fixtures/zero_two_three/config/post-daemonize/readme +5 -0
- data/spec/fixtures/zero_two_three/config/pre-daemonize/readme +12 -0
- data/spec/fixtures/zero_two_three/config/pre-daemonize/safely.rb +13 -0
- data/spec/fixtures/zero_two_three/lib/zero_two_three.rb +2 -0
- data/spec/fixtures/zero_two_three/libexec/zero_two_three-daemon.rb +18 -0
- data/spec/fixtures/zero_two_three/script/console +4 -0
- data/spec/fixtures/zero_two_three/script/destroy +4 -0
- data/spec/fixtures/zero_two_three/script/generate +4 -0
- data/spec/{spec.opts → fixtures/zero_two_three/spec/spec.opts} +0 -0
- data/spec/fixtures/zero_two_three/spec/spec_helper.rb +22 -0
- data/spec/fixtures/zero_two_three/spec/zero_two_three_spec.rb +11 -0
- data/spec/fixtures/zero_two_three/tasks/rspec.rake +13 -0
- data/spec/initializer_spec.rb +59 -7
- data/spec/spec_helper.rb +8 -0
- data/tasks/ci.rake +8 -0
- data/tasks/rspec.rake +1 -1
- metadata +62 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90f5bbda2dfba4dc58989fb7d284ea2b52c6b16b
|
4
|
+
data.tar.gz: 8655f358efe6044f8b916e9979970d7fa21d4844
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9302898942d1dfb22c1c9df876d72803518ad6983dc5da4515ed903ea40667a7f74c93271122e5d8042810d97981088aa61ba2767abc6f56056414c80727c1d
|
7
|
+
data.tar.gz: e2697eb00c2009c32eb7c5690353214f3d81f9dbf7d76968f2b4b05c7b8a5f38966ca90504d428aad12b3324ab6b284375da8e6ee61b01e51e7a5300c83c0926
|
data/.rspec
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
[![Code Climate](https://codeclimate.com/github/kennethkalmer/daemon-kit.png)](https://codeclimate.com/github/kennethkalmer/daemon-kit)
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/daemon-kit.png)](http://badge.fury.io/rb/daemon-kit)
|
5
5
|
[![Build Status](https://travis-ci.org/kennethkalmer/daemon-kit.png)](https://travis-ci.org/kennethkalmer/daemon-kit)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/kennethkalmer/daemon-kit/badge.png)](https://coveralls.io/r/kennethkalmer/daemon-kit)
|
6
7
|
|
7
8
|
* https://github.com/kennethkalmer/daemon-kit/wiki
|
8
9
|
* http://rdoc.info/github/kennethkalmer/daemon-kit
|
@@ -81,7 +82,7 @@ The [ruote](http://openwfe.rubyforge.org) remote participant generator speeds up
|
|
81
82
|
|
82
83
|
Depending on the generator you choose for your daemon, it might require additional gems to run.
|
83
84
|
|
84
|
-
* xmpp - [blather](http://blather.squishtech.com/)
|
85
|
+
* xmpp - [blather](http://blather.squishtech.com/) ~> 0.8.7
|
85
86
|
* cron - [rufus-scheduler](http://github.com/jmettraux/rufus-scheduler) (at least version 2.0.0)
|
86
87
|
* amqp - [amqp](http://github.com/tmm1/amqp)
|
87
88
|
* ruote - none, although [ruote](http://openwfe.rubyforge.org) should probably be running somewhere
|
data/Upgrading.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
1
|
Some important upgrading information
|
2
2
|
====================================
|
3
3
|
|
4
|
+
Upgrading to 0.3.0
|
5
|
+
------------------
|
6
|
+
|
7
|
+
From 0.2 there hasn't been any signifant changes. 0.3.0.rc2 made some changes
|
8
|
+
to the way a daemon boots, so after updating you'll need to run:
|
9
|
+
|
10
|
+
$ rake daemon_kit:upgrade
|
11
|
+
|
12
|
+
We recommend running this task on a clean repo, or branch, so you can review
|
13
|
+
the changes using your favourite diff tool.
|
14
|
+
|
4
15
|
Upgrading to 0.1.9
|
5
16
|
------------------
|
6
17
|
|
data/daemon-kit.gemspec
CHANGED
@@ -42,9 +42,9 @@ $ daemon-kit -h
|
|
42
42
|
gem.add_development_dependency(%q<cucumber>, ["~> 1.3.8"])
|
43
43
|
gem.add_development_dependency(%q<aruba>, ["~> 0.5.3"])
|
44
44
|
gem.add_development_dependency(%q<SyslogLogger>)
|
45
|
+
gem.add_development_dependency(%q<safely>, ["~> 0.3.2"])
|
45
46
|
|
46
47
|
gem.add_dependency(%q<thor>)
|
47
48
|
gem.add_runtime_dependency(%q<eventmachine>, [">= 0.12.10"])
|
48
|
-
gem.add_runtime_dependency(%q<safely>, [">= 0.3.1"])
|
49
49
|
gem.add_runtime_dependency(%q<i18n>)
|
50
50
|
end
|
@@ -8,3 +8,20 @@ When(/^I accept the conflicts$/) do
|
|
8
8
|
type "a\n"
|
9
9
|
#eot
|
10
10
|
end
|
11
|
+
|
12
|
+
Then(/^the Gemfile should point to edge daemon\-kit$/) do
|
13
|
+
prep_for_fs_check do
|
14
|
+
gemfile = IO.read('Gemfile')
|
15
|
+
|
16
|
+
gemfile.should =~ /^gem 'daemon\-kit', :github => 'kennethkalmer\/daemon\-kit'$/
|
17
|
+
gemfile.should_not =~ /^gem 'daemon\-kit'$/
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Given(/^I have a daemon generated by daemon\-kit "(.*?)"$/) do |project|
|
22
|
+
copy_fixture_project( project )
|
23
|
+
end
|
24
|
+
|
25
|
+
Given(/^I cd to the old project$/) do
|
26
|
+
cd "fixture_project"
|
27
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
begin
|
2
|
+
require 'coveralls'
|
3
|
+
Coveralls.wear_merged!
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
|
1
7
|
require 'rspec'
|
2
8
|
|
3
9
|
DAEMON_ENV = "test"
|
@@ -6,3 +12,7 @@ $:.unshift File.expand_path( '/../lib', __FILE__ )
|
|
6
12
|
require 'daemon_kit'
|
7
13
|
|
8
14
|
require 'aruba/cucumber'
|
15
|
+
|
16
|
+
Before do
|
17
|
+
@aruba_timeout_seconds = 5
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ProjectFixtures
|
2
|
+
DAEMON_FIXTURES_PATH = File.expand_path( '../../../spec/fixtures', __FILE__ )
|
3
|
+
|
4
|
+
def copy_fixture_project( name )
|
5
|
+
name = case name
|
6
|
+
when '0.2.3'
|
7
|
+
'zero_two_three'
|
8
|
+
else
|
9
|
+
raise ArgumentError, "Unknown fixture project: #{name}"
|
10
|
+
end
|
11
|
+
|
12
|
+
src = File.join( DAEMON_FIXTURES_PATH, name )
|
13
|
+
|
14
|
+
in_current_dir do
|
15
|
+
FileUtils.cp_r( src, 'fixture_project' )
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
World( ProjectFixtures )
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Upgrading an older daemon
|
2
|
+
|
3
|
+
daemon-kit offers help during upgrades to newer versions.
|
4
|
+
|
5
|
+
Scenario: Upgrading from 0.2.3
|
6
|
+
Given I have a daemon generated by daemon-kit "0.2.3"
|
7
|
+
And I cd to the old project
|
8
|
+
When I run `rake daemon_kit:upgrade` interactively
|
9
|
+
And I accept the conflicts
|
10
|
+
Then the file "Gemfile" should contain "gem 'daemon-kit', :github => 'kennethkalmer/daemon-kit'"
|
11
|
+
And the file "config/boot.rb" should not contain "VendorBoot"
|
data/gemfiles/Gemfile.ci
ADDED
@@ -8,8 +8,6 @@ $LOAD_PATH.unshift( File.expand_path('../', __FILE__).to_absolute_path ) unless
|
|
8
8
|
$LOAD_PATH.include?( File.expand_path('../', __FILE__).to_absolute_path )
|
9
9
|
|
10
10
|
require 'daemon_kit'
|
11
|
-
require 'safely'
|
12
|
-
|
13
11
|
module DaemonKit
|
14
12
|
|
15
13
|
class << self
|
@@ -75,13 +73,19 @@ module DaemonKit
|
|
75
73
|
end
|
76
74
|
end
|
77
75
|
|
78
|
-
|
76
|
+
if safely_available?
|
77
|
+
Safely::Backtrace.safe_shutdown! if DaemonKit.configuration.backtraces && clean
|
78
|
+
end
|
79
79
|
|
80
80
|
DaemonKit.logger.warn "Shutting down #{DaemonKit.configuration.daemon_name}"
|
81
81
|
|
82
82
|
exit if do_exit
|
83
83
|
end
|
84
84
|
|
85
|
+
def self.safely_available?
|
86
|
+
defined? Safely
|
87
|
+
end
|
88
|
+
|
85
89
|
def initialize( configuration )
|
86
90
|
@configuration = configuration
|
87
91
|
end
|
@@ -104,7 +108,7 @@ module DaemonKit
|
|
104
108
|
|
105
109
|
include_core_lib
|
106
110
|
load_postdaemonize_configs
|
107
|
-
|
111
|
+
configure_exception_handling
|
108
112
|
|
109
113
|
set_process_name
|
110
114
|
|
@@ -203,9 +207,14 @@ module DaemonKit
|
|
203
207
|
end
|
204
208
|
end
|
205
209
|
|
206
|
-
def
|
210
|
+
def configure_exception_handling
|
207
211
|
Thread.abort_on_exception = true
|
208
212
|
|
213
|
+
configure_safely if self.class.safely_available?
|
214
|
+
end
|
215
|
+
|
216
|
+
def configure_safely
|
217
|
+
DaemonKit.logger.info "Configuring safely for exception handling"
|
209
218
|
Safely::Strategy::Log.logger = DaemonKit.logger
|
210
219
|
|
211
220
|
Safely::Backtrace.trace_directory = File.join( DAEMON_ROOT, "log" )
|
@@ -325,8 +334,9 @@ module DaemonKit
|
|
325
334
|
@shutdown_hooks << ( proc || block )
|
326
335
|
end
|
327
336
|
|
328
|
-
def pid_file( instance =
|
329
|
-
@pid_file ||=
|
337
|
+
def pid_file( instance = instance )
|
338
|
+
@pid_file ||=
|
339
|
+
File.join( File.dirname(self.default_log_path), "#{self.daemon_name}.#{instance}.pid" )
|
330
340
|
end
|
331
341
|
|
332
342
|
def instance
|
@@ -346,6 +356,10 @@ module DaemonKit
|
|
346
356
|
self.signal_traps[ signal ].each { |trap| trap.call }
|
347
357
|
end
|
348
358
|
|
359
|
+
def default_log_path
|
360
|
+
File.join(root_path, 'log', "#{environment}.log")
|
361
|
+
end
|
362
|
+
|
349
363
|
private
|
350
364
|
|
351
365
|
def set_trap( signal )
|
@@ -403,10 +417,6 @@ module DaemonKit
|
|
403
417
|
[ 'lib' ]
|
404
418
|
end
|
405
419
|
|
406
|
-
def default_log_path
|
407
|
-
File.join(root_path, 'log', "#{environment}.log")
|
408
|
-
end
|
409
|
-
|
410
420
|
def default_log_level
|
411
421
|
environment == 'production' ? :info : :debug
|
412
422
|
end
|
@@ -105,7 +105,8 @@ module DaemonKit
|
|
105
105
|
|
106
106
|
cmdq = mq.queue( q, :durable => true )
|
107
107
|
cmdq.subscribe( :ack => true ) do |header, message|
|
108
|
-
|
108
|
+
|
109
|
+
receiver = lambda do |header, message|
|
109
110
|
DaemonKit.logger.debug("Received workitem: #{message.inspect}")
|
110
111
|
|
111
112
|
RuoteWorkitem.process( :amqp, @amqp_reply_queue, message )
|
@@ -114,6 +115,15 @@ module DaemonKit
|
|
114
115
|
|
115
116
|
header.ack
|
116
117
|
end
|
118
|
+
|
119
|
+
if DaemonKit::Initializer.safely_available?
|
120
|
+
safely { receiver.call( header, message ) }
|
121
|
+
|
122
|
+
else
|
123
|
+
receiver.call( header, message )
|
124
|
+
|
125
|
+
end
|
126
|
+
|
117
127
|
end
|
118
128
|
end
|
119
129
|
end
|
@@ -1,80 +1,9 @@
|
|
1
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
2
|
|
74
3
|
desc "Upgrade your local files for a daemon after upgrading daemon-kit"
|
75
4
|
task :upgrade => 'environment' do
|
76
5
|
# Run these
|
77
|
-
%w{
|
6
|
+
%w{ config root scripts }.each do |t|
|
78
7
|
Rake::Task["daemon_kit:upgrade:#{t}"].invoke
|
79
8
|
end
|
80
9
|
|
@@ -83,41 +12,31 @@ namespace :daemon_kit do
|
|
83
12
|
end
|
84
13
|
|
85
14
|
namespace :upgrade do
|
86
|
-
|
87
|
-
|
88
|
-
|
15
|
+
def invoke_from_app_generator(method)
|
16
|
+
app_generator.send(method)
|
17
|
+
end
|
89
18
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
19
|
+
def app_generator
|
20
|
+
@app_generator ||= begin
|
21
|
+
require 'daemon_kit/generators'
|
94
22
|
|
95
|
-
|
96
|
-
|
97
|
-
|
23
|
+
name = DaemonKit.configuration.daemon_name
|
24
|
+
gen = DaemonKit::Generators::AppGenerator.new( [name], { :with_dispatchers => true },
|
25
|
+
:destination_root => DaemonKit.root )
|
26
|
+
gen
|
98
27
|
end
|
99
28
|
end
|
100
29
|
|
101
|
-
|
102
|
-
|
103
|
-
copy_framework_template( 'Rakefile' )
|
30
|
+
task :config do
|
31
|
+
invoke_from_app_generator(:create_config_files)
|
104
32
|
end
|
105
33
|
|
106
|
-
|
107
|
-
|
108
|
-
%w{ console destroy generate }.each do |s|
|
109
|
-
copy_framework_template( "script", s )
|
110
|
-
end
|
34
|
+
task :root do
|
35
|
+
invoke_from_app_generator(:create_root_files)
|
111
36
|
end
|
112
37
|
|
113
|
-
|
114
|
-
|
115
|
-
copy_framework_template( 'Gemfile' )
|
38
|
+
task :scripts do
|
39
|
+
invoke_from_app_generator(:create_script_files)
|
116
40
|
end
|
117
41
|
end
|
118
42
|
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
|
data/lib/daemon_kit/version.rb
CHANGED
data/lib/daemon_kit/xmpp.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'blather/client/client'
|
2
2
|
require 'blather/client/dsl'
|
3
|
+
require 'blather/version'
|
3
4
|
|
4
5
|
module DaemonKit
|
5
6
|
# Thin wrapper around the blather DSL
|
@@ -9,6 +10,10 @@ module DaemonKit
|
|
9
10
|
class << self
|
10
11
|
|
11
12
|
def run( &block )
|
13
|
+
if Blather::VERSION < '0.8.0'
|
14
|
+
DaemonKit.logger.warn "Blather version to old, please upgrade to 0.8.x"
|
15
|
+
end
|
16
|
+
|
12
17
|
DaemonKit.trap('INT') { ::EM.stop }
|
13
18
|
DaemonKit.trap('TERM') { ::EM.stop }
|
14
19
|
|
@@ -53,9 +58,9 @@ module DaemonKit
|
|
53
58
|
def configure_roster!
|
54
59
|
DaemonKit.logger.debug 'Configuring roster'
|
55
60
|
|
56
|
-
my_roster.each do |
|
57
|
-
unless
|
58
|
-
DaemonKit.logger.debug "Removing #{jid} from roster"
|
61
|
+
my_roster.each do |item|
|
62
|
+
unless valid_contact?( item.jid )
|
63
|
+
DaemonKit.logger.debug "Removing #{item.jid} from roster"
|
59
64
|
|
60
65
|
my_roster.delete( item.jid )
|
61
66
|
next
|
@@ -68,7 +73,7 @@ module DaemonKit
|
|
68
73
|
my_roster.add( Blather::JID.new( jid ) )
|
69
74
|
end
|
70
75
|
|
71
|
-
my_roster.each do |
|
76
|
+
my_roster.each do |item|
|
72
77
|
item.subscription = :both
|
73
78
|
item.ask = :subscribe
|
74
79
|
end
|
@@ -83,7 +88,11 @@ module DaemonKit
|
|
83
88
|
end
|
84
89
|
|
85
90
|
def contacts
|
86
|
-
@config.masters
|
91
|
+
@config.masters | ( @config.supporters || [] )
|
92
|
+
end
|
93
|
+
|
94
|
+
def valid_contact?( jid )
|
95
|
+
contacts.include?( jid.stripped.to_s )
|
87
96
|
end
|
88
97
|
|
89
98
|
def run
|