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
@@ -20,6 +20,9 @@ module DaemonKit
|
|
20
20
|
class_option :cucumber, :type => :boolean, :aliases => '-c', :default => false,
|
21
21
|
:desc => "Install cucumber support"
|
22
22
|
|
23
|
+
class_option :edge, :type => :boolean, :default => false,
|
24
|
+
:desc => "Let the initial Gemfile track kennethkalmer/daemon-kit instead of rubygems"
|
25
|
+
|
23
26
|
def initialize( *args )
|
24
27
|
super
|
25
28
|
|
@@ -42,10 +45,13 @@ module DaemonKit
|
|
42
45
|
FileUtils.cd( destination_root )
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
48
|
+
def create_readme
|
46
49
|
template 'README.tt', 'README'
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_root_files
|
47
53
|
copy_file 'Rakefile'
|
48
|
-
|
54
|
+
template 'Gemfile.tt', 'Gemfile'
|
49
55
|
end
|
50
56
|
|
51
57
|
def create_bin_files
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# Update this Gemfile with any additional dependencies and run
|
2
|
+
# 'bundle install' to get them all installed. Daemon-kit's capistrano
|
3
|
+
# deployment will ensure that the bundle required by your daemon is properly
|
4
|
+
# installed.
|
5
|
+
#
|
6
|
+
# For more information on bundler, please visit http://gembundler.com
|
7
|
+
|
8
|
+
source 'https://rubygems.org'
|
9
|
+
|
10
|
+
<% if options.edge? -%>
|
11
|
+
gem 'daemon-kit', :github => 'kennethkalmer/daemon-kit'
|
12
|
+
<% else -%>
|
13
|
+
# Live on the edge instead: gem 'daemon-kit', :github => 'kennethkalmer/daemon-kit'
|
14
|
+
gem 'daemon-kit'
|
15
|
+
<% end -%>
|
16
|
+
|
17
|
+
#
|
18
|
+
# safely (http://github.com/kennethkalmer/safely)
|
19
|
+
#
|
20
|
+
|
21
|
+
gem 'safely' # Optional, but recommended.
|
22
|
+
|
23
|
+
# gem 'toadhopper' # For reporting exceptions to hoptoad
|
24
|
+
# gem 'mail' # For reporting exceptions via mail
|
25
|
+
|
@@ -10,21 +10,13 @@ module DaemonKit
|
|
10
10
|
class << self
|
11
11
|
def boot!
|
12
12
|
unless booted?
|
13
|
-
|
13
|
+
GemBoot.new.run
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
def booted?
|
18
18
|
defined? DaemonKit::Initializer
|
19
19
|
end
|
20
|
-
|
21
|
-
def pick_boot
|
22
|
-
(vendor_kit? ? VendorBoot : GemBoot).new
|
23
|
-
end
|
24
|
-
|
25
|
-
def vendor_kit?
|
26
|
-
File.exists?( "#{DAEMON_ROOT}/vendor/daemon-kit" )
|
27
|
-
end
|
28
20
|
end
|
29
21
|
|
30
22
|
class Boot
|
@@ -34,12 +26,6 @@ module DaemonKit
|
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
37
|
-
class VendorBoot < Boot
|
38
|
-
def load_initializer
|
39
|
-
require "#{DAEMON_ROOT}/vendor/daemon-kit/lib/daemon_kit/initializer"
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
29
|
class GemBoot < Boot
|
44
30
|
def load_initializer
|
45
31
|
begin
|
@@ -31,11 +31,6 @@ set :config_files, %w{}
|
|
31
31
|
# into the root directory of the deployment.
|
32
32
|
set :shared_children, %w{log tmp}
|
33
33
|
|
34
|
-
# Record our dependencies
|
35
|
-
unless File.directory?( "#{DaemonKit.root}/vendor/daemon_kit" )
|
36
|
-
depend :remote, :gem, "daemon-kit", ">=#{DaemonKit.version}"
|
37
|
-
end
|
38
|
-
|
39
34
|
# Hook into capistrano's events
|
40
35
|
before "deploy:update_code", "deploy:check"
|
41
36
|
|
@@ -2,19 +2,23 @@
|
|
2
2
|
|
3
3
|
# The configuration specifies the following keys:
|
4
4
|
# * jabber_id - Identidy (username) of the user
|
5
|
+
# * host - Host to connect to (optional)
|
6
|
+
# * port - Port to connect to (optional)
|
5
7
|
# * password - Password used to authenticate
|
6
8
|
# * resource - Multiple connections can be made with the same credentials and different resources
|
7
9
|
# * masters - Array of Jabber ID's whose messages will be processed
|
8
|
-
# * supporters - Additional 'buddies' to keep on roster, but messages won't be processed
|
10
|
+
# * supporters - Additional 'buddies' to keep on roster, but messages won't be processed (optional)
|
9
11
|
# * enable_logging - Enable Blather logging (VERY VERBOSE)
|
10
12
|
# * require_master - Disable filtering of messages based on the sender being a 'master'
|
11
13
|
|
12
14
|
defaults: &defaults
|
13
|
-
jabber_id: dk@jabber
|
15
|
+
jabber_id: dk@jabber.org
|
16
|
+
host: jabber.org
|
17
|
+
port: 5222
|
14
18
|
password: secret
|
15
19
|
resource: daemon_kit
|
16
20
|
enable_logging: false
|
17
|
-
masters:
|
21
|
+
masters:
|
18
22
|
- kenneth.kalmer@gmail.com
|
19
23
|
supporters:
|
20
24
|
- someone@gmail.com
|
@@ -0,0 +1,65 @@
|
|
1
|
+
daemon-kit README
|
2
|
+
================
|
3
|
+
|
4
|
+
daemon-kit 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
|
+
zero_two_three - 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
|
+
zero_two_three.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
|
+
Rake Tasks
|
38
|
+
==========
|
39
|
+
|
40
|
+
Note that the Rakefile does not load the `config/environments.rb` file, so if you have
|
41
|
+
environment-specific tasks (such as tests), you will need to call rake with the environment:
|
42
|
+
|
43
|
+
DAEMON_ENV=staging bundle exec rake -T
|
44
|
+
|
45
|
+
Logging
|
46
|
+
=======
|
47
|
+
|
48
|
+
One of the biggest issues with writing daemons are getting insight into what your
|
49
|
+
daemons are doing. Logging with daemon-kit is simplified as DaemonKit creates log
|
50
|
+
files per environment in log.
|
51
|
+
|
52
|
+
On all environments except production the log level is set to DEBUG, but you can
|
53
|
+
toggle the log level by sending the running daemon SIGUSR1 and SIGUSR2 signals.
|
54
|
+
SIGUSR1 will toggle between DEBUG and INFO levels, SIGUSR2 will blatantly set the
|
55
|
+
level to DEBUG.
|
56
|
+
|
57
|
+
Bundler
|
58
|
+
=======
|
59
|
+
|
60
|
+
daemon-kit uses bundler to ease the nightmare of dependency loading in Ruby
|
61
|
+
projects. daemon-kit and its generators all create/update the Gemfile in the
|
62
|
+
root of the daemon. You can satisfy the project's dependencies by running
|
63
|
+
`bundle install` from within the project root.
|
64
|
+
|
65
|
+
For more information on bundler, please see http://github.com/carlhuda/bundler
|
@@ -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,64 @@
|
|
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
|
+
require "rubygems"
|
7
|
+
require "bundler/setup"
|
8
|
+
|
9
|
+
module DaemonKit
|
10
|
+
class << self
|
11
|
+
def boot!
|
12
|
+
unless booted?
|
13
|
+
pick_boot.run
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def booted?
|
18
|
+
defined? DaemonKit::Initializer
|
19
|
+
end
|
20
|
+
|
21
|
+
def pick_boot
|
22
|
+
(vendor_kit? ? VendorBoot : GemBoot).new
|
23
|
+
end
|
24
|
+
|
25
|
+
def vendor_kit?
|
26
|
+
File.exists?( "#{DAEMON_ROOT}/vendor/daemon-kit" )
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class Boot
|
31
|
+
def run
|
32
|
+
load_initializer
|
33
|
+
DaemonKit::Initializer.run
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class VendorBoot < Boot
|
38
|
+
def load_initializer
|
39
|
+
require "#{DAEMON_ROOT}/vendor/daemon-kit/lib/daemon_kit/initializer"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class GemBoot < Boot
|
44
|
+
def load_initializer
|
45
|
+
begin
|
46
|
+
require 'rubygems' unless defined?( ::Gem )
|
47
|
+
gem 'daemon-kit'
|
48
|
+
require 'daemon_kit/initializer'
|
49
|
+
rescue ::Gem::LoadError => e
|
50
|
+
msg = <<EOF
|
51
|
+
|
52
|
+
You are missing the daemon-kit gem. Please install the following gem:
|
53
|
+
|
54
|
+
sudo gem install daemon-kit
|
55
|
+
|
56
|
+
EOF
|
57
|
+
$stderr.puts msg
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
DaemonKit.boot!
|
@@ -0,0 +1,22 @@
|
|
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
|
+
# Auto-require default libraries and those for the current ruby environment.
|
10
|
+
Bundler.require :default, DaemonKit.env
|
11
|
+
|
12
|
+
DaemonKit::Initializer.run do |config|
|
13
|
+
|
14
|
+
# The name of the daemon as reported by process monitoring tools
|
15
|
+
config.daemon_name = 'zero_two_three'
|
16
|
+
|
17
|
+
# Force the daemon to be killed after X seconds from asking it to
|
18
|
+
# config.force_kill_wait = 30
|
19
|
+
|
20
|
+
# Log backraces when a thread/daemon dies (Recommended)
|
21
|
+
# config.backtraces = true
|
22
|
+
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,13 @@
|
|
1
|
+
# Safely is responsible for providing exception reporting and the
|
2
|
+
# logging of backtraces when your daemon dies unexpectedly. The full
|
3
|
+
# documentation for safely can be found at
|
4
|
+
# http://github.com/kennethkalmer/safely/wiki
|
5
|
+
|
6
|
+
# By default Safely will use the daemon-kit's logger to log exceptions,
|
7
|
+
# and will store backtraces in the "log" directory.
|
8
|
+
|
9
|
+
# Comment out to enable Hoptoad support
|
10
|
+
# Safely::Strategy::Hoptoad.hoptoad_key = ""
|
11
|
+
|
12
|
+
# Comment out to use email exceptions
|
13
|
+
# Safely::Strategy::Mail.recipient = "your.name@gmail.com"
|
@@ -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
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
DAEMON_ENV = 'test' unless defined?( DAEMON_ENV )
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rspec'
|
5
|
+
rescue LoadError
|
6
|
+
require 'rubygems'
|
7
|
+
require 'rspec'
|
8
|
+
end
|
9
|
+
|
10
|
+
require File.dirname(__FILE__) + '/../config/environment'
|
11
|
+
DaemonKit::Application.running!
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
# == Mock Framework
|
15
|
+
#
|
16
|
+
# RSpec uses it's own mocking framework by default. If you prefer to
|
17
|
+
# use mocha, flexmock or RR, uncomment the appropriate line:
|
18
|
+
#
|
19
|
+
# config.mock_with :mocha
|
20
|
+
# config.mock_with :flexmock
|
21
|
+
# config.mock_with :rr
|
22
|
+
end
|