Revision cf2a3529 snf-cyclades-gtools/synnefo/ganeti/eventd.py
b/snf-cyclades-gtools/synnefo/ganeti/eventd.py | ||
---|---|---|
51 | 51 |
import pyinotify |
52 | 52 |
import daemon |
53 | 53 |
import daemon.pidlockfile |
54 |
import socket |
|
54 |
import daemon.runner |
|
55 |
from lockfile import LockTimeout |
|
55 | 56 |
from signal import signal, SIGINT, SIGTERM |
56 | 57 |
|
57 | 58 |
from ganeti import utils |
... | ... | |
286 | 287 |
|
287 | 288 |
(opts, args) = parse_arguments(sys.argv[1:]) |
288 | 289 |
|
289 |
# Create pidfile |
|
290 |
pidf = daemon.pidlockfile.TimeoutPIDLockFile(opts.pid_file, 10) |
|
291 | 290 |
|
292 | 291 |
# Initialize logger |
293 | 292 |
lvl = logging.DEBUG if opts.debug else logging.INFO |
... | ... | |
301 | 300 |
logger.addHandler(handler) |
302 | 301 |
handler_logger = logger |
303 | 302 |
|
303 |
# Create pidfile |
|
304 |
pidf = daemon.pidlockfile.TimeoutPIDLockFile(opts.pid_file, 10) |
|
305 |
|
|
306 |
# Remove any stale PID files, left behind by previous invocations |
|
307 |
if daemon.runner.is_pidfile_stale(pidf): |
|
308 |
logger.warning("Removing stale PID lock file %s", pidf.path) |
|
309 |
pidf.break_lock() |
|
310 |
|
|
304 | 311 |
# Become a daemon: |
305 | 312 |
# Redirect stdout and stderr to handler.stream to catch |
306 | 313 |
# early errors in the daemonization process [e.g., pidfile creation] |
... | ... | |
311 | 318 |
stdout=handler.stream, |
312 | 319 |
stderr=handler.stream, |
313 | 320 |
files_preserve=[handler.stream]) |
314 |
daemon_context.open() |
|
321 |
try: |
|
322 |
daemon_context.open() |
|
323 |
except (daemon.pidlockfile.AlreadyLocked, LockTimeout): |
|
324 |
logger.critical("Failed to lock pidfile %s, another instance running?", |
|
325 |
pidf.path) |
|
326 |
sys.exit(1) |
|
327 |
|
|
315 | 328 |
logger.info("Became a daemon") |
316 | 329 |
|
317 | 330 |
# Catch signals to ensure graceful shutdown |
Also available in: Unified diff