3 // this daemon runs in the background and updates all feeds
6 // define('DEFAULT_ERROR_LEVEL', E_ALL);
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE
);
11 define('DISABLE_SESSIONS', true);
13 require_once "version.php";
15 if (strpos(VERSION
, ".99") !== false ||
getenv('DAEMON_XDEBUG')) {
16 define('DAEMON_EXTENDED_DEBUG', true);
19 define('PURGE_INTERVAL', 3600); // seconds
21 require_once "sanity_check.php";
22 require_once "config.php";
24 if (!defined('PHP_EXECUTABLE')) {
25 define('PHP_EXECUTABLE', '/usr/bin/php');
28 if (!ENABLE_UPDATE_DAEMON
) {
29 die("Please enable option ENABLE_UPDATE_DAEMON in config.php\n");
32 require_once "db.php";
33 require_once "db-prefs.php";
34 require_once "functions.php";
36 error_reporting(DEFAULT_ERROR_LEVEL
);
38 function sigint_handler() {
39 unlink(LOCK_DIRECTORY
. "/update_daemon.lock");
40 die("Received SIGINT. Exiting.\n");
43 function sigalrm_handler() {
44 die("received SIGALRM, hang in feed update?\n");
47 if (function_exists('pcntl_signal')) {
48 pcntl_signal(SIGINT
, sigint_handler
);
49 pcntl_signal(SIGALRM
, sigalrm_handler
);
51 _debug("Warning: pcntl_signal function not present, continuing without support for signals.");
54 $lock_handle = make_lockfile("update_daemon.lock");
57 die("error: Can't create lockfile ($lock_filename). ".
58 "Maybe another daemon is already running.\n");
61 // Testing database connection.
62 // It is unnecessary to start the fork loop if database is not ok.
63 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
66 if (DB_TYPE
== "mysql") {
69 // PG seems to display its own errors just fine by default.
79 passthru(PHP_EXECUTABLE
. " update_daemon_loop.php SRV_RUN_OK");
81 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
83 sleep(DAEMON_SLEEP_INTERVAL
);