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
[ -d "/proc/$pid" ] || warn "Service is already dead: $service"
[ -d "/proc/$pid" ] && fskill "$pid"
rm "$pidfile"
return 0
done
}
@ -269,28 +270,49 @@ fsstatus() {
fi
# Service information
if [ -d "$_optrundir" ]; then
for pidfile in "$_optrundir"/*.pid; do
local name="$(basename -- "$pidfile" .pid)"
local pid="$(< "$pidfile")"
local len=16
local status
local description
if [ -z "$pid" ]; then
# PID is empty
status="\e[31m○\e[0m"
description="No 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)"
local len=16
local status
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
# PID is empty
status="\e[31m○\e[0m"
description="No 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
# PID is good, time for secondary validation
status="\e[32m●\e[0m"
description="Running (PID $pid)"
# 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"
done
@ -608,7 +630,7 @@ main() {
fi
# Validate core program dependencies
log "Validating dependencies" 2
if ! has basename; then
if ! has basename sort; then
error "Failed to find program: $_return" 1
fi
# Fixes random SIGALRM bug