From cf502d6e72ebbfd1cec622928c28bd38563e47d7 Mon Sep 17 00:00:00 2001 From: Tom Werner Date: Mon, 20 Aug 2007 13:24:07 -0700 Subject: [PATCH] fixed god binary exiting with -1; fixed god binary group control --- Announce.txt | 15 +++++++-------- History.txt | 8 ++++++++ bin/god | 13 +++++-------- lib/god.rb | 2 +- test/configs/child_polls/child_polls.god | 1 + test/test_god.rb | 29 +++++++++++++++++++++++++++-- 6 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Announce.txt b/Announce.txt index ebe9594..4ac05f5 100644 --- a/Announce.txt +++ b/Announce.txt @@ -1,17 +1,18 @@ Subject: [ANN] god 0.3.0 released -Wow, there are some really big changes and improvements in this release of god. Most noticeable is a simplification of the config file. Sadly, we must say goodbye to the much loved God.meddle and promote God.watch to top level. This change allows you to easily load in other god config files and have them work as expected. There's even a God.load that takes a glob-style file path string and expands it to load multiple files. +Plenty of big changes and improvements in this release of god. Most noticeable is a simplification of the config file. Sadly, we must say goodbye to the much loved God.meddle and promote God.watch to top level. This change allows you to easily load in other god config files and have them work as expected. There's even a God.load that takes a glob-style file path string and expands it to load multiple files. -PID file support is now baked in so you don't have to set a pid_file attribute on any conditions. This also allows god to support processes that aren't already daemons. If you don't specify a PID file for the watch, god will auto-daemonize and keep track of your process for you! To use this feature, you must either run as root (pid files will be stored by default in /var/run/god) or set the pid_file_directory attribute in a God.init block (see docs). +PID file support is now baked in so you don't have to set the pid_file attribute on conditions anymore. This also allows god to support processes that aren't already daemons. If you don't specify a PID file for the watch, god will auto-daemonize and keep track of your process for you! To use this feature, you must either run as root (pid files will be stored by default in /var/run/god) or set the pid_file_directory attribute in a God.init block (see docs). -For anyone that had problems installing the 0.2.0 release because of the events system not compiling, god 0.3.0 will now allow you to install without event support. Most systems are capable of supporting events, but it requires some dedication to get the headers in place and make sure your kernel is new enough. To determine if you have event support you can run "sudo god -V" (this MUST be run as root on Linux, as netlink connector requires root permissions). +For anyone that had problems installing the 0.2.0 release because of the events system not compiling, god 0.3.0 will now allow you to install without event support. Most systems are capable of supporting events, but it requires some dedication to get the headers in place and make sure your kernel is new enough. To determine if your god installation has event support you can run "sudo god -V" (this MUST be run as root on Linux, as netlink connector requires root permissions). -Using the god binary you will now be able to control your watches from the command line. You can start/stop/restart/monitor/unmonitor watches at your demand. +Using the god binary you can now control your watches from the command line. You can start/stop/restart/monitor/unmonitor watches at your demand. New watch attributes now available: + pid_file: sets the watch process' PID file location uid/gid: start processes as someone else (requires root access) - group: assign a watch to a group - autostart: prevent auto start on god start + group: assign a watch to a group (to control them all at once) + autostart: prevent auto start on god start if false Updated documentation is now available on the website: @@ -34,8 +35,6 @@ INSTALL sudo gem install god -* note: currently tested only on Redhat Linux and Darwin (won't work on Windows) - FEATURES diff --git a/History.txt b/History.txt index fd45da6..1c803ae 100644 --- a/History.txt +++ b/History.txt @@ -1,3 +1,11 @@ +== 0.4.0 + +* Major Enhancements + +* Bug Fixes + * Use exit!(0) instead of exit! in god binary to exit with code 0 (instead of default -1) + * Command line group control fixed + == 0.3.0 / 2007-08-17 * Fix netlink header problem on Ubuntu Edgy [Dan Sully] diff --git a/bin/god b/bin/god index 63d69c1..e795cf3 100755 --- a/bin/god +++ b/bin/god @@ -55,7 +55,7 @@ if options[:version] # print version puts "Version #{God::VERSION}" - exit! + exit!(0) elsif options[:info] require 'god' @@ -63,15 +63,12 @@ elsif options[:info] puts "Polls: enabled" puts "Events: " + God::EventHandler.event_system - exit! + exit!(0) elsif command = ARGV[0] require 'god' # a command was specified - - # disable at_exit - # module God; def self.at_exit; end; end - + # get the name of the watch/group name = ARGV[1] @@ -94,7 +91,7 @@ elsif command = ARGV[0] abort "Command '#{command}' is not valid. Run 'god --help' for usage" end - exit! + exit!(0) else # start god if !options[:daemonize] @@ -141,6 +138,6 @@ else ::Process.detach pid - exit! + exit!(0) end end diff --git a/lib/god.rb b/lib/god.rb index 573cdee..deb7f62 100644 --- a/lib/god.rb +++ b/lib/god.rb @@ -107,7 +107,7 @@ module God end self.groups[w.group] ||= [] - self.groups[w.group] << w.name + self.groups[w.group] << w end # register watch diff --git a/test/configs/child_polls/child_polls.god b/test/configs/child_polls/child_polls.god index effbd7c..79b6f89 100644 --- a/test/configs/child_polls/child_polls.god +++ b/test/configs/child_polls/child_polls.god @@ -6,6 +6,7 @@ God.watch do |w| w.grace = 2 w.uid = 'tom' w.gid = 'tom' + w.group = 'test' w.start_if do |start| start.condition(:process_running) do |c| diff --git a/test/test_god.rb b/test/test_god.rb index 54f2f60..9528c14 100644 --- a/test/test_god.rb +++ b/test/test_god.rb @@ -52,26 +52,34 @@ class TestGod < Test::Unit::TestCase end def test_watch_should_get_stored_by_group + a = nil + God.watch do |w| + a = w w.name = 'foo' w.group = 'test' end - assert_equal({'test' => ['foo']}, God.groups) + assert_equal({'test' => [a]}, God.groups) end def test_watches_should_get_stored_by_group + a = nil + b = nil + God.watch do |w| + a = w w.name = 'foo' w.group = 'test' end God.watch do |w| + b = w w.name = 'bar' w.group = 'test' end - assert_equal({'test' => ['foo', 'bar']}, God.groups) + assert_equal({'test' => [a, b]}, God.groups) end def test_watch_should_allow_multiple_watches @@ -149,6 +157,23 @@ class TestGod < Test::Unit::TestCase end end + def test_control_should_operate_on_each_watch_in_group + God.watch do |w| + w.name = 'foo1' + w.group = 'bar' + end + + God.watch do |w| + w.name = 'foo2' + w.group = 'bar' + end + + God.watches['foo1'].expects(:monitor) + God.watches['foo2'].expects(:monitor) + + God.control('bar', 'start') + end + # start def test_start_should_check_for_at_least_one_watch -- 2.11.4.GIT