3 * FusionForge cron job utilities
5 * Copyright 2003, GForge, LLC
6 * Copyright 2009, Roland Mas
7 * Copyright (C) 2011 Alain Peyrat - Alcatel-Lucent
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 // This key id# is important - do not change or renumber
29 $cron_arr[0]='unused';
30 $cron_arr[1]='calculate_user_metric.php';
31 $cron_arr[2]='check_stale_tracker_items.php';
32 $cron_arr[3]='db_project_sums.php';
33 $cron_arr[4]='db_stats_agg.php';
34 $cron_arr[5]='db_trove_maint.php';
35 $cron_arr[6]='massmail.php';
36 $cron_arr[7]='project_cleanup.php';
37 $cron_arr[8]='project_weekly_metric.php';
38 $cron_arr[9]='rating_stats.php';
39 $cron_arr[10]='rotate_activity.php';
40 $cron_arr[11]='site_stats.php';
41 $cron_arr[12]='vacuum.php';
42 $cron_arr[13]='cvs.php';
43 $cron_arr[14]='history_parse.php';
44 $cron_arr[15]='ssh_create.php';
45 $cron_arr[16]='usergroup.php';
46 $cron_arr[17]='mailaliases.php';
47 $cron_arr[18]='mailing_lists_create.php';
48 $cron_arr[19]='tarballs.php';
49 $cron_arr[20]='reporting_cron.php';
50 $cron_arr[21]='create_svn.php';
51 $cron_arr[22]='daily_task_email.php';
52 $cron_arr[23]='backup_site.php';
53 $cron_arr[24]='svn-stats.php';
54 $cron_arr[25]='homedirs.php';
55 $cron_arr[26]='update_users.php';
56 $cron_arr[27]='create_scm_repos.php';
57 $cron_arr[28]='gather_scm_stats.php';
58 $cron_arr[29]='weekly.php';
60 $cron_arr[901]='create_groups.php';
61 $cron_arr[902]='mailing_lists_index.php';
62 $cron_arr[903]='job-server.pl';
64 function cron_entry($job,$output) {
65 $sql='INSERT INTO cron_history (rundate,job,output)
66 values ($1, $2, $3)' ;
67 return db_query_params ($sql,
68 array (time(), $job, $output));
71 function cron_debug($string) {
78 function checkChroot() {
80 if(forge_get_config('chroot') != '' && is_dir(forge_get_config('chroot'))) {
87 // Create lock via semaphore so long running jobs don't overlap
90 // $name - Name of cron job to use in the lock file name
92 function cron_create_lock($name) {
93 if (function_exists('sem_get')) {
94 global $cron_utils_sem ;
95 if (! $cron_utils_sem[$name]) {
96 $token = ftok ($name, 'g');
97 $cron_utils_sem[$name] = sem_get ($token, 1, 0600, 0) ;
99 return sem_acquire ($cron_utils_sem[$name]);
102 $name = basename($name);
103 if (!preg_match('/^[[:alnum:]\.\-_]+$/', $name)) {
106 $lockf = '/tmp/blahlock'.$name;
108 if (file_exists($lockf)) {
111 $fp = fopen($lockf,'w');
121 // Delete lock created by cron_create_lock
124 // $name - Name of cron job to use in the lock file name
126 function cron_remove_lock($name) {
127 if (function_exists('sem_get')) {
128 global $cron_utils_sem ;
129 if (! $cron_utils_sem[$name]) {
130 $token = ftok ($name, 'g');
131 $cron_utils_sem[$name] = sem_get ($token, 1, 0600, 0) ;
133 return sem_release ($cron_utils_sem[$name]);
136 $name = basename($name);
137 $lockf = '/tmp/blahlock'.$name;
139 if (file_exists($lockf) && is_writeable($lockf)) {
140 if (unlink($lockf)) {
149 // c-file-style: "bsd"