Separate the svc pidfile and the service one
Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
parent
4414293f9b
commit
075d94e58c
50
ssm
50
ssm
|
@ -148,7 +148,6 @@ svc() {
|
|||
nullexec kill -n "$service_stop_signal" "$job_pid"
|
||||
|
||||
anywait "$job_pid" "$service_stop_timeout"
|
||||
rm -f "$svc_pidfile" "$service_ready_flag"
|
||||
|
||||
# Cgroup stuff
|
||||
if cgroups; then
|
||||
|
@ -168,6 +167,8 @@ svc() {
|
|||
fi
|
||||
fi
|
||||
|
||||
rm -f "$svc_pidfile" "$service_pidfile" "$service_ready_flag"
|
||||
|
||||
die 0
|
||||
}; trap 'svc::cleanup' TERM
|
||||
|
||||
|
@ -200,6 +201,8 @@ svc() {
|
|||
# Wait for the process to exit and record the exit code
|
||||
# This depends on a few things
|
||||
if service_managed; then
|
||||
printf '%s' "$job_pid" > "$service_pidfile"
|
||||
|
||||
wait "$job_pid"; job_exit=$?
|
||||
else
|
||||
# We need to wait for the service to write down its pidfile
|
||||
|
@ -416,11 +419,7 @@ start() {
|
|||
reload() {
|
||||
service_running || return 3
|
||||
|
||||
if service_managed; then
|
||||
kill -n 1 "$service_pid"
|
||||
else
|
||||
kill -n "$service_reload_signal" "$service_pid"
|
||||
fi
|
||||
kill -n 1 "$svc_pid"
|
||||
}
|
||||
|
||||
## Stop the service
|
||||
|
@ -436,13 +435,9 @@ stop() {
|
|||
else
|
||||
service_running || return 3
|
||||
|
||||
if service_managed; then
|
||||
kill -n 15 "$service_pid" || return 1
|
||||
else
|
||||
kill -n "$service_stop_signal" "$service_pid" || return 1
|
||||
fi
|
||||
kill -n 15 "$svc_pid" || return 1
|
||||
|
||||
anywait "$service_pid" "$service_stop_timeout" || return 5
|
||||
anywait "$svc_pid" "$service_stop_timeout" || return 5
|
||||
> "$service_stopped_flag"
|
||||
|
||||
# Cgroup stuff
|
||||
|
@ -570,6 +565,7 @@ var service_pid \
|
|||
cgroup_home \
|
||||
failed_deps \
|
||||
svc_pidfile \
|
||||
svc_pid \
|
||||
cfg_path \
|
||||
cfg_file \
|
||||
cfg_dir \
|
||||
|
@ -778,10 +774,10 @@ fi
|
|||
service_pidfile && service_managed = 0
|
||||
|
||||
# Semi-hardcoded stuff
|
||||
svc_pidfile = "$rundir/$service_name.pid"
|
||||
svc_pidfile = "$rundir/$service_name.svc_pid"
|
||||
|
||||
# Service-level defaults
|
||||
service_pidfile := "$svc_pidfile"
|
||||
service_pidfile := "$rundir/$service_name.pid"
|
||||
service_logfile_out := "$logdir/${service_name}.log"
|
||||
service_logfile_err := "$service_logfile_out"
|
||||
service_success_exit := 0
|
||||
|
@ -792,13 +788,35 @@ if service_nologs; then
|
|||
service_logfile_err = '/dev/null'
|
||||
fi
|
||||
|
||||
# Let's see if there's a PID
|
||||
# Get the last recorded mainpid
|
||||
if service_pidfile is file; then
|
||||
read -r service_pid < "$service_pidfile"
|
||||
fi
|
||||
|
||||
# Let's see if there's an svc running
|
||||
if svc_pidfile is file; then
|
||||
read -r svc_pid < "$svc_pidfile"
|
||||
|
||||
# Let's see if it's running
|
||||
if nullexec kill -0 "$service_pid"; then
|
||||
if nullexec kill -0 "$svc_pid"; then
|
||||
service_running = 1
|
||||
|
||||
# If it's running, we know its PID probably:
|
||||
if service_pid; then
|
||||
if ! nullexec kill -0 "$service_pid"; then
|
||||
printf 'WARNING: The recorded service main PID (%s) is not running.\n' "$service_pid" >&2
|
||||
fi
|
||||
else
|
||||
printf 'WARNING: No service pidfile found; service PID unknown.\n' "$service_pidfile" >&2
|
||||
fi
|
||||
else
|
||||
if nullexec kill -0 "$service_pid"; then
|
||||
die 75 "ERROR: No svc active for $service_name, but its last recorded PID ($service_pidfile) is currenlty running: ${service_pid}."
|
||||
fi
|
||||
|
||||
# Remove the stale svc pidfile
|
||||
printf 'WARNING: Removing a stale svc pidfile: %s\n' "$svc_pidfile"
|
||||
rm -f "$svc_pidfile"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user