+# check if SERVICE is present in systemd and ACTION is valid systemctl command
+# returns false if systemd is disabled or not active
+is_systemd_service() {
+ local SERVICE=$1 ACTION=$2
+
+ [ "$USE_SYSTEMD" = "no" ] && return 1
+
+ # if we are called from systemd itself, because some .service specified
+ # invocation via /sbin/service. this avoids loops
+ # detect this via CMDLINE var, which has leaked from geninitrd
+ if [ -n "$CMDLINE" ]; then
+ echo >&2 "Warning: CMDLINE env set, likely you are defining .service to use /sbin/service, please use /etc/rc.d/init.d/<SERVICE> instead"
+ return 1
+ fi
+
+ case "$ACTION" in
+ # list obtained as: man systemctl | grep N.*A.*M.*E
+ start | \
+ stop | \
+ reload | \
+ restart | \
+ try-restart | \
+ reload-or-restart | \
+ reload-or-try-restart | \
+ isolate | \
+ kill | \
+ is-active | \
+ status | \
+ show | \
+ reset-failed | \
+ enable | \
+ disable | \
+ is-enabled | \
+ reenable | \
+ preset | \
+ mask | \
+ unmask | \
+ link | \
+ load | \
+ snapshot | \
+ delete | \
+ set-environment | \
+ unset-environment )
+ ;;
+ *)
+ #echo "Not valid systemd command"
+ return 1
+ esac
+
+ [ -x /bin/systemd_booted ] || return 1
+ /bin/systemd_booted || return 1
+
+ /bin/systemctl show "$SERVICE".service | grep -q LoadError= && return 1 || return 0
+}
+