]> git.pld-linux.org Git - projects/rc-scripts.git/blobdiff - service
fix message printing; pass anything to systemd if it is up (status is valid action...
[projects/rc-scripts.git] / service
diff --git a/service b/service
index c29c382a442a375e2d947badac68757fd30b7f9b..3c3071caed0934069fd6f97c9932915a6801b90d 100755 (executable)
--- a/service
+++ b/service
@@ -16,11 +16,52 @@ is_ignored_file() {
        return 1
 }
 
+status_all() {
+       local SERVICE TYPE
+       cd ${SERVICEDIR}
+       for SERVICE in *; do
+               case "${SERVICE}" in
+               functions | halt | killall | single| linuxconf| kudzu)
+                       ;;
+               *)
+               if ! is_ignored_file "${SERVICE}" \
+                               && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+                       if [ -f /etc/init/${SERVICE}.conf ]; then
+                               # U for upstart
+                               TYPE='U'
+                       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"
+                               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"
+                                       continue
+                               else
+                                       #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
+                                       echo " [ - ]{$TYPE} $SERVICE"
+                                       continue
+                               fi
+                       fi
+                       #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
+               fi
+               ;;
+               esac
+       done
+}
+
 VERSION="$(basename $0) ver. 0.91-pld"
 USAGE="Usage: $(basename $0) < option > | --status-all | \
 [ service_name [ command | --full-restart ] ]"
 
 SERVICE=
+USE_UPSTART=
 
 if [ -d /etc/rc.d/init.d ]; then
        SERVICEDIR="/etc/rc.d/init.d"
@@ -36,55 +77,45 @@ fi
 cd /
 while [ $# -gt 0 ]; do
        case "${1}" in
-         --help | -h | --h* )
+       --help | -h | --h* )
                echo "${USAGE}" >&2
                exit 0
                ;;
-         --version | -V )
+       --version | -V )
                echo "${VERSION}" >&2
                exit 0
                ;;
+       --ignore-dependencies)
+               export SYSTEMCTL_IGNORE_DEPENDENCIES=1
+               shift
+               ;;
+       --skip-redirect)
+               export SYSTEMCTL_SKIP_REDIRECT=1
+               shift
+               ;;
+       --upstart)
+               USE_UPSTART=yes
+               shift
+               ;;
+       --no-upstart)
+               USE_UPSTART=no
+               shift
+               ;;
          *)
                if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
-                       cd ${SERVICEDIR}
-                       for SERVICE in *; do
-                               case "${SERVICE}" in
-                               functions | halt | killall | single| linuxconf| kudzu)
-                                       ;;
-                               *)
-                               if ! is_ignored_file "${SERVICE}" \
-                                               && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-                                       if ! grep -qs "\Wstatus)" "$SERVICE"; then
-                                               #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
-                                               echo " [ ? ]  $SERVICE" 1>&2
-                                               continue
-                                       else
-                                               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 " [ + ]  $SERVICE"
-                                                       continue
-                                               else
-                                                       #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
-                                                       echo " [ - ]  $SERVICE"
-                                                       continue
-                                               fi
-                                       fi
-                                       #env -i LANG="$LANG" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
-                               fi
-                               ;;
-                               esac
-                       done
+                       status_all
                        exit 0
                elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
                        SERVICE="${1}"
                        if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-                               env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" stop
-                               env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" start
+                               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
                                exit $?
                        fi
                elif [ -z "${SERVICE}" ]; then
                        SERVICE="${1}"
+               elif [ -z "${ACTION}" ]; then
+                       ACTION="${1}"
                else
                        OPTIONS="${OPTIONS} ${1}"
                fi
@@ -93,8 +124,11 @@ while [ $# -gt 0 ]; do
        esac
 done
 
-if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
-       env -i LANG=$LANG PATH=$PATH TERM=$TERM "${SERVICEDIR}/${SERVICE}" ${OPTIONS}
+if [ -x /bin/systemd_booted ] && /bin/systemd_booted; then
+       echo >&2 "Redirecting to /bin/systemctl ${ACTION} ${SERVICE}.service ${OPTIONS}"
+       exec /bin/systemctl ${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
        echo "${SERVICE}: unrecognized service" >&2
        exit 1
This page took 0.030916 seconds and 4 git commands to generate.