Revision de081774 logic/dispatcher.py
b/logic/dispatcher.py | ||
---|---|---|
174 | 174 |
parser = OptionParser() |
175 | 175 |
parser.add_option("-d", "--debug", action="store_true", default=False, |
176 | 176 |
dest="debug", help="Enable debug mode") |
177 |
parser.add_option("-l", "--log", dest="log_file", |
|
178 |
default=settings.DISPATCHER_LOG_FILE, metavar="FILE", |
|
179 |
help="Write log to FILE instead of %s" % |
|
180 |
settings.DISPATCHER_LOG_FILE) |
|
181 | 177 |
parser.add_option("-c", "--cleanup-queues", action="store_true", |
182 | 178 |
default=False, dest="cleanup_queues", |
183 | 179 |
help="Remove all declared queues (DANGEROUS!)") |
184 | 180 |
parser.add_option("-w", "--workers", default=2, dest="workers", |
185 | 181 |
help="Number of workers to spawn", type="int") |
186 |
|
|
182 |
parser.add_option("-p", '--pid-file', dest="pid_file", |
|
183 |
default=os.path.join(os.getcwd(), "dispatcher.pid"), |
|
184 |
help="Save PID to file (default:%s)" % |
|
185 |
os.path.join(os.getcwd(), "dispatcher.pid")) |
|
186 |
|
|
187 | 187 |
return parser.parse_args(args) |
188 | 188 |
|
189 | 189 |
|
... | ... | |
245 | 245 |
debug_mode() |
246 | 246 |
return |
247 | 247 |
|
248 |
# Create pidfile |
|
249 |
pidf = pidfile.TimeoutPIDLockFile("/Volumes/Files/Developer/grnet/synnefo/dispatcher.pid", 10) |
|
250 |
pidf.acquire() |
|
251 |
pidf.__enter__() |
|
252 |
|
|
253 | 248 |
# Become a daemon |
254 | 249 |
daemon_context = daemon.DaemonContext( |
255 | 250 |
stdout=sys.stdout, |
... | ... | |
257 | 252 |
umask=022) |
258 | 253 |
|
259 | 254 |
daemon_context.open() |
255 |
|
|
256 |
# Create pidfile |
|
257 |
pidf = pidfile.TimeoutPIDLockFile(opts.pid_file, 10) |
|
258 |
pidf.acquire() |
|
259 |
|
|
260 | 260 |
logger.info("Became a daemon") |
261 | 261 |
|
262 | 262 |
# Fork workers |
... | ... | |
282 | 282 |
signal(SIGTERM, _parent_handler) |
283 | 283 |
|
284 | 284 |
# Wait for all children processes to die, one by one |
285 |
for pid in children:
|
|
286 |
try:
|
|
287 |
os.waitpid(pid, 0)
|
|
288 |
except Exception:
|
|
289 |
pass
|
|
290 |
|
|
291 |
pidf.release()
|
|
292 |
pidf.__exit__()
|
|
285 |
try :
|
|
286 |
for pid in children:
|
|
287 |
try:
|
|
288 |
os.waitpid(pid, 0)
|
|
289 |
except Exception:
|
|
290 |
pass |
|
291 |
finally:
|
|
292 |
pidf.release()
|
|
293 | 293 |
|
294 | 294 |
if __name__ == "__main__": |
295 | 295 |
logging.basicConfig(level=logging.DEBUG) |
Also available in: Unified diff