Skip to content

Commit

Permalink
Check if service exists before stopping it (Linux) (actions#1135)
Browse files Browse the repository at this point in the history
* Check if service exists before stopping it

* Remove empty line (formatting)

* Use the same way as status to check service

* Revert formatting change
  • Loading branch information
fhammerl authored Jun 8, 2021
1 parent 31584f4 commit a1bcd59
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/Misc/layoutbin/systemd.svc.sh.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1bcd59

Please sign in to comment.