kennethkalmer-daemon-kit 0.1.6 → 0.1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Configuration.txt +58 -0
  2. data/History.txt +16 -0
  3. data/Manifest.txt +29 -2
  4. data/PostInstall.txt +1 -1
  5. data/{README.textile → README.rdoc} +31 -19
  6. data/Rakefile +2 -4
  7. data/TODO.txt +6 -5
  8. data/app_generators/daemon_kit/daemon_kit_generator.rb +29 -0
  9. data/app_generators/daemon_kit/templates/Rakefile +3 -1
  10. data/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  11. data/app_generators/daemon_kit/templates/config/boot.rb +2 -2
  12. data/app_generators/daemon_kit/templates/script/console +3 -0
  13. data/app_generators/daemon_kit/templates/script/destroy +14 -0
  14. data/app_generators/daemon_kit/templates/script/generate +14 -0
  15. data/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
  16. data/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
  17. data/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  18. data/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
  19. data/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
  20. data/daemon_generators/deploy_capistrano/templates/config/deploy.rb +51 -0
  21. data/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
  22. data/lib/daemon_kit/application.rb +135 -11
  23. data/lib/daemon_kit/arguments.rb +151 -0
  24. data/lib/daemon_kit/commands/console.rb +38 -0
  25. data/lib/daemon_kit/config.rb +1 -0
  26. data/lib/daemon_kit/console_daemon.rb +2 -0
  27. data/lib/daemon_kit/core_ext/string.rb +22 -0
  28. data/lib/daemon_kit/core_ext.rb +1 -0
  29. data/lib/daemon_kit/deployment/capistrano.rb +485 -0
  30. data/lib/daemon_kit/initializer.rb +87 -25
  31. data/lib/daemon_kit/pid_file.rb +61 -0
  32. data/lib/daemon_kit/tasks/environment.rake +5 -4
  33. data/lib/daemon_kit/tasks/framework.rake +15 -1
  34. data/lib/daemon_kit/tasks/god.rake +62 -0
  35. data/lib/daemon_kit/tasks/monit.rake +29 -0
  36. data/lib/daemon_kit.rb +11 -5
  37. data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +1 -1
  38. data/spec/argument_spec.rb +51 -0
  39. data/spec/config_spec.rb +77 -0
  40. data/spec/daemon_kit_spec.rb +2 -2
  41. data/spec/fixtures/env.yml +15 -0
  42. data/spec/fixtures/noenv.yml +4 -0
  43. data/spec/initializer_spec.rb +4 -3
  44. data/spec/spec_helper.rb +8 -11
  45. data/templates/god/god.erb +69 -0
  46. data/templates/monit/monit.erb +14 -0
  47. data/test/test_daemon-kit_generator.rb +15 -1
  48. data/test/test_deploy_capistrano_generator.rb +48 -0
  49. metadata +41 -21
  50. 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