diff options
author | Andrew Dolgov <[email protected]> | 2008-01-23 10:30:55 +0100 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2008-01-23 10:30:55 +0100 |
commit | 6a69e61ffbd1fe8ff348adc84fe32c7b580c9e75 (patch) | |
tree | 535a201fc142b68e4c651b752c2a9b2bf14f636b /update_daemon2.php | |
parent | b7ff666fe8f88e036f5c31a62e4793ef06e089b6 (diff) |
update_daemon2: make proper lockfile
Diffstat (limited to 'update_daemon2.php')
-rw-r--r-- | update_daemon2.php | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/update_daemon2.php b/update_daemon2.php index 3721a0979..650b101dd 100644 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -7,7 +7,8 @@ declare(ticks = 1); - require "config.php"; + require_once "config.php"; + require_once "functions.php"; define('MAX_JOBS', 2); define('CLIENT_PROCESS', './update_daemon2_client.php SRV_RUN_OK'); @@ -23,7 +24,20 @@ pcntl_waitpid(-1, $status, WNOHANG); } + function sigint_handler() { + unlink(LOCK_DIRECTORY . "/update_daemon.lock"); + die("Received SIGINT. Exiting.\n"); + } + pcntl_signal(SIGCHLD, 'sigchld_handler'); + pcntl_signal(SIGINT, 'sigint_handler'); + + $lock_handle = make_lockfile("update_daemon.lock"); + + if (!$lock_handle) { + die("error: Can't create lockfile ($lock_filename). ". + "Maybe another daemon is already running.\n"); + } while (true) { @@ -43,6 +57,7 @@ print "OK [$running_jobs]\n"; } else { pcntl_signal(SIGCHLD, SIG_IGN); + pcntl_signal(SIGINT, SIG_DFL); passthru(CLIENT_PROCESS); exit(0); } |