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"
|
nullexec kill -n "$service_stop_signal" "$job_pid"
|
||||||
|
|
||||||
anywait "$job_pid" "$service_stop_timeout"
|
anywait "$job_pid" "$service_stop_timeout"
|
||||||
rm -f "$svc_pidfile" "$service_ready_flag"
|
|
||||||
|
|
||||||
# Cgroup stuff
|
# Cgroup stuff
|
||||||
if cgroups; then
|
if cgroups; then
|
||||||
|
@ -168,6 +167,8 @@ svc() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -f "$svc_pidfile" "$service_pidfile" "$service_ready_flag"
|
||||||
|
|
||||||
die 0
|
die 0
|
||||||
}; trap 'svc::cleanup' TERM
|
}; trap 'svc::cleanup' TERM
|
||||||
|
|
||||||
|
@ -200,6 +201,8 @@ svc() {
|
||||||
# Wait for the process to exit and record the exit code
|
# Wait for the process to exit and record the exit code
|
||||||
# This depends on a few things
|
# This depends on a few things
|
||||||
if service_managed; then
|
if service_managed; then
|
||||||
|
printf '%s' "$job_pid" > "$service_pidfile"
|
||||||
|
|
||||||
wait "$job_pid"; job_exit=$?
|
wait "$job_pid"; job_exit=$?
|
||||||
else
|
else
|
||||||
# We need to wait for the service to write down its pidfile
|
# We need to wait for the service to write down its pidfile
|
||||||
|
@ -416,11 +419,7 @@ start() {
|
||||||
reload() {
|
reload() {
|
||||||
service_running || return 3
|
service_running || return 3
|
||||||
|
|
||||||
if service_managed; then
|
kill -n 1 "$svc_pid"
|
||||||
kill -n 1 "$service_pid"
|
|
||||||
else
|
|
||||||
kill -n "$service_reload_signal" "$service_pid"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
## Stop the service
|
## Stop the service
|
||||||
|
@ -436,13 +435,9 @@ stop() {
|
||||||
else
|
else
|
||||||
service_running || return 3
|
service_running || return 3
|
||||||
|
|
||||||
if service_managed; then
|
kill -n 15 "$svc_pid" || return 1
|
||||||
kill -n 15 "$service_pid" || return 1
|
|
||||||
else
|
|
||||||
kill -n "$service_stop_signal" "$service_pid" || return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
anywait "$service_pid" "$service_stop_timeout" || return 5
|
anywait "$svc_pid" "$service_stop_timeout" || return 5
|
||||||
> "$service_stopped_flag"
|
> "$service_stopped_flag"
|
||||||
|
|
||||||
# Cgroup stuff
|
# Cgroup stuff
|
||||||
|
@ -570,6 +565,7 @@ var service_pid \
|
||||||
cgroup_home \
|
cgroup_home \
|
||||||
failed_deps \
|
failed_deps \
|
||||||
svc_pidfile \
|
svc_pidfile \
|
||||||
|
svc_pid \
|
||||||
cfg_path \
|
cfg_path \
|
||||||
cfg_file \
|
cfg_file \
|
||||||
cfg_dir \
|
cfg_dir \
|
||||||
|
@ -778,10 +774,10 @@ fi
|
||||||
service_pidfile && service_managed = 0
|
service_pidfile && service_managed = 0
|
||||||
|
|
||||||
# Semi-hardcoded stuff
|
# Semi-hardcoded stuff
|
||||||
svc_pidfile = "$rundir/$service_name.pid"
|
svc_pidfile = "$rundir/$service_name.svc_pid"
|
||||||
|
|
||||||
# Service-level defaults
|
# Service-level defaults
|
||||||
service_pidfile := "$svc_pidfile"
|
service_pidfile := "$rundir/$service_name.pid"
|
||||||
service_logfile_out := "$logdir/${service_name}.log"
|
service_logfile_out := "$logdir/${service_name}.log"
|
||||||
service_logfile_err := "$service_logfile_out"
|
service_logfile_err := "$service_logfile_out"
|
||||||
service_success_exit := 0
|
service_success_exit := 0
|
||||||
|
@ -792,13 +788,35 @@ if service_nologs; then
|
||||||
service_logfile_err = '/dev/null'
|
service_logfile_err = '/dev/null'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Let's see if there's a PID
|
# Get the last recorded mainpid
|
||||||
if service_pidfile is file; then
|
if service_pidfile is file; then
|
||||||
read -r service_pid < "$service_pidfile"
|
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
|
# Let's see if it's running
|
||||||
if nullexec kill -0 "$service_pid"; then
|
if nullexec kill -0 "$svc_pid"; then
|
||||||
service_running = 1
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user