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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -0
  3. data/.travis.yml +2 -0
  4. data/README.md +2 -1
  5. data/Upgrading.md +11 -0
  6. data/daemon-kit.gemspec +1 -1
  7. data/features/app_generator.feature +5 -0
  8. data/features/step_definitions/daemon_steps.rb +17 -0
  9. data/features/support/env.rb +10 -0
  10. data/features/support/fixtures.rb +21 -0
  11. data/features/upgrades.feature +11 -0
  12. data/gemfiles/Gemfile.ci +8 -0
  13. data/lib/daemon_kit/abstract_logger.rb +0 -1
  14. data/lib/daemon_kit/initializer.rb +21 -11
  15. data/lib/daemon_kit/ruote_participants.rb +11 -1
  16. data/lib/daemon_kit/tasks/framework.rake +17 -98
  17. data/lib/daemon_kit/version.rb +3 -1
  18. data/lib/daemon_kit/xmpp.rb +14 -5
  19. data/lib/generators/daemon_kit/app/app_generator.rb +8 -2
  20. data/lib/generators/daemon_kit/app/templates/Gemfile.tt +25 -0
  21. data/lib/generators/daemon_kit/app/templates/README.tt +1 -1
  22. data/lib/generators/daemon_kit/app/templates/config/boot.rb +1 -15
  23. data/lib/generators/daemon_kit/capistrano/templates/config/deploy.rb.tt +0 -5
  24. data/lib/generators/daemon_kit/xmpp/templates/config/xmpp.yml +7 -3
  25. data/lib/generators/daemon_kit/xmpp/xmpp_generator.rb +1 -1
  26. data/{lib/generators/daemon_kit/app/templates → spec/fixtures/zero_two_three}/Gemfile +4 -0
  27. data/spec/fixtures/zero_two_three/README +65 -0
  28. data/spec/fixtures/zero_two_three/Rakefile +6 -0
  29. data/spec/fixtures/zero_two_three/bin/zero_two_three +8 -0
  30. data/spec/fixtures/zero_two_three/config/arguments.rb +12 -0
  31. data/spec/fixtures/zero_two_three/config/boot.rb +64 -0
  32. data/spec/fixtures/zero_two_three/config/environment.rb +22 -0
  33. data/spec/fixtures/zero_two_three/config/environments/development.rb +2 -0
  34. data/spec/fixtures/zero_two_three/config/post-daemonize/readme +5 -0
  35. data/spec/fixtures/zero_two_three/config/pre-daemonize/readme +12 -0
  36. data/spec/fixtures/zero_two_three/config/pre-daemonize/safely.rb +13 -0
  37. data/spec/fixtures/zero_two_three/lib/zero_two_three.rb +2 -0
  38. data/spec/fixtures/zero_two_three/libexec/zero_two_three-daemon.rb +18 -0
  39. data/spec/fixtures/zero_two_three/script/console +4 -0
  40. data/spec/fixtures/zero_two_three/script/destroy +4 -0
  41. data/spec/fixtures/zero_two_three/script/generate +4 -0
  42. data/spec/{spec.opts → fixtures/zero_two_three/spec/spec.opts} +0 -0
  43. data/spec/fixtures/zero_two_three/spec/spec_helper.rb +22 -0
  44. data/spec/fixtures/zero_two_three/spec/zero_two_three_spec.rb +11 -0
  45. data/spec/fixtures/zero_two_three/tasks/rspec.rake +13 -0
  46. data/spec/initializer_spec.rb +59 -7
  47. data/spec/spec_helper.rb +8 -0
  48. data/tasks/ci.rake +8 -0
  49. data/tasks/rspec.rake +1 -1
  50. metadata +62 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9356410391db8c1c25d11bed90a08e76fba383a3
4
- data.tar.gz: c87d71466d79190914007f2596262df9c8b338fd
3
+ metadata.gz: 90f5bbda2dfba4dc58989fb7d284ea2b52c6b16b
4
+ data.tar.gz: 8655f358efe6044f8b916e9979970d7fa21d4844
5
5
  SHA512:
