More service management functions
This commit is contained in:
parent
b5452b44c0
commit
ba11289f23
@ -38,11 +38,15 @@ If `firestarter` is invoked without any arguments, it will attempt to start a se
|
|||||||
|
|
||||||
* `list`, `ls`: List all configuration files and, if they are fsdefaults files, resolve them. Useful for debugging.
|
* `list`, `ls`: List all configuration files and, if they are fsdefaults files, resolve them. Useful for debugging.
|
||||||
|
|
||||||
|
* `logout`: Kill Firestarter, if it's running.
|
||||||
|
|
||||||
|
* `restart`: Stop a running service and start it back up again. Does not fail on dead services.
|
||||||
|
|
||||||
* `start`: Start a configuration file, redirecting output to the proper logs and dropping its PID in `/run` for existing Firestarter instances to use.
|
* `start`: Start a configuration file, redirecting output to the proper logs and dropping its PID in `/run` for existing Firestarter instances to use.
|
||||||
|
|
||||||
* `status`, `st`, `stat`: Prints information about the running Firestarter session, including PID, display, and the state of all services.
|
* `status`, `st`, `stat`: Prints information about the running Firestarter session, including PID, display, and the state of all services.
|
||||||
|
|
||||||
* `stop`: Kill Firestarter, if it's running.
|
* `stop`: Stop a running service
|
||||||
|
|
||||||
## Logging
|
## Logging
|
||||||
|
|
||||||
|
51
firestarter
51
firestarter
@ -23,6 +23,8 @@ declare -i _optverbose
|
|||||||
declare -a _args
|
declare -a _args
|
||||||
declare -i _hasdbus
|
declare -i _hasdbus
|
||||||
declare _return
|
declare _return
|
||||||
|
# Junk FD used for read waiting
|
||||||
|
exec 1023<> <(:)
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
log() {
|
log() {
|
||||||
@ -107,6 +109,37 @@ gettarget() {
|
|||||||
done < "$1"
|
done < "$1"
|
||||||
return 2
|
return 2
|
||||||
}
|
}
|
||||||
|
fskill() {
|
||||||
|
# Kill any number of PIDs, validating inputs n stuff
|
||||||
|
for pid in $@; do
|
||||||
|
# Sanity checks
|
||||||
|
[ -z "$pid" ] && continue
|
||||||
|
[ "$pid" -gt 0 ] 2> /dev/null || warn "Invalid PID: $pid" 2
|
||||||
|
[ -d "/proc/$pid" ] || warn "Process is already dead: $pid" 2
|
||||||
|
kill "$pid"
|
||||||
|
(
|
||||||
|
exec 1023<> <(:)
|
||||||
|
for (( i=0; i<10; i++ )); do
|
||||||
|
kill -0 "$pid" 2> /dev/null || return 0
|
||||||
|
read -t 1 -u 1023 || :
|
||||||
|
done
|
||||||
|
warn "Force stopping unresponsive process: $pid"
|
||||||
|
kill -9 "$pid"
|
||||||
|
)
|
||||||
|
done
|
||||||
|
}
|
||||||
|
fsstop() {
|
||||||
|
# Stop a running service by name
|
||||||
|
for service in $@; do
|
||||||
|
pidfile="$_optrundir"/"$service".pid
|
||||||
|
[ -f "$pidfile" ] || warn "Service is not already running: $service"
|
||||||
|
pid="$(< $pidfile)"
|
||||||
|
[ "$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"
|
||||||
|
return 0
|
||||||
|
done
|
||||||
|
}
|
||||||
fsexec() {
|
fsexec() {
|
||||||
# Execute an fsdefaults file
|
# Execute an fsdefaults file
|
||||||
[ -z "$1" ] && return 1
|
[ -z "$1" ] && return 1
|
||||||
@ -448,7 +481,7 @@ step_logout() {
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# Otherwise just brute it out
|
# Otherwise just brute it out
|
||||||
kill $(jobs -p)
|
fskill $(jobs -p)
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -468,8 +501,11 @@ provided
|
|||||||
|
|
||||||
init Start all services and wait
|
init Start all services and wait
|
||||||
list List all valid services
|
list List all valid services
|
||||||
start Start the provided service, fork, and exit
|
logout Log out of an existing Firestarter session
|
||||||
|
restart Stop and restart the provided services
|
||||||
|
start Start the provided services, fork, and exit
|
||||||
status Show status information
|
status Show status information
|
||||||
|
stop Stop the provided services
|
||||||
|
|
||||||
Environment Variables:
|
Environment Variables:
|
||||||
|
|
||||||
@ -496,6 +532,12 @@ firestart() {
|
|||||||
ls|list)
|
ls|list)
|
||||||
fslist
|
fslist
|
||||||
;;
|
;;
|
||||||
|
restart)
|
||||||
|
for file in "${_args[@]:1}"; do
|
||||||
|
fsstop "$file"
|
||||||
|
fsexec "$_optconfigdir"/"$file"
|
||||||
|
done
|
||||||
|
;;
|
||||||
start)
|
start)
|
||||||
for file in "${_args[@]:1}"; do
|
for file in "${_args[@]:1}"; do
|
||||||
fsexec "$_optconfigdir"/"$file"
|
fsexec "$_optconfigdir"/"$file"
|
||||||
@ -505,6 +547,11 @@ firestart() {
|
|||||||
fsstatus
|
fsstatus
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
|
for file in "${_args[@]:1}"; do
|
||||||
|
fsstop "$file"
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
logout)
|
||||||
if [ -n "$FIRESTARTER" ] && [ -d "/proc/$FIRESTARTER" ] && [ "$FIRESTARTER" -gt 0 ] 2> /dev/null; then
|
if [ -n "$FIRESTARTER" ] && [ -d "/proc/$FIRESTARTER" ] && [ "$FIRESTARTER" -gt 0 ] 2> /dev/null; then
|
||||||
log "Killing PID $FIRESTARTER"
|
log "Killing PID $FIRESTARTER"
|
||||||
kill $FIRESTARTER
|
kill $FIRESTARTER
|
||||||
|
Loading…
Reference in New Issue
Block a user