issue #9: adding check to prevent cronjob from running multiple times
parent
10f9d666d2
commit
17c7f3b3c3
|
@ -14,6 +14,7 @@
|
||||||
- Adding Portuguese / Brazilian language file (thanks to Luiz Alberto S. Ribeiro).
|
- Adding Portuguese / Brazilian language file (thanks to Luiz Alberto S. Ribeiro).
|
||||||
- Large status page by Michael Greenhill.
|
- Large status page by Michael Greenhill.
|
||||||
- New config file (see install instructions in README).
|
- New config file (see install instructions in README).
|
||||||
|
- Cronjob will be prevented from running multiple times at the same time (with a 10 mins timeout).
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
#
|
#
|
||||||
|
|
|
@ -125,6 +125,9 @@ If it is your own server or you have shell access and permission to open the cro
|
||||||
As you can see, this line will run the status.cron.php script every 15 minutes. Change the line to suit your needs.
|
As you can see, this line will run the status.cron.php script every 15 minutes. Change the line to suit your needs.
|
||||||
If you do not have shell access, ask your web hosting provider to set it up for you.
|
If you do not have shell access, ask your web hosting provider to set it up for you.
|
||||||
|
|
||||||
|
The update script has been designed to prevent itself from running multiple times. It has a maximum timeout of 10 minutes.
|
||||||
|
After that the script is assumed dead and the cronjob will run again.
|
||||||
|
|
||||||
|
|
||||||
## CUSTOMIZING
|
## CUSTOMIZING
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,15 @@
|
||||||
// include main configuration and functionality
|
// include main configuration and functionality
|
||||||
require_once dirname(__FILE__) . '/../src/bootstrap.php';
|
require_once dirname(__FILE__) . '/../src/bootstrap.php';
|
||||||
|
|
||||||
|
// prevent cron from running twice at the same time
|
||||||
|
// however if the cron has been running for 10 mins, we'll assume it died and run anyway
|
||||||
|
$time = time();
|
||||||
|
if(psm_get_conf('cron_running') == 1 && ($time - psm_get_conf('cron_running_time') < 600)) {
|
||||||
|
die('Cron is already running. Exiting.');
|
||||||
|
}
|
||||||
|
psm_update_conf('cron_running', 1);
|
||||||
|
psm_update_conf('cron_running_time', $time);
|
||||||
|
|
||||||
// get the active servers from database
|
// get the active servers from database
|
||||||
$servers = $db->select(
|
$servers = $db->select(
|
||||||
PSM_DB_PREFIX.'servers',
|
PSM_DB_PREFIX.'servers',
|
||||||
|
@ -70,4 +79,6 @@ foreach ($servers as $server) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
psm_update_conf('cron_running', 0);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -110,13 +110,17 @@ class Queries {
|
||||||
('version', '{$version}'),
|
('version', '{$version}'),
|
||||||
('auto_refresh_servers', '0'),
|
('auto_refresh_servers', '0'),
|
||||||
('show_update', '1'),
|
('show_update', '1'),
|
||||||
('last_update_check', '0');";
|
('last_update_check', '0'),
|
||||||
|
('cron_running', '0'),
|
||||||
|
('cron_running_time', '0');";
|
||||||
} else {
|
} else {
|
||||||
if(version_compare($version_from, '2.1.0', '<')) {
|
if(version_compare($version_from, '2.1.0', '<')) {
|
||||||
// 2.0 upgrade
|
// 2.0 upgrade
|
||||||
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP `config_id`;";
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP `config_id`;";
|
||||||
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` ADD PRIMARY KEY ( `key` );";
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` ADD PRIMARY KEY ( `key` );";
|
||||||
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP INDEX `key`;";
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "config` DROP INDEX `key`;";
|
||||||
|
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('cron_running', '0');";
|
||||||
|
$queries[] = "INSERT INTO `" . PSM_DB_PREFIX . "config` (`key`, `value`) VALUES ('cron_running_time', '0');";
|
||||||
|
|
||||||
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `error` `error` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL;";
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `error` `error` VARCHAR( 255 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL;";
|
||||||
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `rtime` `rtime` FLOAT( 9, 7 ) NULL;";
|
$queries[] = "ALTER TABLE `" . PSM_DB_PREFIX . "servers` CHANGE `rtime` `rtime` FLOAT( 9, 7 ) NULL;";
|
||||||
|
|
Loading…
Reference in New Issue