god 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. data/History.txt +26 -2
  2. data/Manifest.txt +19 -5
  3. data/Rakefile +7 -2
  4. data/bin/god +131 -11
  5. data/examples/events.god +52 -0
  6. data/examples/gravatar.god +29 -35
  7. data/ext/god/extconf.rb +49 -2
  8. data/ext/god/kqueue_handler.c +2 -2
  9. data/ext/god/netlink_handler.c +17 -4
  10. data/lib/god.rb +127 -25
  11. data/lib/god/behavior.rb +8 -3
  12. data/lib/god/behaviors/clean_pid_file.rb +2 -8
  13. data/lib/god/condition.rb +6 -5
  14. data/lib/god/conditions/cpu_usage.rb +4 -4
  15. data/lib/god/conditions/lambda.rb +19 -0
  16. data/lib/god/conditions/memory_usage.rb +4 -4
  17. data/lib/god/conditions/process_exits.rb +5 -7
  18. data/lib/god/conditions/process_running.rb +4 -4
  19. data/lib/god/errors.rb +3 -0
  20. data/lib/god/event_handler.rb +28 -3
  21. data/lib/god/event_handlers/dummy_handler.rb +13 -0
  22. data/lib/god/event_handlers/kqueue_handler.rb +2 -0
  23. data/lib/god/event_handlers/netlink_handler.rb +2 -0
  24. data/lib/god/hub.rb +40 -23
  25. data/lib/god/metric.rb +4 -4
  26. data/lib/god/process.rb +105 -0
  27. data/lib/god/registry.rb +28 -0
  28. data/lib/god/server.rb +3 -4
  29. data/lib/god/sugar.rb +47 -0
  30. data/lib/god/system/process.rb +1 -2
  31. data/lib/god/timer.rb +13 -6
  32. data/lib/god/watch.rb +61 -29
  33. data/test/configs/child_events/child_events.god +25 -0
  34. data/test/configs/child_events/simple_server.rb +3 -0
  35. data/test/configs/child_polls/child_polls.god +15 -0
  36. data/test/configs/child_polls/simple_server.rb +3 -0
  37. data/test/configs/daemon_events/daemon_events.god +30 -0
  38. data/test/configs/daemon_events/simple_server.rb +6 -0
  39. data/test/configs/real.rb +47 -49
  40. data/test/configs/test.rb +52 -62
  41. data/test/helper.rb +44 -14
  42. data/test/test_behavior.rb +10 -2
  43. data/test/test_condition.rb +19 -3
  44. data/test/test_conditions_process_running.rb +42 -0
  45. data/test/test_event_handler.rb +73 -0
  46. data/test/test_god.rb +206 -9
  47. data/test/test_handlers_kqueue_handler.rb +12 -0
  48. data/test/test_hub.rb +157 -0
  49. data/test/test_metric.rb +30 -2
  50. data/test/test_process.rb +84 -0
  51. data/test/test_registry.rb +14 -0
  52. data/test/test_server.rb +3 -2
  53. data/test/test_sugar.rb +42 -0
  54. data/test/test_system_process.rb +1 -1
  55. data/test/test_timer.rb +8 -1
  56. data/test/test_watch.rb +137 -2
  57. metadata +28 -17
  58. data/examples/local.god +0 -60
  59. data/ext/god/Makefile +0 -149
  60. data/lib/god/base.rb +0 -13
  61. data/lib/god/meddle.rb +0 -38
  62. data/test/test_meddle.rb +0 -46
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: god
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-07-18 00:00:00 -07:00
6
+ version: 0.3.0
7
+ date: 2007-08-17 00:00:00 -07:00
8
8
  summary: Like monit, only awesome
9
9
  require_paths:
10
10
  - lib
@@ -35,46 +35,60 @@ files:
35
35
  - README.txt
36
36
  - Rakefile
37
37
  - bin/god
38
+ - examples/events.god
38
39
  - examples/gravatar.god
39
- - examples/local.god
40
- - ext/god/Makefile
41
40
  - ext/god/extconf.rb
42
41
  - ext/god/kqueue_handler.c
43
42
  - ext/god/netlink_handler.c
44
43
  - lib/god.rb
45
- - lib/god/base.rb
46
44
  - lib/god/behavior.rb
47
45
  - lib/god/behaviors/clean_pid_file.rb
48
46
  - lib/god/condition.rb
49
47
  - lib/god/conditions/always.rb
50
48
  - lib/god/conditions/cpu_usage.rb
