diff --git a/service/service b/service/service index 2e5b421..d422571 100644 --- a/service/service +++ b/service/service @@ -8,7 +8,10 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin export PATH VERSION="service version 0.91-alt" -SERVICEDIR="/etc/init.d" +SERVICEDIR=/etc/init.d +SYSTEMCTL=/bin/systemctl +SYSTEMD_SERVICE_DIR=/lib/systemd/system +SYSTEMD_CGROUP_DIR=/sys/fs/cgroup/systemd SERVICE= OPTIONS= @@ -30,13 +33,30 @@ usage() [ -n "$1" ] && exit "$1" || exit } +systemd_status= +systemd_is_active() +{ + if [ -z "$systemd_status" ]; then + [ -x "$SYSTEMCTL" -a \ + -d "$SYSTEMD_CGROUP_DIR" ] && + mountpoint -q "$SYSTEMD_CGROUP_DIR" + systemd_status=$? + fi + return $systemd_status +} + check_service() { [ -n "${SERVICE##*/*}" ] || fatal "$SERVICE: Invalid service name" - [ -x "$SERVICEDIR/$SERVICE" ] || - fatal "$SERVICE: Unrecognized service" + [ -x "$SERVICEDIR/$SERVICE" ] && return 0 + + [ -f "$SYSTEMD_SERVICE_DIR/$SERVICE.service" ] && + systemd_is_active && + return 0 + + fatal "$SERVICE: Unrecognized service" } if [ $# -eq 0 ]; then @@ -69,7 +89,11 @@ case "$1" in shift check_service cd / || exit - "$SERVICEDIR/$SERVICE" "$@" - exit $? + if systemd_is_active; then + exec "$SYSTEMCTL" "$@" "$SERVICE.service" + else + exec "$SERVICEDIR/$SERVICE" "$@" + fi + exit ;; esac