Improve status display

This commit is contained in:
Salt 2020-10-07 18:37:20 -05:00
parent 85b39fba5c
commit 21068e902a

View File

@ -137,6 +137,7 @@ fsstop() {
[ "$pid" -gt 0 ] 2> /dev/null || error "PID is invalid for service: $service (PID $pid)" 51 [ "$pid" -gt 0 ] 2> /dev/null || error "PID is invalid for service: $service (PID $pid)" 51
[ -d "/proc/$pid" ] || warn "Service is already dead: $service" [ -d "/proc/$pid" ] || warn "Service is already dead: $service"
[ -d "/proc/$pid" ] && fskill "$pid" [ -d "/proc/$pid" ] && fskill "$pid"
rm "$pidfile"
return 0 return 0
done done
} }
@ -269,28 +270,49 @@ fsstatus() {
fi fi
# Service information # Service information
if [ -d "$_optrundir" ]; then if [ -d "$_optrundir" ]; then
for pidfile in "$_optrundir"/*.pid; do local len=16
local name="$(basename -- "$pidfile" .pid)" local status
local pid="$(< "$pidfile")" local description
local len=16 # TODO: This does not handle services that are running but had their configs removed
local status for file in $(echo "$_optconfigdir"/*); do
local description [ -d "$file" ] && continue
if [ -z "$pid" ]; then local name="$(basename -- "$file" .pid)"
# PID is empty local service="$_optconfigdir/$name"
status="\e[31m○\e[0m" local pidfile="$_optrundir/$name.pid"
description="No PID" local pid=""
elif ! [ "$pid" -gt 0 ] 2> /dev/null; then if [ -f "$pidfile" ]; then
# PID is not a number greater than 0 # Service has a pidfile and SHOULD be running
status="\e[31m○\e[0m" local pid="$(< "$pidfile")"
description="\e[31mInvalid PID\e[0m ($pid)" if [ -z "$pid" ]; then
elif ! [ -d "/proc/$pid" ]; then # PID is empty
# PID is valid, but does not exist in /proc (i.e. is dead) status="\e[31m○\e[0m"
status="\e[31m●\e[0m" description="No PID"
description="\e[31mDead\e[0m (PID $pid)" elif ! [ "$pid" -gt 0 ] 2> /dev/null; then
# PID is not a number greater than 0
status="\e[31m○\e[0m"
description="\e[31mInvalid PID\e[0m ($pid)"
elif ! [ -d "/proc/$pid" ]; then
# PID is valid, but does not exist in /proc (i.e. is dead)
status="\e[31m●\e[0m"
description="\e[31mDead\e[0m (PID $pid)"
elif ! [ -x "$service" ]; then
# PID is good, but service is not enabled
status="\e[33m●\e[0m"
description="Running, disabled (PID $pid)"
else
# PID is good, time for secondary validation
status="\e[32m●\e[0m"
description="Running (PID $pid)"
fi
else else
# PID is good, time for secondary validation # Service does not have a pidfile and SHOULD be stopped
status="\e[32m●\e[0m" if [ -x "$service" ]; then
description="Running (PID $pid)" status="\e[35m●\e[0m"
description="Stopped"
elif ! [ -x "$service" ]; then
status="\e[35m○\e[0m"
description="Disabled"
fi
fi fi
printf "\t$status %-${len}.${len}s $description\n" "$name" printf "\t$status %-${len}.${len}s $description\n" "$name"
done done
@ -608,7 +630,7 @@ main() {
fi fi
# Validate core program dependencies # Validate core program dependencies
log "Validating dependencies" 2 log "Validating dependencies" 2
if ! has basename; then if ! has basename sort; then
error "Failed to find program: $_return" 1 error "Failed to find program: $_return" 1
fi fi
# Fixes random SIGALRM bug # Fixes random SIGALRM bug