49
+ - lib/god/conditions/lambda.rb
51
50
  - lib/god/conditions/memory_usage.rb
52
51
  - lib/god/conditions/process_exits.rb
53
52
  - lib/god/conditions/process_running.rb
54
53
  - lib/god/conditions/timeline.rb
55
54
  - lib/god/errors.rb
56
55
  - lib/god/event_handler.rb
56
+ - lib/god/event_handlers/dummy_handler.rb
57
57
  - lib/god/event_handlers/kqueue_handler.rb
58
58
  - lib/god/event_handlers/netlink_handler.rb
59
59
  - lib/god/hub.rb
60
- - lib/god/meddle.rb
61
60
  - lib/god/metric.rb
61
+ - lib/god/process.rb
62
+ - lib/god/registry.rb
62
63
  - lib/god/reporter.rb
63
64
  - lib/god/server.rb
65
+ - lib/god/sugar.rb
64
66
  - lib/god/system/process.rb
65
67
  - lib/god/timer.rb
66
68
  - lib/god/watch.rb
69
+ - test/configs/child_events/child_events.god
70
+ - test/configs/child_events/simple_server.rb
71
+ - test/configs/child_polls/child_polls.god
72
+ - test/configs/child_polls/simple_server.rb
73
+ - test/configs/daemon_events/daemon_events.god
74
+ - test/configs/daemon_events/simple_server.rb
67
75
  - test/configs/real.rb
68
76
  - test/configs/test.rb
69
77
  - test/helper.rb
70
78
  - test/suite.rb
71
79
  - test/test_behavior.rb
72
80
  - test/test_condition.rb
81
+ - test/test_conditions_process_running.rb
82
+ - test/test_event_handler.rb
73
83
  - test/test_god.rb
74
- - test/test_meddle.rb
84
+ - test/test_handlers_kqueue_handler.rb
85
+ - test/test_hub.rb
75
86
  - test/test_metric.rb
87
+ - test/test_process.rb
88
+ - test/test_registry.rb
76
89
  - test/test_reporter.rb
77
90
  - test/test_server.rb
91
+ - test/test_sugar.rb
78
92
  - test/test_system_process.rb
79
93
  - test/test_timeline.rb
80
94
  - test/test_timer.rb
@@ -82,11 +96,17 @@ files:
82
96
  test_files:
83
97
  - test/test_behavior.rb
84
98
  - test/test_condition.rb
99
+ - test/test_conditions_process_running.rb
100
+ - test/test_event_handler.rb
85
101
  - test/test_god.rb
86
- - test/test_meddle.rb
102
+ - test/test_handlers_kqueue_handler.rb
103
+ - test/test_hub.rb
87
104
  - test/test_metric.rb
105
+ - test/test_process.rb
106
+ - test/test_registry.rb
88
107
  - test/test_reporter.rb
89
108
  - test/test_server.rb
109
+ - test/test_sugar.rb
90
110
  - test/test_system_process.rb
91
111
  - test/test_timeline.rb
92
112
  - test/test_timer.rb
@@ -105,15 +125,6 @@ extensions:
105
125
  requirements: []
106
126
 
107
127
  dependencies:
108
- - !ruby/object:Gem::Dependency
109
- name: daemons
110
- version_requirement:
111
- version_requirements: !ruby/object:Gem::Version::Requirement
112
- requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: 1.0.7
116
- version:
117
128
  - !ruby/object:Gem::Dependency
118
129
  name: hoe
119
130
  version_requirement:
