From 8b694432aaa229823674eb4933eded3f2ab1517a Mon Sep 17 00:00:00 2001 From: Anthony Bourguignon Date: Tue, 20 Feb 2024 19:46:44 +0100 Subject: [PATCH] fix: Check if Zigbee2MQTT is running in `update.sh` (#21494) --- update.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/update.sh b/update.sh index c91db91b..38fbd695 100755 --- a/update.sh +++ b/update.sh @@ -1,18 +1,24 @@ #!/bin/bash -e cd "$(dirname "$0")" +NEED_RESTART=0 + if [ -d data-backup ]; then - echo "ERROR: Backup directory exists. May be previous restoring was failed?" - echo "1. Save 'data-backup' and 'data' dirs to safe location to make possibility to restore config later." - echo "2. Manually delete 'data-backup' dir and try again." - exit 1 + echo "ERROR: Backup directory exists. May be previous restoring was failed?" + echo "1. Save 'data-backup' and 'data' dirs to safe location to make possibility to restore config later." + echo "2. Manually delete 'data-backup' dir and try again." + exit 1 fi if which systemctl 2> /dev/null > /dev/null; then - echo "Stopping Zigbee2MQTT..." - sudo systemctl stop zigbee2mqtt + echo "Checking Zigbee2MQTT status..." + if systemctl is-active --quiet zigbee2mqtt; then + echo "Stopping Zigbee2MQTT..." + sudo systemctl stop zigbee2mqtt + NEED_RESTART=1 + fi else - echo "Skipped stopping Zigbee2MQTT, no systemctl found" + echo "Skipped stopping Zigbee2MQTT, no systemctl found" fi echo "Creating backup of configuration..." @@ -34,11 +40,9 @@ echo "Restore configuration..." cp -R data-backup/* data rm -rf data-backup -if which systemctl 2> /dev/null > /dev/null; then - echo "Starting Zigbee2MQTT..." - sudo systemctl start zigbee2mqtt -else - echo "Skipped starting Zigbee2MQTT, no systemctl found" +if [ $NEED_RESTART -eq 1 ]; then + echo "Starting Zigbee2MQTT..." + sudo systemctl start zigbee2mqtt fi echo "Done!"