From a1bcd5996bbbc5e0f32add3b7b648cc9ddc67222 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl <31069338+fhammerl@users.noreply.github.com> Date: Tue, 8 Jun 2021 13:27:19 +0200 Subject: [PATCH] Check if service exists before stopping it (Linux) (#1135) * Check if service exists before stopping it * Remove empty line (formatting) * Use the same way as status to check service * Revert formatting change --- src/Misc/layoutbin/systemd.svc.sh.template | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Misc/layoutbin/systemd.svc.sh.template b/src/Misc/layoutbin/systemd.svc.sh.template index df4fa515372..4361a1a1e9d 100644 --- a/src/Misc/layoutbin/systemd.svc.sh.template +++ b/src/Misc/layoutbin/systemd.svc.sh.template @@ -106,18 +106,30 @@ 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}" fi systemctl daemon-reload || failed "failed to reload daemons" } +function service_exists() { + if [ -f "${UNIT_PATH}" ]; then + return 0 + else + return 1 + fi +} + function status() { - if [ -f "${UNIT_PATH}" ]; then + if service_exists; then echo echo "${UNIT_PATH}" else