god 0.7.0 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,20 @@
1
+ == 0.7.3 / 2008-02-14
2
+ * Minor Enhancements
3
+ * Add --bleakhouse to make running diagnostics easier
4
+ * Bug Fixes
5
+ * Use ::Process.kill(0, ...) instead of `kill -0`
6
+ * Fix pid_file behavior in process-centric conditions so they work with tasks
7
+ * Redirect output of daemonized god to log file or /dev/null earlier
8
+
9
+ == 0.7.2 / 2008-02-04
10
+ * Bug Fixes
11
+ * Start event system for CLI commands
12
+ * Up internal history to 100 lines per watch
13
+
14
+ == 0.7.1 / 2008-02-04
15
+ * Minor Enhancements
16
+ * Add --no-events option to completely disable events system
17
+
1
18
  == 0.7.0 / 2008-02-01
2
19
  * Minor Enhancements
3
20
  * Better default pid_file_directory behavior
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'hoe'
3
3
 
4
- Hoe.new('god', '0.7.0') do |p|
4
+ Hoe.new('god', '0.7.3') do |p|
5
5
  p.rubyforge_name = 'god'
6
6
  p.author = 'Tom Preston-Werner'
7
7
  p.email = 'tom@rubyisawesome.com'
data/bin/god CHANGED
@@ -9,7 +9,7 @@ require 'optparse'
9
9
  require 'drb'
10
10
 
11
11
  begin
12
- options = {:daemonize => true, :port => 17165, :syslog => true}
12
+ options = {:daemonize => true, :port => 17165, :syslog => true, :events => true}
13
13
 
14
14
  opts = OptionParser.new do |opts|
15
15
  opts.banner = <<-EOF
@@ -83,6 +83,14 @@ begin
83
83
  opts.on("--attach PID", "Quit god when the attached process dies") do |x|
84
84
  options[:attach] = x
85
85
  end
86
+
87
+ opts.on("--no-events", "Disable the event system") do
88
+ options[:events] = false
89
+ end
90
+
91
+ opts.on("--bleakhouse", "Enable bleakhouse profiling") do
92
+ options[:bleakhouse] = true
93
+ end
86
94
  end
87
95
 
88
96
  opts.parse!
@@ -98,9 +106,11 @@ begin
98
106
  God::CLI::Version.version
99
107
  elsif !options[:config] && options[:info]
100
108
  require 'god'
109
+ God::EventHandler.load
101
110
  God::CLI::Version.version_extended
102
111
  elsif !options[:config] && command = ARGV[0]
103
112
  require 'god'
113
+ God::EventHandler.load
104
114
  God::CLI::Command.new(command, options, ARGV)
105
115
  else
106
116
  require 'god/cli/run'
data/lib/god.rb CHANGED
@@ -89,9 +89,6 @@ def root_binding
89
89
  binding
90
90
  end
91
91
 
92
- # Load the event handler system
93
- God::EventHandler.load
94
-
95
92
  module Kernel
96
93
  alias_method :abort_orig, :abort
97
94
 
@@ -133,9 +130,9 @@ class Module
133
130
  end
134
131
 
135
132
  module God
136
- VERSION = '0.7.0'
133
+ VERSION = '0.7.3'
137
134
 
138
- LOG_BUFFER_SIZE_DEFAULT = 10
135
+ LOG_BUFFER_SIZE_DEFAULT = 100
139
136
  PID_FILE_DIRECTORY_DEFAULTS = ['/var/run/god', '~/.god/pids']
140
137
  DRB_PORT_DEFAULT = 17165
141
138
  DRB_ALLOW_DEFAULT = ['127.0.0.1']
@@ -149,7 +146,8 @@ module God
149
146
  :allow,
150
147
  :log_buffer_size,
151
148
  :pid_file_directory,
152
- :log_level
149
+ :log_level,
150
+ :use_events
153
151
 
154
152
  # internal
155
153
  attr_accessor :inited,
data/lib/god/cli/run.rb CHANGED
@@ -43,16 +43,11 @@ module God
43
43
 
44
44
  log_file = @options[:log] || "/dev/null"
45
45
 
46
- unless God::EventHandler.loaded?
47
- puts
48
- puts "***********************************************************************"
49
- puts "*"
50
- puts "* Event conditions are not available for your installation of god."
51
- puts "* You may still use and write custom conditions using the poll system"
52
- puts "*"
53
- puts "***********************************************************************"
54
- puts
55
- end
46
+ # reset file descriptors
47
+ STDIN.reopen "/dev/null"
48
+ STDOUT.reopen(log_file, "a")
49
+ STDERR.reopen STDOUT
50
+ STDOUT.sync = true
56
51
 
