]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/php | |
2 | <?php | |
3 | define('DISABLE_SESSIONS', true); | |
4 | ||
5 | chdir(dirname(__FILE__)); | |
6 | ||
7 | require_once "functions.php"; | |
8 | require_once "sanity_check.php"; | |
9 | require_once "config.php"; | |
10 | require_once "db.php"; | |
11 | require_once "db-prefs.php"; | |
12 | ||
13 | if (!defined('PHP_EXECUTABLE')) | |
14 | define('PHP_EXECUTABLE', '/usr/bin/php'); | |
15 | ||
16 | $op = $argv[1]; | |
17 | ||
18 | if (!$op || $op == "-help") { | |
19 | print "Tiny Tiny RSS data update script.\n\n"; | |
20 | print "Options:\n"; | |
21 | print " -feeds - update feeds\n"; | |
22 | print " -feedbrowser - update feedbrowser\n"; | |
23 | print " -daemon - start single-process update daemon\n"; | |
24 | print " -cleanup-tags - perform tags table maintenance\n"; | |
25 | print " -get-feeds - receive popular feeds from linked instances\n"; | |
26 | print " -help - show this help\n"; | |
27 | return; | |
28 | } | |
29 | ||
30 | if ($op != "-daemon") { | |
31 | $lock_filename = "update.lock"; | |
32 | } else { | |
33 | $lock_filename = "update_daemon.lock"; | |
34 | } | |
35 | ||
36 | $lock_handle = make_lockfile($lock_filename); | |
37 | $must_exit = false; | |
38 | ||
39 | // Try to lock a file in order to avoid concurrent update. | |
40 | if (!$lock_handle) { | |
41 | die("error: Can't create lockfile ($lock_filename). ". | |
42 | "Maybe another update process is already running.\n"); | |
43 | } | |
44 | ||
45 | // Create a database connection. | |
46 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
47 | ||
48 | if (!$link) { | |
49 | if (DB_TYPE == "mysql") { | |
50 | print mysql_error(); | |
51 | } | |
52 | // PG seems to display its own errors just fine by default. | |
53 | return; | |
54 | } | |
55 | ||
56 | init_connection($link); | |
57 | ||
58 | if ($op == "-feeds") { | |
59 | // Update all feeds needing a update. | |
60 | update_daemon_common($link); | |
61 | ||
62 | // Update feedbrowser | |
63 | $count = update_feedbrowser_cache($link); | |
64 | _debug("Feedbrowser updated, $count feeds processed."); | |
65 | ||
66 | // Purge orphans and cleanup tags | |
67 | purge_orphans($link, true); | |
68 | ||
69 | $rc = cleanup_tags($link, 14, 50000); | |
70 | _debug("Cleaned $rc cached tags."); | |
71 | } | |
72 | ||
73 | if ($op == "-feedbrowser") { | |
74 | $count = update_feedbrowser_cache($link); | |
75 | print "Finished, $count feeds processed.\n"; | |
76 | } | |
77 | ||
78 | if ($op == "-daemon") { | |
79 | while (true) { | |
80 | passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop"); | |
81 | _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); | |
82 | sleep(DAEMON_SLEEP_INTERVAL); | |
83 | } | |
84 | } | |
85 | ||
86 | if ($op == "-daemon-loop") { | |
87 | if (!make_stampfile('update_daemon.stamp')) { | |
88 | die("error: unable to create stampfile\n"); | |
89 | } | |
90 | ||
91 | // Call to the feed batch update function | |
92 | // or regenerate feedbrowser cache | |
93 | ||
94 | if (rand(0,100) > 30) { | |
95 | update_daemon_common($link); | |
96 | } else { | |
97 | $count = update_feedbrowser_cache($link); | |
98 | _debug("Feedbrowser updated, $count feeds processed."); | |
99 | ||
100 | purge_orphans($link, true); | |
101 | ||
102 | $rc = cleanup_tags($link, 14, 50000); | |
103 | ||
104 | _debug("Cleaned $rc cached tags."); | |
105 | } | |
106 | ||
107 | } | |
108 | ||
109 | if ($op == "-cleanup-tags") { | |
110 | $rc = cleanup_tags($link, 14, 50000); | |
111 | print "$rc tags deleted.\n"; | |
112 | } | |
113 | ||
114 | if ($op == "-get-feeds") { | |
115 | get_linked_feeds($link); | |
116 | } | |
117 | ||
118 | db_close($link); | |
119 | ||
120 | unlink(LOCK_DIRECTORY . "/$lock_filename"); | |
121 | ?> |