diff options
Diffstat (limited to 'recipes-connectivity/lora/lora-network-server-mtcap/lora-network-server.init')
-rwxr-xr-x | recipes-connectivity/lora/lora-network-server-mtcap/lora-network-server.init | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/recipes-connectivity/lora/lora-network-server-mtcap/lora-network-server.init b/recipes-connectivity/lora/lora-network-server-mtcap/lora-network-server.init index 86d731b..9357030 100755 --- a/recipes-connectivity/lora/lora-network-server-mtcap/lora-network-server.init +++ b/recipes-connectivity/lora/lora-network-server-mtcap/lora-network-server.init @@ -1,6 +1,7 @@ #!/bin/bash NAME="lora-network-server" +LOCK="/var/lock/$NAME" ENABLED="yes" START_STOP_DAEMON="/usr/sbin/start-stop-daemon" @@ -10,7 +11,6 @@ START_STOP_DAEMON="/usr/sbin/start-stop-daemon" run_dir=/var/run/lora conf_dir=/var/config/lora conf_file=/opt/lora/lora-network-server.conf -conf_db=$conf_dir/lora-network-server.db net_server=/opt/lora/lora-network-server net_server_log=/var/log/lora-network-server.log @@ -57,16 +57,33 @@ if [ "$ENABLED" != "yes" ]; then exit fi +force_stop() { + do_stop + rm -fr $LOCK +} + +function try_lock() { + if mkdir $LOCK; then + trap "rm -fr $LOCK" EXIT + else + echo "Lora Network Server lock not acquired, resource in use" + exit 1 + fi +} + + case "$1" in "start") + try_lock do_start ;; "stop") - do_stop + force_stop ;; "restart") ## Stop the service and regardless of whether it was ## running or not, start it again. + try_lock do_stop do_start ;; |