]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - service
Allow overriding of vlan base device name
[projects/rc-scripts.git] / service
diff --git a/service b/service
index cf7b1bc73b07f2be7287a6caddea6bbe24f87502..2d5a3e555e42674e6bb9401eb39f0ffbdb2365d0 100755 (executable)
--- a/service
+++ b/service
@@ -16,12 +16,55 @@ is_ignored_file() {
        return 1
 }
 
-# check if SERVICE is present in systemd
+# 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
+       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
 
@@ -29,7 +72,20 @@ is_systemd_service() {
 }
 
 status_all() {
-       local SERVICE TYPE
+       local SERVICE TYPE has_systemd has_upstart
+
+       if [ "$USE_SYSTEMD" != "no" ] && [ -x /bin/systemd_booted ] && /bin/systemd_booted; then
+               has_systemd=1
+       else
+               unset has_systemd
+       fi
+
+       if [ "$USE_UPSTART" != "no" ] && [ -x /sbin/initctl ]; then
+               has_upstart=1
+       else
+               unset has_upstart
+       fi
+
        cd ${SERVICEDIR}
        for SERVICE in *; do
                case "${SERVICE}" in
@@ -38,7 +94,10 @@ status_all() {
                *)
                if ! is_ignored_file "${SERVICE}" \
                                && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-                       if [ -f /etc/init/${SERVICE}.conf ]; then
+                       if [ "$has_systemd" ] && [ -f /lib/systemd/system/${SERVICE}.service ]; then
+                               # D for SystemD
+                               TYPE='D'
+                       elif [ "$has_upstart" ] && [ -f /etc/init/${SERVICE}.conf ]; then
                                # U for upstart
                                TYPE='U'
                        else
@@ -46,22 +105,18 @@ status_all() {
                                TYPE='S'
                        fi
                        if ! grep -qs "\Wstatus)" "$SERVICE"; then
-                               #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
-                               echo " [ ? ]{$TYPE} $SERVICE"
+                               printf " %s %-60s %s\n" "$TYPE:[?]" "$SERVICE:" "unknown"
                                continue
                        else
                                out=$(env -i USE_UPSTART=$USE_UPSTART LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
                                if [ "$?" = "0" -a -n "$out" ]; then
-                                       #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
-                                       echo " [ + ]{$TYPE} $SERVICE"
+                                       printf " %s %-60s %s\n" "$TYPE:[+]" "$SERVICE:" "running"
                                        continue
                                else
-                                       #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
-                                       echo " [ - ]{$TYPE} $SERVICE"
+                                       printf " %s %-60s %s %s\n" "$TYPE:[-]" "$SERVICE:" "NOT running"
                                        continue
                                fi
                        fi
-                       #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
                fi
                ;;
                esac
@@ -141,9 +196,9 @@ while [ $# -gt 0 ]; do
        esac
 done
 
-if is_systemd_service "${SERVICE}"; then
-       echo >&2 "Redirecting to /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}"
-       exec /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}
+if is_systemd_service "${SERVICE}" "${ACTION}"; then
+       echo >&2 "Redirecting to /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}"
+       exec /bin/systemctl --output=cat ${ACTION} ${SERVICE}.service ${OPTIONS}
 elif [ -x "${SERVICEDIR}/${SERVICE}" ]; then
        exec env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
 else
This page took 0.071299 seconds and 4 git commands to generate.