[LEDE-DEV] sysupgrade: run only one instance at a time.

Submitted by Kenneth Johansson on April 3, 2017, 1:21 p.m.

Details

Message ID efd9b0a8-41be-7cc4-ba70-3c574b210dd1@inteno.se
State New
Headers show

Commit Message

Kenneth Johansson April 3, 2017, 1:21 p.m.
Things do not work well if running multiple instances of
upgrade at the same time.

Signed-off-by: Kenneth Johansson <kenneth.johansson@inteno.se>
---
  package/base-files/files/sbin/sysupgrade | 14 ++++++++++++++
  1 file changed, 14 insertions(+)

Patch hide | download patch | download mbox

diff --git a/package/base-files/files/sbin/sysupgrade b/package/base-files/files/sbin/sysupgrade
index c095ca8..491928c 100755
--- a/package/base-files/files/sbin/sysupgrade
+++ b/package/base-files/files/sbin/sysupgrade
@@ -47,6 +47,20 @@  while [ -n "$1" ]; do
      shift;
  done
  
+# just one instance
+if  ! lock -n /tmp/sysupgrade.lock
+then
+    echo "Another instance of sysupgrade already running"
+    echo "If you are sure this is wrong remove file /tmp/sysupgrade.lock"
+    exit 1
+fi
+
+# make sure the lock is removed when done even when killed
+finish() {
+    lock -u /var/sysupgrade.lock
+}
+trap finish EXIT INT TERM
+
  export CONFFILES=/tmp/sysupgrade.conffiles
  export CONF_TAR=/tmp/sysupgrade.tgz