]> git.pld-linux.org Git - projects/rc-scripts.git/commitdiff
service: --status-all: recognize systemd, more verbose output
authorElan Ruusamäe <glen@delfi.ee>
Sat, 1 Mar 2014 22:06:04 +0000 (00:06 +0200)
committerElan Ruusamäe <glen@delfi.ee>
Sat, 1 Mar 2014 22:09:13 +0000 (00:09 +0200)
service

diff --git a/service b/service
index 337465709b829e450180dd84e83d44222c857f22..2d5a3e555e42674e6bb9401eb39f0ffbdb2365d0 100755 (executable)
--- a/service
+++ b/service
@@ -72,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
@@ -81,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
@@ -89,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
This page took 0.063055 seconds and 4 git commands to generate.