@@ -1,60 +0,0 @@
1
- # This example shows how you might keep a local development Rails server up
2
- # and running on your Mac.
3
-
4
- # Run with:
5
- # god start -c /path/to/local.god
6
-
7
- RAILS_ROOT = "/Users/tom/dev/powerset/querytopia"
8
-
9
- God.meddle do |god|
10
- god.watch do |w|
11
- w.name = "local-3000"
12
- w.interval = 5 # seconds
13
- w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -d"
14
- w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
15
- w.grace = 5
16
-
17
- pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
18
-
19
- # clean pid files before start if necessary
20
- w.behavior(:clean_pid_file) do |b|
21
- b.pid_file = pid_file
22
- end
23
-
24
- # start if process is not running
25
- w.start_if do |start|
26
- start.condition(:process_exits) do |c|
27
- c.pid_file = pid_file
28
- end
29
- end
30
-
31
- # restart if memory or cpu is too high
32
- w.restart_if do |restart|
33
- restart.condition(:memory_usage) do |c|
34
- c.pid_file = pid_file
35
- c.above = (50 * 1024) # 50mb
36
- c.times = [3, 5]
37
- end
38
-
39
- restart.condition(:cpu_usage) do |c|
40
- c.pid_file = pid_file
41
- c.above = 10 # percent
42
- c.times = [3, 5]
43
- end
44
- end
45
- end
46
-
47
- # clear old session files
48
- god.watch do |w|
49
- w.name = "local-session-cleanup"
50
- w.interval = 60 # seconds
51
- w.cwd = File.join(RAILS_ROOT, 'tmp/sessions')
52
- w.start = lambda do
53
- Dir['ruby_sess.*'].select { |f| File.mtime(f) < Time.now - (7 * 24 * 60 * 60) }.each { |f| File.delete(f) }
54
- end
55
-
56
- w.start_if do |start|
57
- start.condition(:always)
58
- end
59
- end
60
- end
@@ -1,149 +0,0 @@
1
-
2
- SHELL = /bin/sh
3
-
4
- #### Start of system configuration section. ####
5
-
6
- srcdir = .
7
- topdir = /usr/local/lib/ruby/1.8/i686-darwin8.9.1
8
- hdrdir = $(topdir)
9
- VPATH = $(srcdir):$(topdir):$(hdrdir)
10
- prefix = $(DESTDIR)/usr/local
11
- exec_prefix = $(prefix)
12
- sitedir = $(DESTDIR)/p/libdata/ruby
13
- rubylibdir = $(libdir)/ruby/$(ruby_version)
14
- docdir = $(datarootdir)/doc/$(PACKAGE)
15
- dvidir = $(docdir)
16
- datarootdir = $(prefix)/share
17
- archdir = $(rubylibdir)/$(arch)
18
- sbindir = $(exec_prefix)/sbin
19
- psdir = $(docdir)
20
- localedir = $(datarootdir)/locale
21
- htmldir = $(docdir)
22
- datadir = $(datarootdir)
23
- includedir = $(prefix)/include
24
- infodir = $(datarootdir)/info
25
- sysconfdir = $(prefix)/etc
26
- mandir = $(datarootdir)/man
27
- libdir = $(exec_prefix)/lib
28
- sharedstatedir = $(prefix)/com
29
- oldincludedir = $(DESTDIR)/usr/include
30
- pdfdir = $(docdir)
31
- sitearchdir = $(sitelibdir)/$(sitearch)
32
- bindir = $(exec_prefix)/bin
33
- localstatedir = $(prefix)/var
34
- sitelibdir = $(sitedir)/$(ruby_version)
35
- libexecdir = $(exec_prefix)/libexec
36
-
37
- CC = gcc
38
- LIBRUBY = $(LIBRUBY_A)
39
- LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
40
- LIBRUBYARG_SHARED =
41
- LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
42
-
43
- RUBY_EXTCONF_H =
44
- CFLAGS = -fno-common -g -O2 -pipe -fno-common
45
- INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
46
- CPPFLAGS =
47
- CXXFLAGS = $(CFLAGS)
48
- DLDFLAGS =
49
- LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
50
- AR = ar
51
- EXEEXT =
52
-
53
- RUBY_INSTALL_NAME = ruby
54
- RUBY_SO_NAME = ruby
55
- arch = i686-darwin8.9.1
56
- sitearch = i686-darwin8.9.1
57
- ruby_version = 1.8
58
- ruby = /usr/local/bin/ruby
59
- RUBY = $(ruby)
60
- RM = rm -f
61
- MAKEDIRS = mkdir -p
62
- INSTALL = /usr/bin/install -c
63
- INSTALL_PROG = $(INSTALL) -m 0755
64
- INSTALL_DATA = $(INSTALL) -m 644
65
- COPY = cp
66
-
67
- #### End of system configuration section. ####
68
-
69
- preload =
70
-
71
- libpath = $(libdir)
72
- LIBPATH = -L"$(libdir)"
73
- DEFFILE =
74
-
75
- CLEANFILES =
76
- DISTCLEANFILES =
77
-
78
- extout =
79
- extout_prefix =
80
- target_prefix =
81
- LOCAL_LIBS =
82
- LIBS = -lpthread -ldl -lobjc
83
- SRCS = kqueue_handler.c netlink_handler.c
84
- OBJS = kqueue_handler.o netlink_handler.o
85
- TARGET = kqueue_handler_ext
86
- DLLIB = $(TARGET).bundle
87
- EXTSTATIC =
88
- STATIC_LIB =
89
-
90
- RUBYCOMMONDIR = $(sitedir)$(target_prefix)
91
- RUBYLIBDIR = $(sitelibdir)$(target_prefix)
92
- RUBYARCHDIR = $(sitearchdir)$(target_prefix)
93
-
94
- TARGET_SO = $(DLLIB)
95
- CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
96
- CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
97
-
98
- all: $(DLLIB)
99
- static: $(STATIC_LIB)
100
-
101
- clean:
102
- @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
103
-
104
- distclean: clean
105
- @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
106
- @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
107
-
108
- realclean: distclean
109
- install: install-so install-rb
110
-
111
- install-so: $(RUBYARCHDIR)
112
- install-so: $(RUBYARCHDIR)/$(DLLIB)
113
- $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
114
- $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
115
- install-rb: pre-install-rb install-rb-default
116
- install-rb-default: pre-install-rb-default
117
- pre-install-rb: Makefile
118
- pre-install-rb-default: Makefile
119
- $(RUBYARCHDIR):
120
- $(MAKEDIRS) $@
121
-
122
- site-install: site-install-so site-install-rb
123
- site-install-so: install-so
124
- site-install-rb: install-rb
125
-
126
- .SUFFIXES: .c .m .cc .cxx .cpp .C .o
127
-
128
- .cc.o:
129
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
130
-
131
- .cxx.o:
132
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
133
-
134
- .cpp.o:
135
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
136
-
137
- .C.o:
138
- $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
139
-
140
- .c.o:
141
- $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
142
-
143
- $(DLLIB): $(OBJS)
144
- @-$(RM) $@
145
- $(LDSHARED) $(DLDFLAGS) $(LIBPATH) -o $@ $(OBJS) $(LOCAL_LIBS) $(LIBS)
146
-
147
-
148
-
149
- $(OBJS): ruby.h defines.h
@@ -1,13 +0,0 @@
1
- module God
2
-
3
- class Base
4
- def abort(msg)
5
- Kernel.abort(msg)
6
- end
7
-
8
- def self.abort(msg)
9
- Kernel.abort(msg)
10
- end
11
- end
12
-
13
- end
@@ -1,38 +0,0 @@
1
- module God
2
-
3
- class Meddle < Base
4
- # drb
5
- attr_accessor :server
6
-
7
- # api
8
- attr_accessor :watches
9
-
10
- # Create a new instance that is ready for use by a configuration file
11
- def initialize(options = {})
12
- self.watches = []
13
- self.server = Server.new(self, options[:host], options[:port])
14
- end
15
-
16
- # Instantiate a new, empty Watch object and pass it to the mandatory
17
- # block. The attributes of the watch will be set by the configuration
18
- # file.
19
- def watch
20
- w = Watch.new(self)
21
- yield(w)
22
-
23
- # ensure the new watch has a unique name
24
- unless @watches.select { |x| x.name == w.name }.empty?
25
- abort "Duplicate Watch with name '#{w.name}'"
26
- end
27
-
28
- # add to list of watches
29
- @watches << w
30
- end
31
-
32
- # Schedule all poll conditions and register all condition events
33
- def monitor
34
- @watches.each { |w| w.monitor }
35
- end
36
- end
37
-
38
- end
@@ -1,46 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestMeddle < Test::Unit::TestCase
4
- def setup
5
- Server.stubs(:new).returns(true)
6
- @meddle = Meddle.new
7
- end
8
-
9
- def test_should_initialize_watches_to_empty_array
10
- assert_equal [], @meddle.watches
11
- end
12
-
13
- def test_watches_should_get_stored
14
- watch = nil
15
- @meddle.watch { |w| watch = w }
16
-
17
- assert_equal 1, @meddle.watches.size
18
- assert_equal watch, @meddle.watches.first
19
- end
20
-
21
- def test_should_kick_off_a_server_instance
22
- Server.expects(:new).returns(true)
23
- Meddle.new
24
- end
25
-
26
- def test_should_take_an_options_hash
27
- Server.expects(:new)
28
- Meddle.new(:port => 5555)
29
- end
30
-
31
- def test_should_allow_multiple_watches
32
- @meddle.watch { |w| w.name = 'foo' }
33
-
34
- assert_nothing_raised do
35
- @meddle.watch { |w| w.name = 'bar' }
36
- end
37
- end
38
-
39
- def test_should_disallow_duplicate_watch_names
40
- @meddle.watch { |w| w.name = 'foo' }
41
-
42
- assert_raise AbortCalledError do
43
- @meddle.watch { |w| w.name = 'foo' }
44
- end
45
- end
46
- end