From 1acb4b1d3a702efc2cf7b80a238ac9187979a366 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 8 Sep 2016 02:29:46 +0200 Subject: [PATCH] autoupdater: add lockfile to prevent concurrent runs --- admin/autoupdater/files/usr/sbin/autoupdater | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/admin/autoupdater/files/usr/sbin/autoupdater b/admin/autoupdater/files/usr/sbin/autoupdater index 0bbc919..bb54ee5 100755 --- a/admin/autoupdater/files/usr/sbin/autoupdater +++ b/admin/autoupdater/files/usr/sbin/autoupdater @@ -309,6 +309,18 @@ local function autoupdate(mirror) end +local lockfile = '/var/lock/autoupdater.lock' +local lockfd = nixio.open(lockfile, 'w', 'rw-------') + +if not lockfd:lock('tlock') then + io.stderr:write(string.format( + "Unable to lock file %s. Make sure there is no other instance of the autoupdater running.\n", + lockfile, err + )) + os.exit(1) +end + + local mirrors = branch.mirror while #mirrors > 0 do