Files
server/opt/psa/admin/sbin/modules/watchdog/wdservice
2026-01-07 20:52:11 +01:00

60 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright 1999-2024. WebPros International GmbH. All rights reserved.
validate_service() {
local service="$1"
if [[ -n "$service" && "$service" != "monit" && "$service" != "wdcollect" ]]; then
echo "Refusing to act on unknown service $service" >&2
exit 2
fi
}
main() {
local action="${1:?"Command must be specified as the first parameter"}"
local service="$2"
if [[ "$action" != "reload-systemd" && -z "$service" ]]; then
echo "Service must be specified as the second parameter" >&2
exit 1
fi
case "$action" in
start)
validate_service "$service"
# Ubuntu 18.04 does not support `enable --now` for init.d services.
systemctl enable "${service}.service" && systemctl start "${service}.service"
exit $?
;;
stop)
validate_service "$service"
# Ubuntu 18.04 does not support `disable --now` for init.d services.
systemctl disable "${service}.service" && systemctl stop "${service}.service"
exit $?
;;
status)
if systemctl is-active -q "${service}.service"; then
echo "is active"
else
echo "is inactive"
fi
;;
enabled)
if systemctl is-enabled -q "${service}.service"; then
echo "is enabled"
else
echo "is disabled"
fi
;;
reload-systemd)
systemctl daemon-reload
;;
*)
echo "Unknown command: ${action}" >&2
echo "Usage: $0 <monit|wdcollect> <start|stop|status>" >&2
exit 1
;;
esac
}
main "$@"