Skip to content

Commit

Permalink
Do not lock the cron anymore so we can have multiple workers
Browse files Browse the repository at this point in the history
  • Loading branch information
nickvergessen committed May 20, 2016
1 parent d0a2fa0 commit 92c21fd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 38 deletions.
11 changes: 0 additions & 11 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,17 +614,6 @@
*/
'cron_log' => true,

/**
* Location of the lock file for cron executions can be specified here.
* Default is within the tmp directory. The file is named in the following way:
* owncloud-server-$INSTANCEID-cron.lock
* where $INSTANCEID is the string specified in the ``instanceid`` field.
* Because the cron lock file is accessed at regular intervals, it may prevent
* enabled disk drives from spinning down. A different location for this file
* can solve such issues.
*/
'cron.lockfile.location' => '',

/**
* Enables log rotation and limits the total size of logfiles. The default is 0,
* or no rotation. Specify a size in bytes, for example 104857600 (100 megabytes
Expand Down
27 changes: 0 additions & 27 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,34 +100,11 @@
}
}

$instanceId = $config->getSystemValue('instanceid');
$lockFileName = 'owncloud-server-' . $instanceId . '-cron.lock';
$lockDirectory = $config->getSystemValue('cron.lockfile.location', sys_get_temp_dir());
$lockDirectory = rtrim($lockDirectory, '\\/');
$lockFile = $lockDirectory . '/' . $lockFileName;

if (!file_exists($lockFile)) {
touch($lockFile);
}

// We call ownCloud from the CLI (aka cron)
if ($appMode != 'cron') {
\OCP\BackgroundJob::setExecutionType('cron');
}

// open the file and try to lock it. If it is not locked, the background
// job can be executed, otherwise another instance is already running
$fp = fopen($lockFile, 'w');
$isLocked = flock($fp, LOCK_EX|LOCK_NB, $wouldBlock);

// check if backgroundjobs is still running. The wouldBlock check is
// needed on systems with advisory locking, see
// http://php.net/manual/en/function.flock.php#45464
if (!$isLocked || $wouldBlock) {
echo "Another instance of cron.php is still running!" . PHP_EOL;
exit(1);
}

// Work
$jobList = \OC::$server->getJobList();

Expand Down Expand Up @@ -155,10 +132,6 @@
}
}

// unlock the file
flock($fp, LOCK_UN);
fclose($fp);

} else {
// We call cron.php from some website
if ($appMode == 'cron') {
Expand Down

0 comments on commit 92c21fd

Please sign in to comment.