6
- metadata.gz: 4d58c735226158c03e18e936f1fdb39d8387bf59f464265c0694312825e23b6d0d9ba850fa13102fdb4ebfcc860fec035b338bf3579cb9b79209d41db0221138
7
- data.tar.gz: e601935b3e7798ca8dd232ffa31ec15c3aab44aa14024fcca41f6b03f099f2936e898f9858154718bb9cb844aad1d646b514ff568caa4794b97ed97d3715b77e
6
+ metadata.gz: e9302898942d1dfb22c1c9df876d72803518ad6983dc5da4515ed903ea40667a7f74c93271122e5d8042810d97981088aa61ba2767abc6f56056414c80727c1d
7
+ data.tar.gz: e2697eb00c2009c32eb7c5690353214f3d81f9dbf7d76968f2b4b05c7b8a5f38966ca90504d428aad12b3324ab6b284375da8e6ee61b01e51e7a5300c83c0926
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --pattern "spec/*_spec.rb"
data/.travis.yml CHANGED
@@ -13,3 +13,5 @@ matrix:
13
13
  - rvm: 1.8.7
14
14
  - rvm: ree
15
15
  before_install: umask 0022
16
+ gemfile:
17
+ - gemfiles/Gemfile.ci
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
@@ -44,3 +44,8 @@ Feature: Generating a new daemon
44
44
  | tasks |
45
45
  | vendor |
46
46
  | tmp |
47
+
48
+ Scenario: Generating an 'edge' daemon
49
+ When I run `daemon-kit vuvuzela --edge`
50
+ And I cd to "vuvuzela"
51
+ Then the Gemfile should point to edge daemon-kit
@@ -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
@@ -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"
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in daemon-kit.gemspec
4
+ gemspec path: '../'
5
+
6
+ group :development do
7
+ gem 'coveralls', require: false
8
+ end
@@ -160,7 +160,6 @@ module DaemonKit
160
160
  def clean_trace( trace )
161
161
  trace = trace.map { |l| l.gsub(DAEMON_ROOT, '') }
162
162
  trace = trace.reject { |l| l =~ /gems\/daemon[\-_]kit/ }
163
- trace = trace.reject { |l| l =~ /vendor\/daemon[\-_]kit/ }
164
163
  trace
165
164
  end
166
165
 
@@ -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
- Safely::Backtrace.safe_shutdown! if DaemonKit.configuration.backtraces && clean
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
- configure_safely
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 configure_safely
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 = nil )
329
- @pid_file ||= "#{File.dirname(self.log_path)}/#{self.daemon_name}.#{instance}.pid"
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
- safely do
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{ initializers rakefile scripts gemfile }.each do |t|
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
- # Upgrade the initializers
87
- task :initializers do
88
- copy_framework_template( 'config', 'boot.rb' )
15
+ def invoke_from_app_generator(method)
16
+ app_generator.send(method)
17
+ end
89
18
 
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
19
+ def app_generator
20
+ @app_generator ||= begin
21
+ require 'daemon_kit/generators'
94
22
 
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' )
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
- # Upgrade the Rakefile
102
- task :rakefile do
103
- copy_framework_template( 'Rakefile' )
30
+ task :config do
31
+ invoke_from_app_generator(:create_config_files)
104
32
  end
105
33
 
106
- # Upgrade the scripts
107
- task :scripts do
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
- # Upgrade the Gemfile
114
- task :gemfile do
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
@@ -1,6 +1,8 @@
1
1
  module DaemonKit
2
+
2
3
  def version
3
- '0.3.0.rc1'
4
+ '0.3.0.rc2'
4
5
  end
6
+
5
7
  module_function :version
6
8
  end
@@ -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 |(jid, item)|
57
- unless contacts.include?( jid )
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 |(jid,item)|
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 + @config.supporters
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