Skip to content
Snippets Groups Projects
Commit d1ab9814 authored by hahn's avatar hahn
Browse files

add locking for cronjob that fetches git revisions

parent 4e552b47
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
// http://iml:deployment@ci.iml.unibe.ch/deployment/?prj=ci&action=deploy&par3=preview&confirm=1 // http://iml:deployment@ci.iml.unibe.ch/deployment/?prj=ci&action=deploy&par3=preview&confirm=1
$iStart=date('U');
$sDocroot = (dirname(__dir__)) . "/public_html"; $sDocroot = (dirname(__dir__)) . "/public_html";
$processUser = posix_getpwuid(posix_geteuid()); $processUser = posix_getpwuid(posix_geteuid());
...@@ -15,6 +16,17 @@ if ($processUser['name']=="root"){ ...@@ -15,6 +16,17 @@ if ($processUser['name']=="root"){
die("Do not start the script as user root\n"); die("Do not start the script as user root\n");
}; };
echo "\n<h1>===== IMLDEPLOYMENT - cache git branches :: ".(date("Y-m-d H:i:s"))." =====</h1>\n\n";
$sLockfile="/tmp/cache-gitbranches.lock";
if (file_exists($sLockfile)){
$iAge=date('U')-filemtime($sLockfile);
$iMagAge=60*60 * 3;
if ($iAge < 60*60 * 3){
die("ABORT: lock file exists: $sLockfile (age: $iAge sec ... needs to wait up to $iMagAge sec or the running script is finished)\n");
}
echo "INFO: ignoring existing lock file $sLockfile (age: $iAge sec is older $iMagAge sec)\n";
}
require_once("$sDocroot/deployment/classes/logger.class.php"); require_once("$sDocroot/deployment/classes/logger.class.php");
global $oCLog; global $oCLog;
$oCLog = new logger(); $oCLog = new logger();
...@@ -25,7 +37,9 @@ require_once("$sDocroot/deployment/classes/project.class.php"); ...@@ -25,7 +37,9 @@ require_once("$sDocroot/deployment/classes/project.class.php");
$oPrj1 = new project(); $oPrj1 = new project();
echo "<h1>===== IMLDEPLOYMENT - cache git branches =====</h1>\n"; echo "creating lock file $sLockfile\n";
file_put_contents($sLockfile, "started ".date("Y-m-d H:i:s"));
foreach ($oPrj1->getProjects() as $sPrj) { foreach ($oPrj1->getProjects() as $sPrj) {
$oPrj = new project($sPrj); $oPrj = new project($sPrj);
...@@ -35,4 +49,9 @@ foreach ($oPrj1->getProjects() as $sPrj) { ...@@ -35,4 +49,9 @@ foreach ($oPrj1->getProjects() as $sPrj) {
} }
echo "<br>\n"; echo "<br>\n";
} }
echo "done\n"; echo "\n\n---------- done\n";
echo "removing lock file $sLockfile\n";
unlink($sLockfile);
echo "Script needed ".(date('U')-$iStart) . " s\n\n";
// echo $oCLog->renderCli();
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment