daemon-kit 0.1.7 → 0.1.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. data/Configuration.txt +58 -0
  2. data/History.txt +24 -0
  3. data/Manifest.txt +50 -2
  4. data/PostInstall.txt +1 -1
  5. data/README.rdoc +7 -9
  6. data/Rakefile +2 -4
  7. data/TODO.txt +6 -5
  8. data/app_generators/daemon_kit/daemon_kit_generator.rb +5 -0
  9. data/app_generators/daemon_kit/templates/Rakefile +3 -1
  10. data/app_generators/daemon_kit/templates/bin/daemon.erb +1 -1
  11. data/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  12. data/app_generators/daemon_kit/templates/config/boot.rb +2 -2
  13. data/app_generators/daemon_kit/templates/script/console +3 -0
  14. data/app_generators/daemon_kit/templates/script/destroy +14 -0
  15. data/app_generators/daemon_kit/templates/script/generate +14 -0
  16. data/daemon_generators/amqp/templates/config/amqp.yml +5 -5
  17. data/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +4 -23
  18. data/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  19. data/daemon_generators/deploy_capistrano/templates/config/deploy.rb +3 -1
  20. data/lib/daemon_kit.rb +33 -5
  21. data/lib/daemon_kit/amqp.rb +2 -1
  22. data/lib/daemon_kit/application.rb +136 -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.rb +1 -0
  28. data/lib/daemon_kit/core_ext/string.rb +22 -0
  29. data/lib/daemon_kit/deployment/capistrano.rb +6 -9
  30. data/lib/daemon_kit/error_handlers/mail.rb +52 -15
  31. data/lib/daemon_kit/initializer.rb +95 -41
  32. data/lib/daemon_kit/pid_file.rb +61 -0
  33. data/lib/daemon_kit/tasks/environment.rake +5 -4
  34. data/lib/daemon_kit/tasks/framework.rake +15 -1
  35. data/lib/daemon_kit/tasks/god.rake +62 -0
  36. data/lib/daemon_kit/tasks/log.rake +8 -0
  37. data/lib/daemon_kit/tasks/monit.rake +29 -0
  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/error_handlers_spec.rb +23 -0
  42. data/spec/fixtures/env.yml +15 -0
  43. data/spec/fixtures/noenv.yml +4 -0
  44. data/spec/initializer_spec.rb +4 -3
  45. data/spec/spec_helper.rb +8 -11
  46. data/templates/god/god.erb +69 -0
  47. data/templates/monit/monit.erb +14 -0
  48. data/test/test_daemon-kit_generator.rb +6 -1
  49. data/test/test_deploy_capistrano_generator.rb +1 -2
  50. data/vendor/tmail-1.2.3/tmail.rb +5 -0
  51. data/vendor/tmail-1.2.3/tmail/address.rb +426 -0
  52. data/vendor/tmail-1.2.3/tmail/attachments.rb +46 -0
  53. data/vendor/tmail-1.2.3/tmail/base64.rb +46 -0
  54. data/vendor/tmail-1.2.3/tmail/compat.rb +41 -0
  55. data/vendor/tmail-1.2.3/tmail/config.rb +67 -0
  56. data/vendor/tmail-1.2.3/tmail/core_extensions.rb +63 -0
  57. data/vendor/tmail-1.2.3/tmail/encode.rb +581 -0
  58. data/vendor/tmail-1.2.3/tmail/header.rb +960 -0
  59. data/vendor/tmail-1.2.3/tmail/index.rb +9 -0
  60. data/vendor/tmail-1.2.3/tmail/interface.rb +1130 -0
  61. data/vendor/tmail-1.2.3/tmail/loader.rb +3 -0
  62. data/vendor/tmail-1.2.3/tmail/mail.rb +578 -0
  63. data/vendor/tmail-1.2.3/tmail/mailbox.rb +495 -0
  64. data/vendor/tmail-1.2.3/tmail/main.rb +6 -0
  65. data/vendor/tmail-1.2.3/tmail/mbox.rb +3 -0
  66. data/vendor/tmail-1.2.3/tmail/net.rb +248 -0
  67. data/vendor/tmail-1.2.3/tmail/obsolete.rb +132 -0
  68. data/vendor/tmail-1.2.3/tmail/parser.rb +1476 -0
  69. data/vendor/tmail-1.2.3/tmail/port.rb +379 -0
  70. data/vendor/tmail-1.2.3/tmail/quoting.rb +118 -0
  71. data/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
  72. data/vendor/tmail-1.2.3/tmail/scanner.rb +49 -0
  73. data/vendor/tmail-1.2.3/tmail/scanner_r.rb +261 -0
  74. data/vendor/tmail-1.2.3/tmail/stringio.rb +280 -0
  75. data/vendor/tmail-1.2.3/tmail/utils.rb +337 -0
  76. data/vendor/tmail-1.2.3/tmail/version.rb +39 -0
  77. data/vendor/tmail.rb +13 -0
  78. metadata +57 -18
  79. data/daemon_generators/deploy_capistrano/USAGE +0 -5
  80. data/lib/daemon_kit/patches/force_kill_wait.rb +0 -120
@@ -1,5 +0,0 @@
1
- Description:
2
-
3
-
4
- Usage:
5
-
@@ -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