Improve status display
This commit is contained in:
parent
85b39fba5c
commit
21068e902a
30
firestarter
30
firestarter
@ -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,12 +270,19 @@ 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
|
||||
# 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"
|
||||
@ -287,11 +295,25 @@ fsstatus() {
|
||||
# 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
|
||||
# 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
|
||||
fi
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user