57
52
  # start attached pid watcher if necessary
58
53
  if @options[:attach]
@@ -73,6 +68,21 @@ module God
73
68
  Logger.syslog = false
74
69
  end
75
70
 
71
+ if @options[:events]
72
+ God::EventHandler.load
73
+ end
74
+
75
+ unless God::EventHandler.loaded?
76
+ puts
77
+ puts "***********************************************************************"
78
+ puts "*"
79
+ puts "* Event conditions are not available for your installation of god."
80
+ puts "* You may still use and write custom conditions using the poll system"
81
+ puts "*"
82
+ puts "***********************************************************************"
83
+ puts
84
+ end
85
+
76
86
  # load config
77
87
  if @options[:config]
78
88
  # set log level, defaults to WARN
@@ -101,12 +111,6 @@ module God
101
111
  end
102
112
  end
103
113
  end
104
-
105
- # reset file descriptors
106
- STDIN.reopen "/dev/null"
107
- STDOUT.reopen(log_file, "a")
108
- STDERR.reopen STDOUT
109
- STDOUT.sync = true
110
114
  rescue => e
111
115
  puts e.message
112
116
  puts e.backtrace.join("\n")
@@ -126,6 +130,10 @@ module God
126
130
  def run_in_front
127
131
  require 'god'
128
132
 
133
+ if @options[:bleakhouse]
134
+ BleakHouseDiagnostic.install
135
+ end
136
+
129
137
  # start attached pid watcher if necessary
130
138
  if @options[:attach]
131
139
  self.attach
@@ -135,6 +143,10 @@ module God
135
143
  God.port = @options[:port]
136
144
  end
137
145
 
146
+ if @options[:events]
147
+ God::EventHandler.load
148
+ end
149
+
138
150
  # set log level if requested
139
151
  if @options[:log_level]
140
152
  God.log_level = @options[:log_level]
@@ -50,12 +50,12 @@ module God
50
50
  end
51
51
 
52
52
  def pid
53
- self.watch.pid || File.read(self.pid_file).strip.to_i
53
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
54
54
  end
55
55
 
56
56
  def valid?
57
57
  valid = true
58
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
58
+ valid &= complain("Attribute 'pid_file' must be specified", self) if self.pid_file.nil? && self.watch.pid_file.nil?
59
59
  valid &= complain("Attribute 'above' must be specified", self) if self.above.nil?
60
60
  valid
61
61
  end
@@ -52,12 +52,12 @@ module God
52
52
  end
53
53
 
54
54
  def pid
55
- self.watch.pid || File.read(self.pid_file).strip.to_i
55
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
56
56
  end
57
57
 
58
58
  def valid?
59
59
  valid = true
60
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
60
+ valid &= complain("Attribute 'pid_file' must be specified", self) if self.pid_file.nil? && self.watch.pid_file.nil?
61
61
  valid &= complain("Attribute 'above' must be specified", self) if self.above.nil?
62
62
  valid
63
63
  end
@@ -23,6 +23,8 @@ module God
23
23
  # c.pid_file = "/var/run/mongrel.3000.pid"
24
24
  # end
25
25
  class ProcessExits < EventCondition
26
+ attr_accessor :pid_file
27
+
26
28
  def initialize
27
29
  self.info = "process exited"
28
30
  end
@@ -31,8 +33,12 @@ module God
31
33
  true
32
34
  end
33
35
 
36
+ def pid
37
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
38
+ end
39
+
34
40
  def register
35
- pid = self.watch.pid
41
+ pid = self.pid
36
42
 
37
43
  begin
38
44
  EventHandler.register(pid, :proc_exit) do |extra|
@@ -49,14 +55,15 @@ module God
49
55
  end
50
56
 
51
57
  def deregister
52
- pid = self.watch.pid
58
+ pid = self.pid
53
59
  if pid
54
60
  EventHandler.deregister(pid, :proc_exit)
55
61
 
56
62
  msg = "#{self.watch.name} deregistered 'proc_exit' event for pid #{pid}"
57
63
  applog(self.watch, :info, msg)
58
64
  else
59
- applog(self.watch, :error, "#{self.watch.name} could not deregister: no cached PID or PID file #{self.watch.pid_file} (#{self.base_name})")
65
+ pid_file_location = self.pid_file || self.watch.pid_file
66
+ applog(self.watch, :error, "#{self.watch.name} could not deregister: no cached PID or PID file #{pid_file_location} (#{self.base_name})")
60
67
  end
