Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' into proc_fs

Conflicts:

	lib/god/system/process.rb
  • Loading branch information...
commit ba98fdce987aa50fe840a2cafd5f1f4e6e0815aa 2 parents 466dbc3 + 582fca9
@kevinclark kevinclark authored
View
1  .gitignore
@@ -2,3 +2,4 @@ coverage
pkg
*.log
logs
+*.rbc
View
16 History.txt
@@ -1,3 +1,19 @@
+== 0.7.5 / 2008-02-21
+ * Bug Fixes
+ * Remove Ruby's Logger and replace with custom SimpleLogger to stop threaded leak
+
+== 0.7.4 / 2008-02-18
+ * Bug Fixes
+ * Introduce local scope to prevent faulty optimization that causes memory to leak
+
+== 0.7.3 / 2008-02-14
+ * Minor Enhancements
+ * Add --bleakhouse to make running diagnostics easier
+ * Bug Fixes
+ * Use ::Process.kill(0, ...) instead of `kill -0` [queso]
+ * Fix pid_file behavior in process-centric conditions so they work with tasks [matias]
+ * Redirect output of daemonized god to log file or /dev/null earlier [_eric]
+
== 0.7.2 / 2008-02-04
* Bug Fixes
* Start event system for CLI commands
View
2  Manifest.txt
@@ -45,6 +45,7 @@ lib/god/logger.rb
lib/god/metric.rb
lib/god/process.rb
lib/god/registry.rb
+lib/god/simple_logger.rb
lib/god/socket.rb
lib/god/sugar.rb
lib/god/system/process.rb
@@ -67,6 +68,7 @@ test/configs/daemon_polls/daemon_polls.god
test/configs/daemon_polls/simple_server.rb
test/configs/degrading_lambda/degrading_lambda.god
test/configs/degrading_lambda/tcp_server.rb
+test/configs/matias/matias.god
test/configs/real.rb
test/configs/running_load/running_load.god
test/configs/stress/simple_server.rb
View
10 README.txt
@@ -24,12 +24,20 @@ Sign up for the god mailing list at http://groups.google.com/group/god-rb
== INSTALL:
$ sudo gem install god
+
+== CONTRIBUTE:
+
+Latest code is available at http://github.com/mojombo/god
+
+The 'master' branch can be cloned with:
+
+ $ git clone git://github.com/mojombo/god.git
== LICENSE:
(The MIT License)
-Copyright (c) 2007 FIX
+Copyright (c) 2007 Tom Preston-Werner
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
View
2  Rakefile
@@ -1,7 +1,7 @@
require 'rubygems'
require 'hoe'
-Hoe.new('god', '0.7.2') do |p|
+Hoe.new('god', '0.7.5') do |p|
p.rubyforge_name = 'god'
p.author = 'Tom Preston-Werner'
p.email = 'tom@rubyisawesome.com'
View
4 bin/god
@@ -87,6 +87,10 @@ begin
opts.on("--no-events", "Disable the event system") do
options[:events] = false
end
+
+ opts.on("--bleakhouse", "Enable bleakhouse profiling") do
+ options[:bleakhouse] = true
+ end
end
opts.parse!
View
5 lib/god.rb
@@ -5,7 +5,6 @@
# core
require 'stringio'
-require 'logger'
require 'fileutils'
begin
@@ -19,6 +18,7 @@
# internal requires
require 'god/errors'
+require 'god/simple_logger'
require 'god/logger'
require 'god/system/process'
@@ -74,7 +74,6 @@
# App wide logging system
LOG = God::Logger.new
-LOG.datetime_format = "%Y-%m-%d %H:%M:%S "
def applog(watch, level, text)
LOG.log(watch, level, text)
@@ -134,7 +133,7 @@ def safe_attr_accessor(*args)
end
module God
- VERSION = '0.7.2'
+ VERSION = '0.7.5'
LOG_BUFFER_SIZE_DEFAULT = 100
PID_FILE_DIRECTORY_DEFAULTS = ['/var/run/god', '~/.god/pids']
View
198 lib/god/cli/run.rb
@@ -33,6 +33,60 @@ def attach
end
end
+ def default_run
+ # start attached pid watcher if necessary
+ if @options[:attach]
+ self.attach
+ end
+
+ if @options[:port]
+ God.port = @options[:port]
+ end
+
+ if @options[:events]
+ God::EventHandler.load
+ end
+
+ # set log level, defaults to WARN
+ if @options[:log_level]
+ God.log_level = @options[:log_level]
+ else
+ God.log_level = @options[:daemonize] ? :warn : :info
+ end
+
+ if @options[:config]
+ unless File.exist?(@options[:config])
+ abort "File not found: #{@options[:config]}"
+ end
+
+ # start the event handler
+ God::EventHandler.start if God::EventHandler.loaded?
+
+ load_config @options[:config]
+ end
+ end
+
+ def run_in_front
+ require 'god'
+
+ if @options[:bleakhouse]
+ BleakHouseDiagnostic.install
+ end
+
+ default_run
+
+ if @options[:log]
+ log_file = File.expand_path(@options[:log])
+ puts "Sending output to log file: #{log_file}"
+
+ # reset file descriptors
+ STDIN.reopen "/dev/null"
+ STDOUT.reopen(log_file, "a")
+ STDERR.reopen STDOUT
+ STDOUT.sync = true
+ end
+ end
+
def run_daemonized
# trap and ignore SIGHUP
Signal.trap('HUP') {}
@@ -43,29 +97,14 @@ def run_daemonized
log_file = @options[:log] || "/dev/null"
- unless God::EventHandler.loaded?
- puts
- puts "***********************************************************************"
- puts "*"
- puts "* Event conditions are not available for your installation of god."
- puts "* You may still use and write custom conditions using the poll system"
- puts "*"
- puts "***********************************************************************"
- puts
- end
-
- # start attached pid watcher if necessary
- if @options[:attach]
- self.attach
- end
-
- # set port if requested
- if @options[:port]
- God.port = @options[:port]
- end
+ # reset file descriptors
+ STDIN.reopen "/dev/null"
+ STDOUT.reopen(log_file, "a")
+ STDERR.reopen STDOUT
+ STDOUT.sync = true
# set pid if requested
- if @options[:pid]
+ if @options[:pid] # and as deamon
God.pid = @options[:pid]
end
@@ -73,44 +112,19 @@ def run_daemonized
Logger.syslog = false
end
- if @options[:events]
- God::EventHandler.load
- end
+ default_run
- # load config
- if @options[:config]
- # set log level, defaults to WARN
- if @options[:log_level]
- God.log_level = @options[:log_level]
- else
- God.log_level = :warn
- end
-
- unless File.exist?(@options[:config])
- abort "File not found: #{@options[:config]}"
- end
-
- # start the event handler
- God::EventHandler.start if God::EventHandler.loaded?
-
- begin
- load File.expand_path(@options[:config])
- rescue Exception => e
- if e.instance_of?(SystemExit)
- raise
- else
- puts e.message
- puts e.backtrace.join("\n")
- abort "There was an error in your configuration file (see above)"
- end
- end
+ unless God::EventHandler.loaded?
+ puts
+ puts "***********************************************************************"
+ puts "*"
+ puts "* Event conditions are not available for your installation of god."
+ puts "* You may still use and write custom conditions using the poll system"
+ puts "*"
+ puts "***********************************************************************"
+ puts
end
- # reset file descriptors
- STDIN.reopen "/dev/null"
- STDOUT.reopen(log_file, "a")
- STDERR.reopen STDOUT
- STDOUT.sync = true
rescue => e
puts e.message
puts e.backtrace.join("\n")
@@ -127,59 +141,35 @@ def run_daemonized
exit
end
- def run_in_front
- require 'god'
-
- # start attached pid watcher if necessary
- if @options[:attach]
- self.attach
- end
-
- if @options[:port]
- God.port = @options[:port]
- end
-
- if @options[:events]
- God::EventHandler.load
- end
-
- # set log level if requested
- if @options[:log_level]
- God.log_level = @options[:log_level]
- end
-
- if @options[:config]
- unless File.exist?(@options[:config])
- abort "File not found: #{@options[:config]}"
+ def load_config(config)
+ if File.directory? config
+ files_loaded = false
+ Dir[File.expand_path('**/*.god', config)].each do |god_file|
+ files_loaded ||= load_god_file(File.expand_path(god_file))
end
-
- # start the event handler
- God::EventHandler.start if God::EventHandler.loaded?
-
- begin
- load File.expand_path(@options[:config])
- rescue Exception => e
- if e.instance_of?(SystemExit)
- raise
- else
- puts e.message
- puts e.backtrace.join("\n")
- abort "There was an error in your configuration file (see above)"
- end
+ unless files_loaded
+ abort "No files could be loaded"
end
-
- if @options[:log]
- log_file = File.expand_path(@options[:log])
- puts "Sending output to log file: #{log_file}"
-
- # reset file descriptors
- STDIN.reopen "/dev/null"
- STDOUT.reopen(log_file, "a")
- STDERR.reopen STDOUT
- STDOUT.sync = true
+ else
+ unless load_god_file(File.expand_path(config))
+ abort "File could not be loaded"
end
end
end
+
+ def load_god_file(god_file)
+ load File.expand_path(god_file)
+ rescue Exception => e
+ if e.instance_of?(SystemExit)
+ raise
+ else
+ puts "There was an error in #{god_file}"
+ puts "\t" + e.message
+ puts "\t" + e.backtrace.join("\n\t")
+ return false
+ end
+ end
+
end # Run
end
View
4 lib/god/conditions/cpu_usage.rb
@@ -50,12 +50,12 @@ def reset
end
def pid
- self.watch.pid || File.read(self.pid_file).strip.to_i
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
end
def valid?
valid = true
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
+ valid &= complain("Attribute 'pid_file' must be specified", self) if self.pid_file.nil? && self.watch.pid_file.nil?
valid &= complain("Attribute 'above' must be specified", self) if self.above.nil?
valid
end
View
4 lib/god/conditions/memory_usage.rb
@@ -52,12 +52,12 @@ def reset
end
def pid
- self.watch.pid || File.read(self.pid_file).strip.to_i
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
end
def valid?
valid = true
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
+ valid &= complain("Attribute 'pid_file' must be specified", self) if self.pid_file.nil? && self.watch.pid_file.nil?
valid &= complain("Attribute 'above' must be specified", self) if self.above.nil?
valid
end
View
13 lib/god/conditions/process_exits.rb
@@ -23,6 +23,8 @@ module Conditions
# c.pid_file = "/var/run/mongrel.3000.pid"
# end
class ProcessExits < EventCondition
+ attr_accessor :pid_file
+
def initialize
self.info = "process exited"
end
@@ -31,8 +33,12 @@ def valid?
true
end
+ def pid
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
+ end
+
def register
- pid = self.watch.pid
+ pid = self.pid
begin
EventHandler.register(pid, :proc_exit) do |extra|
@@ -49,14 +55,15 @@ def register
end
def deregister
- pid = self.watch.pid
+ pid = self.pid
if pid
EventHandler.deregister(pid, :proc_exit)
msg = "#{self.watch.name} deregistered 'proc_exit' event for pid #{pid}"
applog(self.watch, :info, msg)
else
- applog(self.watch, :error, "#{self.watch.name} could not deregister: no cached PID or PID file #{self.watch.pid_file} (#{self.base_name})")
+ pid_file_location = self.pid_file || self.watch.pid_file
+ applog(self.watch, :error, "#{self.watch.name} could not deregister: no cached PID or PID file #{pid_file_location} (#{self.base_name})")
end
end
end
View
11 lib/god/conditions/process_running.rb
@@ -37,12 +37,12 @@ class ProcessRunning < PollCondition
attr_accessor :running, :pid_file
def pid
- self.watch.pid || File.read(self.pid_file).strip.to_i
+ self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid
end
def valid?
valid = true
- valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
+ valid &= complain("Attribute 'pid_file' must be specified", self) if self.pid_file.nil? && self.watch.pid_file.nil?
valid &= complain("Attribute 'running' must be specified", self) if self.running.nil?
valid
end
@@ -50,12 +50,7 @@ def valid?
def test
self.info = []
- # unless File.exist?(self.watch.pid_file)
- # self.info << "#{self.watch.name} #{self.class.name}: no such pid file: #{self.watch.pid_file}"
- # return !self.running
- # end
-
- pid = self.watch.pid
+ pid = self.pid
active = pid && System::Process.new(pid).exists?
if (self.running && active)
View
1  lib/god/configurable.rb
@@ -31,6 +31,7 @@ def valid?
end
def base_name
+ x = 1 # fix for MRI's local scope optimization bug DO NOT REMOVE!
self.class.name.split('::').last
end
View
4 lib/god/diagnostics.rb
@@ -22,8 +22,8 @@ def self.install
File.delete(LOG_FILE) rescue nil
end
- def self.snapshot
- self.logger.snapshot(LOG_FILE, "timer", false) if self.logger
+ def self.snapshot(name)
+ self.logger.snapshot(LOG_FILE, name, false) if self.logger
end
def self.spin(delay = 1)
View
5 lib/god/event_handler.rb
@@ -40,12 +40,13 @@ def self.register(pid, event, &block)
def self.deregister(pid, event=nil)
if watching_pid? pid
+ running = ::Process.kill(0, pid.to_i) rescue false
if event.nil?
@@actions.delete(pid)
- @@handler.register_process(pid, []) if system("kill -0 #{pid} &> /dev/null")
+ @@handler.register_process(pid, []) if running
else
@@actions[pid].delete(event)
- @@handler.register_process(pid, @@actions[pid].keys) if system("kill -0 #{pid} &> /dev/null")
+ @@handler.register_process(pid, @@actions[pid].keys) if running
end
end
end
View
4 lib/god/logger.rb
@@ -1,6 +1,6 @@
module God
- class Logger < ::Logger
+ class Logger < SimpleLogger
SYSLOG_EQUIVALENTS = {:fatal => :crit,
:error => :err,
:warn => :debug,
@@ -22,7 +22,7 @@ def initialize
@mutex = Mutex.new
@capture = nil
@templogio = StringIO.new
- @templog = ::Logger.new(@templogio)
+ @templog = SimpleLogger.new(@templogio)
@templog.level = Logger::INFO
load_syslog
end
View
53 lib/god/simple_logger.rb
@@ -0,0 +1,53 @@
+module God
+
+ class SimpleLogger
+ DEBUG = 2
+ INFO = 4
+ WARN = 8
+ ERROR = 16
+ FATAL = 32
+
+ SEV_LABEL = {DEBUG => 'DEBUG',
+ INFO => 'INFO',
+ WARN => 'WARN',
+ ERROR => 'ERROR',
+ FATAL => 'FATAL'}
+
+ attr_accessor :datetime_format, :level
+
+ def initialize(io)
+ @io = io
+ @level = INFO
+ @datetime_format = "%Y-%m-%d %H:%M:%S"
+ end
+
+ def output(level, msg)
+ return if level < self.level
+
+ time = Time.now.strftime(self.datetime_format)
+ label = SEV_LABEL[level]
+ @io.print("#{label[0..0]} [#{time}] #{label.rjust(5)}: #{msg}\n")
+ end
+
+ def fatal(msg)
+ self.output(FATAL, msg)
+ end
+
+ def error(msg)
+ self.output(ERROR, msg)
+ end
+
+ def warn(msg)
+ self.output(WARN, msg)
+ end
+
+ def info(msg)
+ self.output(INFO, msg)
+ end
+
+ def debug(msg)
+ self.output(DEBUG, msg)
+ end
+ end
+
+end
View
2  lib/god/system/process.rb
@@ -9,7 +9,7 @@ def initialize(pid)
# Return true if this process is running, false otherwise
def exists?
- !!Process.kill(0, @pid) rescue false
+ !!::Process.kill(0, @pid) rescue false
end
# Memory usage in kilobytes (resident set size)
View
192 site/index.html
@@ -1,189 +1,11 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-<title>god - process and task monitoring done right</title>
-<link href="styles.css" rel="stylesheet" type="text/css" />
-<style type="text/css" media="screen">
-* {
- margin: 0;
- font-size: 100%;
-}
-
-body {
- font: normal .8em/1.5em "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
- color: #484848;
- background: #E6EAE9 url(images/bg_grey.gif);
-}
-
-a {
- color: #c75f3e;
- text-decoration: none;
-}
-
-a:hover,
-a:active {
- text-decoration: underline;
-}
-
-#mothership {
- width: 307px;
- height: 117px;
- margin: 0 auto;
- background: url(images/god_logo1.gif);
-}
-
-#content {
- width: 700px;
- margin: 3px auto;
- background: white;
- border: 1px solid #444;
- padding: 0 24px;
- background: #f8f8ff;
- overflow: hidden;
-}
-
-.banner {
- margin-top: 24px;
- border: 1px solid #ddd;
- width: 698px;
- height: 150px;
- background: url(images/banner.jpg);
-}
-
-#menu {
- margin-top: 5px;
-}
-
-#menu div.dots {
- background: url(images/red_dot.gif) repeat;
- height: 5px;
- width: 700px;
- font-size: 0;
-}
-
-#menu ul {
- font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
- font-weight: bold;
- text-transform: uppercase;
- color: #4D4D4D;
- font-size: 12px;
- padding: 0;
- margin: 0;
- margin-top: 0 !important;
- margin-top: -2px;
-}
-
-#menu li {
- display: inline;
- margin: 0 30px 0 0;
-}
-
-#menu a:link,
-#menu a:visited {
- color: #4D4D4D;
- text-decoration: none;
-}
-
-#menu a:hover,
-#menu a:active {
- color: black;
- text-decoration: none;
-}
-
-#page_home #menu li.menu_home a {
- color: #A70000;
-}
-
-.columnleft {
- float: left;
- width: 325px;
- margin-bottom: 20px;
-}
-
-.columnleft p {
- text-align: justify;
-}
-
-.columnright {
- float: right;
- width: 325px;
- margin-bottom: 20px;
-}
-
-h1 {
- font: bold 1.5em "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
- color: #f36e21;
- text-transform: uppercase;
- margin: 1.5em 0 .5em 0;
- clear: both;
-}
-
-p {
- margin-bottom: 1em;
-}
-
-ul {
- margin-bottom: 1em;
-}
-
-ul.features {
- padding: 0;
- margin-left: 1.5em !important;
- margin-left: 1.3em;
-}
-
-ul.features li {
- list-style-position: outside;
- list-style-type: circle;
- list-style-image: url(images/bullet.jpg);
- line-height: 1.4em;
-}
-
-#footer {
- text-align: center;
- color: white;
- margin-bottom: 50px;
-}
-
-
-
-pre {
- line-height: 1.3;
- border: 1px solid #ccc;
- padding: 1em;
- background-color: #efefef;
- margin: 1em 0;
-}
-
-code {
- font-size: 1.2em;
-}
-
-.ruby .keywords {
- color: blue;
-}
-
-.ruby .comment {
- color : green;
-}
-
-.ruby .string {
- color : teal;
-}
-
-.ruby .keywords {
- color : navy;
-}
-
-.ruby .brackets {
- color : navy;
-}
-</style>
-
-<script type="text/javascript" src="javascripts/code_highlighter.js"></script>
-<script type="text/javascript" src="javascripts/ruby.js"></script>
-
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+ <title>god - process and task monitoring done right</title>
+ <link href="stylesheets/layout.css" rel="stylesheet" type="text/css" />
+ <script type="text/javascript" src="javascripts/code_highlighter.js"></script>
+ <script type="text/javascript" src="javascripts/ruby.js"></script>
</head>
<body id="page_home">
@@ -225,10 +47,10 @@
</ul>
</div>
- <h1>Installation (v 0.6)</h1>
+ <h1>Installation (v 0.7.3)</h1>
<p>The best way to get god is via rubygems:</p>
<pre>$ sudo gem install god</pre>
- <p>You can also peruse or clone the code from <a href="http://repo.or.cz/w/god.git">http://repo.or.cz/w/god.git</a></p>
+ <p>You can also peruse or clone the code from <a href="git://github.com/mojombo/god.git">git://github.com/mojombo/god.git</a></p>
<h1>Requirements</h1>
View
174 site/stylesheets/layout.css
@@ -0,0 +1,174 @@
+* {
+ margin: 0;
+ font-size: 100%;
+}
+
+body {
+ font: normal .8em/1.5em "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+ color: #484848;
+ background: #E6EAE9 url(../images/bg_grey.gif);
+}
+
+a {
+ color: #c75f3e;
+ text-decoration: none;
+}
+
+a:hover,
+a:active {
+ text-decoration: underline;
+}
+
+#mothership {
+ width: 307px;
+ height: 117px;
+ margin: 0 auto;
+ background: url(../images/god_logo1.gif);
+}
+
+#content {
+ width: 700px;
+ margin: 3px auto;
+ background: white;
+ border: 1px solid #444;
+ padding: 0 24px;
+ background: #f8f8ff;
+ overflow: hidden;
+}
+
+.banner {
+ margin-top: 24px;
+ border: 1px solid #ddd;
+ width: 698px;
+ height: 150px;
+ background: url(../images/banner.jpg);
+}
+
+#menu {
+ margin-top: 5px;
+}
+
+#menu div.dots {
+ background: url(../images/red_dot.gif) repeat;
+ height: 5px;
+ width: 700px;
+ font-size: 0;
+}
+
+#menu ul {
+ font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+ font-weight: bold;
+ text-transform: uppercase;
+ color: #4D4D4D;
+ font-size: 12px;
+ padding: 0;
+ margin: 0;
+ margin-top: 0 !important;
+ margin-top: -2px;
+}
+
+#menu li {
+ display: inline;
+ margin: 0 30px 0 0;
+}
+
+#menu a:link,
+#menu a:visited {
+ color: #4D4D4D;
+ text-decoration: none;
+}
+
+#menu a:hover,
+#menu a:active {
+ color: black;
+ text-decoration: none;
+}
+
+#page_home #menu li.menu_home a {
+ color: #A70000;
+}
+
+.columnleft {
+ float: left;
+ width: 325px;
+ margin-bottom: 20px;
+}
+
+.columnleft p {
+ text-align: justify;
+}
+
+.columnright {
+ float: right;
+ width: 325px;
+ margin-bottom: 20px;
+}
+
+h1 {
+ font: bold 1.5em "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
+ color: #f36e21;
+ text-transform: uppercase;
+ margin: 1.5em 0 .5em 0;
+ clear: both;
+}
+
+p {
+ margin-bottom: 1em;
+}
+
+ul {
+ margin-bottom: 1em;
+}
+
+ul.features {
+ padding: 0;
+ margin-left: 1.5em !important;
+ margin-left: 1.3em;
+}
+
+ul.features li {
+ list-style-position: outside;
+ list-style-type: circle;
+ list-style-image: url(../images/bullet.jpg);
+ line-height: 1.4em;
+}
+
+#footer {
+ text-align: center;
+ color: white;
+ margin-bottom: 50px;
+}
+
+
+
+pre {
+ line-height: 1.3;
+ border: 1px solid #ccc;
+ padding: 1em;
+ background-color: #efefef;
+ margin: 1em 0;
+}
+
+code {
+ font-size: 1.2em;
+}
+
+.ruby .keywords {
+ color: blue;
+}
+
+.ruby .comment {
+ color : green;
+}
+
+.ruby .string {
+ color : teal;
+}
+
+.ruby .keywords {
+ color : navy;
+}
+
+.ruby .brackets {
+ color : navy;
+}
View
50 test/configs/matias/matias.god
@@ -0,0 +1,50 @@
+$pid_file = "/tmp/matias.pid"
+
+God.task do |w|
+ w.name = "watcher"
+ w.interval = 5.seconds
+ w.valid_states = [:init, :up, :down]
+ w.initial_state = :init
+
+ # determine the state on startup
+ w.transition(:init, { true => :up, false => :down }) do |on|
+ on.condition(:process_running) do |c|
+ c.running = true
+ c.pid_file = $pid_file
+ end
+ end
+
+ # when process is up
+ w.transition(:up, :down) do |on|
+ # transition to 'start' if process goes down
+ on.condition(:process_running) do |c|
+ c.running = false
+ c.pid_file = $pid_file
+ end
+
+ # send up info
+ on.condition(:lambda) do |c|
+ c.lambda = lambda do
+ puts 'yay I am up'
+ false
+ end
+ end
+ end
+
+ # when process is down
+ w.transition(:down, :up) do |on|
+ # transition to 'up' if process comes up
+ on.condition(:process_running) do |c|
+ c.running = true
+ c.pid_file = $pid_file
+ end
+
+ # send down info
+ on.condition(:lambda) do |c|
+ c.lambda = lambda do
+ puts 'boo I am down'
+ false
+ end
+ end
+ end
+end
View
4 test/configs/stress/stress.god
@@ -1,8 +1,8 @@
-('01'..'40').each do |i|
+('01'..'08').each do |i|
God.watch do |w|
w.name = "stress-#{i}"
w.start = "ruby " + File.join(File.dirname(__FILE__), *%w[simple_server.rb])
- w.interval = 1
+ w.interval = 0
w.grace = 2
w.group = 'test'
View
4 test/test_process.rb
@@ -115,7 +115,7 @@ def setup
# alive?
def test_alive_should_call_system_process_exists
- File.expects(:read).with('blah.pid').returns('1234')
+ File.expects(:read).with('blah.pid').times(2).returns('1234')
System::Process.any_instance.expects(:exists?).returns(false)
assert !@p.alive?
end
@@ -165,7 +165,7 @@ def test_pid_should_retain_last_pid_value_if_pid_file_is_removed
File.stubs(:read).returns("123")
assert_equal 123, @p.pid
- File.stubs(:read).returns("")
+ File.stubs(:read).raises(Errno::ENOENT)
assert_equal 123, @p.pid
File.stubs(:read).returns("246")
Please sign in to comment.
Something went wrong with that request. Please try again.