From patchwork Wed Oct 31 16:35:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [2/2] nodewatcher: Prevent multiple instances at the same time From: Adrian Schmutzler X-Patchwork-Id: 946 Message-Id: <20181031163539.6518-1-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Wed, 31 Oct 2018 17:35:39 +0100 This is based on the configurehood-Patch from Tim Niemeyer. Signed-off-by: Adrian Schmutzler Reviewed-by: Robert Langhammer Reviewed-by: Fabian Bläse --- src/packages/fff/fff-nodewatcher/Makefile | 2 +- src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/packages/fff/fff-nodewatcher/Makefile b/src/packages/fff/fff-nodewatcher/Makefile index 12ccb0f6..7f989fdb 100644 --- a/src/packages/fff/fff-nodewatcher/Makefile +++ b/src/packages/fff/fff-nodewatcher/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=fff-nodewatcher -PKG_VERSION:=48 +PKG_VERSION:=49 PKG_RELEASE:=1 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) diff --git a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher index c0ae57b8..b0b67e1a 100755 --- a/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher +++ b/src/packages/fff/fff-nodewatcher/files/usr/sbin/nodewatcher @@ -2,10 +2,18 @@ # Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg # License; GPL v3 -SCRIPT_VERSION="48" - test -f /tmp/started || exit +# Allow only one instance +lockfile="/var/lock/${0##*/}.lock" +if ! lock -n "$lockfile"; then + echo "Only one instance of $0 allowed." + exit 1 +fi +trap "lock -u \"$lockfile\"" INT TERM EXIT + +SCRIPT_VERSION="49" + #Get the configuration from the uci configuration file #If it does not exists, then get it from a normal bash file with variables. if [ -f /etc/config/nodewatcher ];then