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,12 +270,19 @@ fsstatus() {
fi fi
# Service information # Service information
if [ -d "$_optrundir" ]; then if [ -d "$_optrundir" ]; then
for pidfile in "$_optrundir"/*.pid; do
local name="$(basename -- "$pidfile" .pid)"
local pid="$(< "$pidfile")"
local len=16 local len=16
local status local status
local description local description
# TODO: This does not handle services that are running but had their configs removed
for file in $(echo "$_optconfigdir"/*); do
[ -d "$file" ] && continue
local name="$(basename -- "$file" .pid)"
local service="$_optconfigdir/$name"
local pidfile="$_optrundir/$name.pid"
local pid=""
if [ -f "$pidfile" ]; then
# Service has a pidfile and SHOULD be running
local pid="$(< "$pidfile")"
if [ -z "$pid" ]; then if [ -z "$pid" ]; then
# PID is empty # PID is empty
status="\e[31m○\e[0m" status="\e[31m○\e[0m"
@ -287,11 +295,25 @@ fsstatus() {
# PID is valid, but does not exist in /proc (i.e. is dead) # PID is valid, but does not exist in /proc (i.e. is dead)
status="\e[31m●\e[0m" status="\e[31m●\e[0m"
description="\e[31mDead\e[0m (PID $pid)" 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 else
# PID is good, time for secondary validation # PID is good, time for secondary validation
status="\e[32m●\e[0m" status="\e[32m●\e[0m"
description="Running (PID $pid)" description="Running (PID $pid)"
fi fi
else
# Service does not have a pidfile and SHOULD be stopped
if [ -x "$service" ]; then
status="\e[35m●\e[0m"
description="Stopped"
elif ! [ -x "$service" ]; then
status="\e[35m○\e[0m"
description="Disabled"
fi
fi
printf "\t$status %-${len}.${len}s $description\n" "$name" printf "\t$status %-${len}.${len}s $description\n" "$name"
done done
fi fi
@ -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