[Fusionforge-commits] FusionForge branch Branch_5_3 updated. b086128b251629c287d01e89126b234baa8d084d

Sylvain Beucler beuc-inria at fusionforge.org
Fri Apr 4 17:33:33 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, Branch_5_3 has been updated
       via  b086128b251629c287d01e89126b234baa8d084d (commit)
      from  4e9c5dfb9046e8960d8b39ca8fc0a2305702021a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit b086128b251629c287d01e89126b234baa8d084d
Author: Sylvain Beucler <sylvain.beucler at inria.fr>
Date:   Fri Apr 4 17:33:19 2014 +0200

    forge_run_job, forge_run_plugin_job: locking: don't run the cron if the previous call didn't finish

diff --git a/src/utils/forge_run_job b/src/utils/forge_run_job
index 443344d..a96970f 100755
--- a/src/utils/forge_run_job
+++ b/src/utils/forge_run_job
@@ -4,6 +4,8 @@
  * FusionForge
  *
  * Copyright 2012, Roland Mas
+ * Copyright (C) 2006  Sylvain Beucler
+ * Copyright (C) 2014  Inria (Sylvain Beucler)
  *
  * This file is part of FusionForge. FusionForge is free software;
  * you can redistribute it and/or modify it under the terms of the
@@ -24,6 +26,20 @@
 require (dirname(__FILE__).'/../common/include/env.inc.php');
 require_once $gfcommon.'include/pre.php';
 
+// Locking: for a single script
+// flock() locks are automatically lost on program termination, however
+// that happened (clean, segfault...)
+$lock = null;  // global, or auto-closed by PHP and we lose the lock!
+function AcquireReplicationLock($script) {
+  // Script lock: http://perl.plover.com/yak/flock/samples/slide006.html
+  global $argv, $lock;
+  $lock = fopen($script, 'r') or die("Failed to ask lock.\n");
+
+  if (!flock($lock, LOCK_EX | LOCK_NB)) {
+    die("There's a lock for '$script', exiting\n");
+  }
+}
+
 if (count ($argv) < 2) {
 	echo "Usage: .../forge_run_job <jobname> [ <parameter> ... ]
 " ;
@@ -41,6 +57,8 @@ if (! is_executable($script)) {
 	// exit (1) ;
 }
 
+AcquireReplicationLock($script);
+
 $cmdline = $script;
 while ($arg = array_shift($argv)) {
 	$cmdline .= ' '.escapeshellarg($arg);
diff --git a/src/utils/forge_run_plugin_job b/src/utils/forge_run_plugin_job
index 0ae55e9..7fe970b 100755
--- a/src/utils/forge_run_plugin_job
+++ b/src/utils/forge_run_plugin_job
@@ -4,6 +4,8 @@
  * FusionForge
  *
  * Copyright 2012, Roland Mas
+ * Copyright (C) 2006  Sylvain Beucler
+ * Copyright (C) 2014  Inria (Sylvain Beucler)
  *
  * This file is part of FusionForge. FusionForge is free software;
  * you can redistribute it and/or modify it under the terms of the
@@ -29,6 +31,20 @@
 require (dirname(__FILE__).'/../common/include/env.inc.php');
 require_once $gfcommon.'include/pre.php';
 
+// Locking: for a single script
+// flock() locks are automatically lost on program termination, however
+// that happened (clean, segfault...)
+$lock = null;  // global, or auto-closed by PHP and we lose the lock!
+function AcquireReplicationLock($script) {
+  // Script lock: http://perl.plover.com/yak/flock/samples/slide006.html
+  global $argv, $lock;
+  $lock = fopen($script, 'r') or die("Failed to ask lock.\n");
+
+  if (!flock($lock, LOCK_EX | LOCK_NB)) {
+    die("There's a lock for '$script', exiting\n");
+  }
+}
+
 if (count ($argv) < 3) {
 	echo "Usage: .../forge_run_plugin_job <plugin> <jobname> [ <parameter> ... ]
 " ;
@@ -51,6 +67,8 @@ if (! is_executable($script)) {
 	// exit (1) ;
 }
 
+AcquireReplicationLock($script);
+
 $cmdline = $script;
 while ($arg = array_shift($argv)) {
 	$cmdline .= ' '.escapeshellarg($arg);

-----------------------------------------------------------------------

Summary of changes:
 src/utils/forge_run_job        |   18 ++++++++++++++++++
 src/utils/forge_run_plugin_job |   18 ++++++++++++++++++
 2 files changed, 36 insertions(+)


hooks/post-receive
-- 
FusionForge



More information about the Fusionforge-commits mailing list