[projects/rc-scripts] service: --status-all: recognize systemd, more verbose output

glen glen at pld-linux.org
Sat Mar 1 23:09:19 CET 2014


commit ab907cc4046ea1cf43c41ea2d134974c1859a3da
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sun Mar 2 00:06:04 2014 +0200

    service: --status-all: recognize systemd, more verbose output

 service | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/service b/service
index 3374657..2d5a3e5 100755
--- 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
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/rc-scripts.git/commitdiff/ab907cc4046ea1cf43c41ea2d134974c1859a3da



More information about the pld-cvs-commit mailing list