Signal passthru and support for $service_name::function style namespacing
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
075d94e58c
commit
88e05630ae
50
ssm
50
ssm
|
@ -123,6 +123,24 @@ die() {
|
|||
exit "$code"
|
||||
}; readonly -f die
|
||||
|
||||
if_service_action() {
|
||||
for f in "$1" "$service_name::$1"; do
|
||||
is_function "$f" && return 0
|
||||
done
|
||||
|
||||
return 0
|
||||
}; readonly -f if_service_action
|
||||
|
||||
run_service_action() {
|
||||
for f in "$1" "$service_name::$1"; do
|
||||
is_function "$f" && {
|
||||
"$f"; return $?
|
||||
}
|
||||
done
|
||||
|
||||
return 0
|
||||
}; readonly -f run_service_action
|
||||
|
||||
spawn() {
|
||||
if [[ $service_logfile_out == "$service_logfile_err" ]]; then
|
||||
exec "$@" >"$service_logfile_out" 2>&1
|
||||
|
@ -176,6 +194,12 @@ svc() {
|
|||
nullexec kill -n "$service_reload_signal" "$job_pid"
|
||||
}; trap 'svc::reload' HUP
|
||||
|
||||
# Signals to pass through to the mainpid.
|
||||
svc::passthru() { kill -n "$1" "$2"; }
|
||||
for s in "${service_signals_passthru[@]}"; do
|
||||
trap "svc::passthru $s \$job_pid" "$s"
|
||||
done
|
||||
|
||||
printf '%s' $BASHPID > "$svc_pidfile"
|
||||
|
||||
# Cgroups
|
||||
|
@ -562,6 +586,7 @@ var service_pid \
|
|||
service_cgroup_name \
|
||||
service_cgroup_procs \
|
||||
service_cgroup_path \
|
||||
service_signals_passthru \
|
||||
cgroup_home \
|
||||
failed_deps \
|
||||
svc_pidfile \
|
||||
|
@ -735,6 +760,7 @@ flag_edit_service && { edit; die $?; }
|
|||
|
||||
# Service name is the basename
|
||||
service_name = "${1##*/}"
|
||||
readonly service_name
|
||||
|
||||
# These depend on the service_name and make little sense to reconfigure.
|
||||
service_ready_flag := "$rundir/$service_name.ready"
|
||||
|
@ -854,8 +880,8 @@ if cgroups; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# Check if action is even defined
|
||||
is_function "$2" || die 17 "Function $2 is not defined for $service_name."
|
||||
# Do we have such a function?
|
||||
if_service_action "$2" || die 17 "Function $2 is not defined for $service_name."
|
||||
|
||||
# cd into the workdir, if defined.
|
||||
service_workdir && {
|
||||
|
@ -863,15 +889,10 @@ service_workdir && {
|
|||
}
|
||||
|
||||
# Run pre_$action function
|
||||
if is_function "pre_$2"; then
|
||||
"pre_$2" || {
|
||||
printf 'pre_%s failed!\n' "$2"
|
||||
die 13
|
||||
}
|
||||
fi
|
||||
run_service_action "pre_$2" || die 13 "pre_$2 failed!"
|
||||
|
||||
# Run the function
|
||||
"$2"; res=$?
|
||||
# Run the main action
|
||||
run_service_action "$2"; res=$?
|
||||
|
||||
case "$2" in
|
||||
stop)
|
||||
|
@ -894,7 +915,7 @@ case "$2" in
|
|||
|
||||
reload)
|
||||
result "$res" \
|
||||
0 "Reloaded $service_name"
|
||||
0 "Reloading $service_name"
|
||||
;;
|
||||
|
||||
status)
|
||||
|
@ -911,9 +932,4 @@ esac
|
|||
(( res )) && exit "$res"
|
||||
|
||||
# Run post_$action function
|
||||
if is_function "post_$2"; then
|
||||
"post_$2" || {
|
||||
printf 'post_%s failed!\n' "$2"
|
||||
die 15
|
||||
}
|
||||
fi
|
||||
run_service_action "post_$2" || die 15 "post_$2 has failed!"
|
||||
|
|
Loading…
Reference in New Issue
Block a user