daemon-kit 0.1.7 → 0.1.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Configuration.txt +58 -0
- data/History.txt +24 -0
- data/Manifest.txt +50 -2
- data/PostInstall.txt +1 -1
- data/README.rdoc +7 -9
- data/Rakefile +2 -4
- data/TODO.txt +6 -5
- data/app_generators/daemon_kit/daemon_kit_generator.rb +5 -0
- data/app_generators/daemon_kit/templates/Rakefile +3 -1
- data/app_generators/daemon_kit/templates/bin/daemon.erb +1 -1
- data/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
- data/app_generators/daemon_kit/templates/config/boot.rb +2 -2
- data/app_generators/daemon_kit/templates/script/console +3 -0
- data/app_generators/daemon_kit/templates/script/destroy +14 -0
- data/app_generators/daemon_kit/templates/script/generate +14 -0
- data/daemon_generators/amqp/templates/config/amqp.yml +5 -5
- data/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +4 -23
- data/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
- data/daemon_generators/deploy_capistrano/templates/config/deploy.rb +3 -1
- data/lib/daemon_kit.rb +33 -5
- data/lib/daemon_kit/amqp.rb +2 -1
- data/lib/daemon_kit/application.rb +136 -11
- data/lib/daemon_kit/arguments.rb +151 -0
- data/lib/daemon_kit/commands/console.rb +38 -0
- data/lib/daemon_kit/config.rb +1 -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/string.rb +22 -0
- data/lib/daemon_kit/deployment/capistrano.rb +6 -9
- data/lib/daemon_kit/error_handlers/mail.rb +52 -15
- data/lib/daemon_kit/initializer.rb +95 -41
- data/lib/daemon_kit/pid_file.rb +61 -0
- data/lib/daemon_kit/tasks/environment.rake +5 -4
- data/lib/daemon_kit/tasks/framework.rake +15 -1
- 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/spec/argument_spec.rb +51 -0
- data/spec/config_spec.rb +77 -0
- data/spec/daemon_kit_spec.rb +2 -2
- 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 +4 -3
- data/spec/spec_helper.rb +8 -11
- data/templates/god/god.erb +69 -0
- data/templates/monit/monit.erb +14 -0
- data/test/test_daemon-kit_generator.rb +6 -1
- data/test/test_deploy_capistrano_generator.rb +1 -2
- data/vendor/tmail-1.2.3/tmail.rb +5 -0
- data/vendor/tmail-1.2.3/tmail/address.rb +426 -0
- data/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
- data/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
- data/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
- data/vendor/tmail-1.2.3/tmail/config.rb +67 -0
- data/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
- data/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
- data/vendor/tmail-1.2.3/tmail/header.rb +960 -0
- data/vendor/tmail-1.2.3/tmail/index.rb +9 -0
- data/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
- data/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
- data/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
- data/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
- data/vendor/tmail-1.2.3/tmail/main.rb +6 -0
- data/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
- data/vendor/tmail-1.2.3/tmail/net.rb +248 -0
- data/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
- data/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
- data/vendor/tmail-1.2.3/tmail/port.rb +379 -0
- data/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
- data/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
- data/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
- data/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
- data/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
- data/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
- data/vendor/tmail-1.2.3/tmail/version.rb +39 -0
- data/vendor/tmail.rb +13 -0
- metadata +57 -18
- data/daemon_generators/deploy_capistrano/USAGE +0 -5
- data/lib/daemon_kit/patches/force_kill_wait.rb +0 -120
@@ -1,120 +0,0 @@
|
|
1
|
-
# Shamelessly taken from http://blog.rapleaf.com/dev/?p=19
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'daemons'
|
5
|
-
require 'timeout'
|
6
|
-
|
7
|
-
module Daemons
|
8
|
-
|
9
|
-
class ApplicationGroup
|
10
|
-
|
11
|
-
# We want to redefine find_applications to not rely on
|
12
|
-
# pidfiles (e.g. find application if pidfile is gone)
|
13
|
-
# We recreate the pid files if they're not there.
|
14
|
-
def find_applications(dir)
|
15
|
-
# Find pid_files, like original implementation
|
16
|
-
pid_files = PidFile.find_files(dir, app_name)
|
17
|
-
@monitor = Monitor.find(dir, app_name + '_monitor')
|
18
|
-
pid_files.reject! {|f| f =~ /_monitor.pid$/}
|
19
|
-
|
20
|
-
# Find the missing pids based on the UNIX pids
|
21
|
-
pidfile_pids = pid_files.map {|pf| PidFile.existing(pf).pid}
|
22
|
-
missing_pids = unix_pids - pidfile_pids
|
23
|
-
|
24
|
-
# Create pidfiles that are gone
|
25
|
-
if missing_pids.size > 0
|
26
|
-
puts "[daemons_ext]: #{missing_pids.size} missing pidfiles: " +
|
27
|
-
"#{missing_pids.inspect}... creating pid file(s)."
|
28
|
-
missing_pids.each do |pid|
|
29
|
-
pidfile = PidFile.new(dir, app_name, multiple)
|
30
|
-
pidfile.pid = pid # Doesn't seem to matter if it's a string or Fixnum
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Now get all the pid file again
|
35
|
-
pid_files = PidFile.find_files(dir, app_name)
|
36
|
-
|
37
|
-
return pid_files.map {|f|
|
38
|
-
app = Application.new(self, {}, PidFile.existing(f))
|
39
|
-
setup_app(app)
|
40
|
-
app
|
41
|
-
}
|
42
|
-
end
|
43
|
-
|
44
|
-
# Specify :force_kill_wait => (seconds to wait) and this method will
|
45
|
-
# block until the process is dead. It first sends a TERM signal, then
|
46
|
-
# a KILL signal (-9) if the process hasn't died after the wait time.
|
47
|
-
def stop_all(force = false)
|
48
|
-
@monitor.stop if @monitor
|
49
|
-
|
50
|
-
wait = options[:force_kill_wait].to_i
|
51
|
-
if wait > 0
|
52
|
-
puts "[daemons_ext]: Killing #{app_name} with force after #{wait} secs."
|
53
|
-
|
54
|
-
# Send term first, don't delete PID files.
|
55
|
-
@applications.each {|a| a.send_sig('TERM')}
|
56
|
-
|
57
|
-
begin
|
58
|
-
started_at = Time.now
|
59
|
-
Timeout::timeout(wait) do
|
60
|
-
num_pids = unix_pids.size
|
61
|
-
while num_pids > 0
|
62
|
-
time_left = wait - (Time.now - started_at)
|
63
|
-
puts "[daemons_ext]: Waiting #{time_left.round} secs on " +
|
64
|
-
"#{num_pids} #{app_name}(s)..."
|
65
|
-
sleep 1
|
66
|
-
num_pids = unix_pids.size
|
67
|
-
end
|
68
|
-
end
|
69
|
-
rescue Timeout::Error
|
70
|
-
@applications.each {|a| a.send_sig('KILL')}
|
71
|
-
ensure
|
72
|
-
# Delete Pidfiles
|
73
|
-
@applications.each {|a| a.zap!}
|
74
|
-
end
|
75
|
-
|
76
|
-
puts "[daemons_ext]: All #{app_name}(s) dead."
|
77
|
-
else
|
78
|
-
@applications.each {|a|
|
79
|
-
if force
|
80
|
-
begin; a.stop; rescue ::Exception; end
|
81
|
-
else
|
82
|
-
a.stop
|
83
|
-
end
|
84
|
-
}
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
# Find UNIX pids based on app_name. CAUTION: This has only been tested on
|
91
|
-
# Mac OS X and CentOS.
|
92
|
-
def unix_pids
|
93
|
-
pids = []
|
94
|
-
x = `ps auxw | grep -v grep | awk '{print $2, $11}' | grep #{app_name}`
|
95
|
-
if x && x.chomp!
|
96
|
-
processes = x.split(/\n/).compact
|
97
|
-
processes = processes.delete_if do |p|
|
98
|
-
pid, name = p.split(/\s/)
|
99
|
-
# We want to make sure that the first part of the process name matches
|
100
|
-
# so that app_name matches app_name_22
|
101
|
-
app_name != name[0..(app_name.length - 1)]
|
102
|
-
end
|
103
|
-
pids = processes.map {|p| p.split(/\s/)[0].to_i}
|
104
|
-
end
|
105
|
-
|
106
|
-
pids
|
107
|
-
end
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
class Application
|
112
|
-
|
113
|
-
# Send signal to the process, rescue if process deson't exist
|
114
|
-
def send_sig(sig)
|
115
|
-
Process.kill(sig, @pid.pid) rescue Errno::ESRCH
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|