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
This commit is contained in:
Ferenc Hammerl
2021-06-08 13:27:19 +02:00
committed by GitHub
parent 31584f4451
commit a1bcd5996b

View File

@@ -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