61
68
  end
62
69
  end
@@ -37,12 +37,12 @@ module God
37
37
  attr_accessor :running, :pid_file
38
38
 
39
39
  def pid
40
- self.watch.pid || File.read(self.pid_file).strip.to_i
40
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
41
41
  end
42
42
 
43
43
  def valid?
44
44
  valid = true
45
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
45
+ valid &= complain("Attribute 'pid_file' must be specified", self) if self.pid_file.nil? && self.watch.pid_file.nil?
46
46
  valid &= complain("Attribute 'running' must be specified", self) if self.running.nil?
47
47
  valid
48
48
  end
@@ -50,12 +50,7 @@ module God
50
50
  def test
51
51
  self.info = []
52
52
 
53
- # unless File.exist?(self.watch.pid_file)
54
- # self.info << "#{self.watch.name} #{self.class.name}: no such pid file: #{self.watch.pid_file}"
55
- # return !self.running
56
- # end
57
-
58
- pid = self.watch.pid
53
+ pid = self.pid
59
54
  active = pid && System::Process.new(pid).exists?
60
55
 
61
56
  if (self.running && active)
@@ -22,8 +22,8 @@ class BleakHouseDiagnostic
22
22
  File.delete(LOG_FILE) rescue nil
23
23
  end
24
24
 
25
- def self.snapshot
26
- self.logger.snapshot(LOG_FILE, "timer", false) if self.logger
25
+ def self.snapshot(name)
26
+ self.logger.snapshot(LOG_FILE, name, false) if self.logger
27
27
  end
28
28
 
29
29
  def self.spin(delay = 1)
@@ -40,12 +40,13 @@ module God
40
40
 
41
41
  def self.deregister(pid, event=nil)
42
42
  if watching_pid? pid
43
+ running = ::Process.kill(0, pid.to_i) rescue false
43
44
  if event.nil?
44
45
  @@actions.delete(pid)
45
- @@handler.register_process(pid, []) if system("kill -0 #{pid} &> /dev/null")
46
+ @@handler.register_process(pid, []) if running
46
47
  else
47
48
  @@actions[pid].delete(event)
48
- @@handler.register_process(pid, @@actions[pid].keys) if system("kill -0 #{pid} &> /dev/null")
49
+ @@handler.register_process(pid, @@actions[pid].keys) if running
49
50
  end
50
51
  end
51
52
  end
@@ -8,7 +8,7 @@ module God
8
8
 
9
9
  # Return true if this process is running, false otherwise
10
10
  def exists?
11
- system("kill -0 #{@pid} &> /dev/null")
11
+ !!::Process.kill(0, @pid) rescue false
12
12
  end
13
13
 
14
14
  # Memory usage in kilobytes (resident set size)
data/test/helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require File.join(File.dirname(__FILE__), *%w[.. lib god])
2
+ God::EventHandler.load
2
3
 
3
4
  require 'test/unit'
4
5
  require 'set'
data/test/test_process.rb CHANGED
@@ -115,7 +115,7 @@ class TestProcessDaemon < Test::Unit::TestCase
115
115
  # alive?
116
116
 
117
117
  def test_alive_should_call_system_process_exists
118
- File.expects(:read).with('blah.pid').returns('1234')
118
+ File.expects(:read).with('blah.pid').times(2).returns('1234')
119
119
  System::Process.any_instance.expects(:exists?).returns(false)
120
120
  assert !@p.alive?
121
121
  end
@@ -165,7 +165,7 @@ class TestProcessDaemon < Test::Unit::TestCase
165
165
  File.stubs(:read).returns("123")
166
166
  assert_equal 123, @p.pid
167
167
 
168
- File.stubs(:read).returns("")
168
+ File.stubs(:read).raises(Errno::ENOENT)
169
169
  assert_equal 123, @p.pid
170
170
 
171
171
  File.stubs(:read).returns("246")
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: god
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.7.0
7
- date: 2008-02-01 00:00:00 -08:00
6
+ version: 0.7.3
7
+ date: 2008-02-13 00:00:00 -08:00
8
8
  summary: Like monit, only awesome
9
9
  require_paths:
10
10
  - lib
@@ -176,5 +176,5 @@ dependencies:
176
176
  requirements:
177
177
  - - ">="
178
178
  - !ruby/object:Gem::Version
179
- version: 1.3.0
179
+ version: 1.4.0
180
180
  version: