public
Fork of mojombo/god
Description: Ruby process monitor
Homepage: http://god.rubyforge.org
Clone URL: git://github.com/auser/god.git
Allowing directories to be loaded at start
Bertg (author)
Sat Mar 01 06:59:55 -0800 2008
commit  15f0ceeef36e49eb51d6efcc7ed4df7b6a03d14f
tree    5f7e59f04922d49e431b30d21c74aaf572776315
parent  f43bb13ed51dad95d6ba51de9fe80979d81df0b4
...
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
 
64
65
66
...
68
69
70
71
72
73
 
74
75
76
...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
 
 
 
 
 
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
 
 
173
174
175
176
177
178
179
180
181
182
183
 
 
 
184
185
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
188
189
...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
103
104
105
 
 
 
 
 
 
 
 
 
 
106
 
107
108
109
110
...
112
113
114
 
 
 
115
116
117
118
...
125
126
127
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
129
130
...
141
142
143
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
145
146
147
148
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
151
152
 
 
 
 
 
 
 
 
 
 
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
0
@@ -33,6 +33,60 @@ module God
0
         end
0
       end
0
       
0
+ def default_run
0
+ # start attached pid watcher if necessary
0
+ if @options[:attach]
0
+ self.attach
0
+ end
0
+
0
+ if @options[:port]
0
+ God.port = @options[:port]
0
+ end
0
+
0
+ if @options[:events]
0
+ God::EventHandler.load
0
+ end
0
+
0
+ # set log level, defaults to WARN
0
+ if @options[:log_level]
0
+ God.log_level = @options[:log_level]
0
+ else
0
+ God.log_level = @options[:daemonize] ? :warn : :info
0
+ end
0
+
0
+ if @options[:config]
0
+ unless File.exist?(@options[:config])
0
+ abort "File not found: #{@options[:config]}"
0
+ end
0
+
0
+ # start the event handler
0
+ God::EventHandler.start if God::EventHandler.loaded?
0
+
0
+ load_config @options[:config]
0
+ end
0
+ end
0
+
0
+ def run_in_front
0
+ require 'god'
0
+
0
+ if @options[:bleakhouse]
0
+ BleakHouseDiagnostic.install
0
+ end
0
+
0
+ default_run
0
+
0
+ if @options[:log]
0
+ log_file = File.expand_path(@options[:log])
0
+ puts "Sending output to log file: #{log_file}"
0
+
0
+ # reset file descriptors
0
+ STDIN.reopen "/dev/null"
0
+ STDOUT.reopen(log_file, "a")
0
+ STDERR.reopen STDOUT
0
+ STDOUT.sync = true
0
+ end
0
+ end
0
+
0
       def run_daemonized
0
         # trap and ignore SIGHUP
0
         Signal.trap('HUP') {}
0
@@ -49,18 +103,8 @@ module God
0
             STDERR.reopen STDOUT
0
             STDOUT.sync = true
0
             
0
- # start attached pid watcher if necessary
0
- if @options[:attach]
0
- self.attach
0
- end
0
-
0
- # set port if requested
0
- if @options[:port]
0
- God.port = @options[:port]
0
- end
0
-
0
             # set pid if requested
0
- if @options[:pid]
0
+ if @options[:pid] # and as deamon
0
               God.pid = @options[:pid]
0
             end
0
             
0
@@ -68,9 +112,7 @@ module God
0
               Logger.syslog = false
0
             end
0
             
0
- if @options[:events]
0
- God::EventHandler.load
0
- end
0
+ default_run
0
             
0
             unless God::EventHandler.loaded?
0
               puts
0
@@ -83,34 +125,6 @@ module God
0
               puts
0
             end
0
             
0
- # load config
0
- if @options[:config]
0
- # set log level, defaults to WARN
0
- if @options[:log_level]
0
- God.log_level = @options[:log_level]
0
- else
0
- God.log_level = :warn
0
- end
0
-
0
- unless File.exist?(@options[:config])
0
- abort "File not found: #{@options[:config]}"
0
- end
0
-
0
- # start the event handler
0
- God::EventHandler.start if God::EventHandler.loaded?
0
-
0
- begin
0
- load File.expand_path(@options[:config])
0
- rescue Exception => e
0
- if e.instance_of?(SystemExit)
0
- raise
0
- else
0
- puts e.message
0
- puts e.backtrace.join("\n")
0
- abort "There was an error in your configuration file (see above)"
0
- end
0
- end
0
- end
0
           rescue => e
0
             puts e.message
0
             puts e.backtrace.join("\n")
0
@@ -127,63 +141,35 @@ module God
0
         exit
0
       end
0
       
0
- def run_in_front
0
- require 'god'
0
-
0
- if @options[:bleakhouse]
0
- BleakHouseDiagnostic.install
0
- end
0
-
0
- # start attached pid watcher if necessary
0
- if @options[:attach]
0
- self.attach
0
- end
0
-
0
- if @options[:port]
0
- God.port = @options[:port]
0
- end
0
-
0
- if @options[:events]
0
- God::EventHandler.load
0
- end
0
-
0
- # set log level if requested
0
- if @options[:log_level]
0
- God.log_level = @options[:log_level]
0
- end
0
-
0
- if @options[:config]
0
- unless File.exist?(@options[:config])
0
- abort "File not found: #{@options[:config]}"
0
+ def load_config(config)
0
+ if File.directory? config
0
+ files_loaded = false
0
+ Dir[File.expand_path('**/*.god', config)].each do |god_file|
0
+ files_loaded ||= load_god_file(File.expand_path(god_file))
0
           end
0
-
0
- # start the event handler
0
- God::EventHandler.start if God::EventHandler.loaded?
0
-
0
- begin
0
- load File.expand_path(@options[:config])
0
- rescue Exception => e
0
- if e.instance_of?(SystemExit)
0
- raise
0
- else
0
- puts e.message
0
- puts e.backtrace.join("\n")
0
- abort "There was an error in your configuration file (see above)"
0
- end
0
+ unless files_loaded
0
+ abort "No files could be loaded"
0
           end
0
-
0
- if @options[:log]
0
- log_file = File.expand_path(@options[:log])
0
- puts "Sending output to log file: #{log_file}"
0
-
0
- # reset file descriptors
0
- STDIN.reopen "/dev/null"
0
- STDOUT.reopen(log_file, "a")
0
- STDERR.reopen STDOUT
0
- STDOUT.sync = true
0
+ else
0
+ unless load_god_file(File.expand_path(config))
0
+ abort "File could not be loaded"
0
           end
0
         end
0
       end
0
+
0
+ def load_god_file(god_file)
0
+ load File.expand_path(god_file)
0
+ rescue Exception => e
0
+ if e.instance_of?(SystemExit)
0
+ raise
0
+ else
0
+ puts "There was an error in #{god_file}"
0
+ puts "\t" + e.message
0
+ puts "\t" + e.backtrace.join("\n\t")
0
+ return false
0
+ end
0
+ end
0
+
0
     end # Run
0
     
0
   end

Comments

    No one has commented yet.