]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - service
Create bondX interfaces when ifcfg-bondX is called with ifup and interface doesn...
[projects/rc-scripts.git] / service
diff --git a/service b/service
index 470e72eb9a91c75f30ff24ae2e53a905bee6c4df..f882bdb2888fd1d2535ce383b87c03716f4c6ec6 100755 (executable)
--- a/service
+++ b/service
@@ -23,6 +23,14 @@ is_systemd_service() {
 
        [ "$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 | \
@@ -64,7 +72,14 @@ is_systemd_service() {
 }
 
 status_all() {
-       local SERVICE TYPE
+       local SERVICE TYPE has_systemd
+
+       if [ "$USE_SYSTEMD" != "no" ] && [ -x /bin/systemd_booted ] && /bin/systemd_booted; then
+               has_systemd=1
+       else
+               unset has_systemd
+       fi
+
        cd ${SERVICEDIR}
        for SERVICE in *; do
                case "${SERVICE}" in
@@ -73,30 +88,26 @@ status_all() {
                *)
                if ! is_ignored_file "${SERVICE}" \
                                && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-                       if [ -f /etc/init/${SERVICE}.conf ]; then
-                               # U for upstart
-                               TYPE='U'
+                       if [ "$has_systemd" ] && [ -f /lib/systemd/system/${SERVICE}.service ]; then
+                               # D for SystemD
+                               TYPE='D'
                        else
                                # S for SysVinit
                                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)
+                               out=$(env -i 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
@@ -108,7 +119,6 @@ USAGE="Usage: $(basename $0) < option > | --status-all | \
 [ service_name [ command | --full-restart ] ]"
 
 SERVICE=
-USE_UPSTART=
 USE_SYSTEMD=
 
 if [ -d /etc/rc.d/init.d ]; then
@@ -141,14 +151,6 @@ while [ $# -gt 0 ]; do
                export SYSTEMCTL_SKIP_REDIRECT=1
                shift
                ;;
-       --upstart)
-               USE_UPSTART=yes
-               shift
-               ;;
-       --no-upstart)
-               USE_UPSTART=no
-               shift
-               ;;
        --no-systemd)
                USE_SYSTEMD=no
                shift
@@ -160,8 +162,8 @@ while [ $# -gt 0 ]; do
                elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
                        SERVICE="${1}"
                        if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-                               env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
-                               env -i USE_UPSTART=$USE_UPSTART LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
+                               env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
+                               env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
                                exit $?
                        fi
                elif [ -z "${SERVICE}" ]; then
@@ -177,10 +179,10 @@ while [ $# -gt 0 ]; do
 done
 
 if is_systemd_service "${SERVICE}" "${ACTION}"; then
-       echo >&2 "Redirecting to /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}"
-       exec /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}
+       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}
+       exec env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${ACTION} ${OPTIONS}
 else
        echo "${SERVICE}: unrecognized service" >&2
        exit 1
This page took 0.106623 seconds and 4 git commands to generate.