From 1472307e28c938e2b8a62456a59874b5fb664e9a Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl Date: Mon, 7 Jun 2021 14:59:45 +0200 Subject: [PATCH 1/4] Check if service exists before stopping it --- src/Misc/layoutbin/systemd.svc.sh.template | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Misc/layoutbin/systemd.svc.sh.template b/src/Misc/layoutbin/systemd.svc.sh.template index df4fa515372..03a0d7e4317 100644 --- a/src/Misc/layoutbin/systemd.svc.sh.template +++ b/src/Misc/layoutbin/systemd.svc.sh.template @@ -106,15 +106,28 @@ function stop() function uninstall() { - stop - systemctl disable ${SVC_NAME} || failed "failed to disable ${SVC_NAME}" - rm "${UNIT_PATH}" || failed "failed to delete ${UNIT_PATH}" + if service_exists; then + stop + systemctl disable ${SVC_NAME} || failed "failed to disable ${SVC_NAME}" + rm "${UNIT_PATH}" || failed "failed to delete ${UNIT_PATH}" + else + echo "Service ${SVC_NAME} is not installed" + fi if [ -f "${CONFIG_PATH}" ]; then - rm "${CONFIG_PATH}" || failed "failed to delete ${CONFIG_PATH}" + rm "${CONFIG_PATH}" || failed "failed to delete ${CONFIG_PATH}" fi systemctl daemon-reload || failed "failed to reload daemons" } +function service_exists() { + if systemctl status "${SVC_NAME}" 2> /dev/null | grep -Fq "Active:"; then + return 0 + else + return 1 + fi +} + + function status() { if [ -f "${UNIT_PATH}" ]; then From 619056ae03b963e9d1d72038dca5431e54a95032 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl Date: Mon, 7 Jun 2021 15:07:58 +0200 Subject: [PATCH 2/4] Remove empty line (formatting) --- src/Misc/layoutbin/systemd.svc.sh.template | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Misc/layoutbin/systemd.svc.sh.template b/src/Misc/layoutbin/systemd.svc.sh.template index 03a0d7e4317..3627c3d024f 100644 --- a/src/Misc/layoutbin/systemd.svc.sh.template +++ b/src/Misc/layoutbin/systemd.svc.sh.template @@ -127,7 +127,6 @@ function service_exists() { fi } - function status() { if [ -f "${UNIT_PATH}" ]; then From 1790a8ae45b61094d102c32b79dc095db9fa9a16 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl Date: Mon, 7 Jun 2021 15:56:08 +0200 Subject: [PATCH 3/4] Use the same way as status to check service --- src/Misc/layoutbin/systemd.svc.sh.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Misc/layoutbin/systemd.svc.sh.template b/src/Misc/layoutbin/systemd.svc.sh.template index 3627c3d024f..76afabe8dc9 100644 --- a/src/Misc/layoutbin/systemd.svc.sh.template +++ b/src/Misc/layoutbin/systemd.svc.sh.template @@ -120,7 +120,7 @@ function uninstall() } function service_exists() { - if systemctl status "${SVC_NAME}" 2> /dev/null | grep -Fq "Active:"; then + if [ -f "${UNIT_PATH}" ]; then return 0 else return 1 @@ -129,7 +129,7 @@ function service_exists() { function status() { - if [ -f "${UNIT_PATH}" ]; then + if service_exists; then echo echo "${UNIT_PATH}" else From 846a1126b4dbbf8457f56a0ecb3f0b5708544493 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl Date: Mon, 7 Jun 2021 16:51:13 +0200 Subject: [PATCH 4/4] Revert formatting change --- src/Misc/layoutbin/systemd.svc.sh.template | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Misc/layoutbin/systemd.svc.sh.template b/src/Misc/layoutbin/systemd.svc.sh.template index 76afabe8dc9..4361a1a1e9d 100644 --- a/src/Misc/layoutbin/systemd.svc.sh.template +++ b/src/Misc/layoutbin/systemd.svc.sh.template @@ -114,7 +114,7 @@ function uninstall() echo "Service ${SVC_NAME} is not installed" fi if [ -f "${CONFIG_PATH}" ]; then - rm "${CONFIG_PATH}" || failed "failed to delete ${CONFIG_PATH}" + rm "${CONFIG_PATH}" || failed "failed to delete ${CONFIG_PATH}" fi systemctl daemon-reload || failed "failed to reload daemons" }