logfile cleanup

Signed-off-by: fbt <fbt@fleshless.org>
This commit is contained in:
Jack L. Frost 2018-01-08 05:48:40 +03:00
parent a5f93916cd
commit e733ed4f6a
1 changed files with 21 additions and 10 deletions

31
ssm
View File

@ -89,7 +89,7 @@ svc() {
var job_pid
svc::cleanup() {
kill -n "$service_stop_signal" "$job_pid"
nullexec kill -n "$service_stop_signal" "$job_pid"
pid_wait "$job_pid"
rm -f "$svc_pidfile" "$service_ready_flag"
@ -99,7 +99,7 @@ svc() {
kill -n "$service_reload_signal" "$job_pid"
}; trap 'svc::reload' HUP
"$@" & job_pid = "$!"
"$@" 1>"$service_logfile_out" 2>"$service_logfile_err" & job_pid = "$!"
printf '%s' "$job_pid" > "$svc_pidfile"
wait "$job_pid"
@ -297,9 +297,9 @@ start() {
if service_managed; then
if service_respawn; then
svc respawn "${service_command[@]}" &>"$service_logfile" &
svc respawn "${service_command[@]}" &
else
svc "${service_command[@]}" &>"$service_logfile" &
svc "${service_command[@]}" &
fi
if timer "$service_ready_timeout" ready; then
@ -308,11 +308,11 @@ start() {
return 5
fi
elif service_oneshot; then
"${service_command[@]}" &>"$service_logfile"; res=$?
"${service_command[@]}" 1>"$service_logfile_out" 2>"$service_logfile_err"; res=$?
(( res )) && return "$res"
printf '1' > "$service_enabled_flag"
else
exec "${service_command[@]}" &
exec "${service_command[@]}" 1>"$service_logfile_out" 2>"$service_logfile_err" &
fi
return 0
@ -368,7 +368,9 @@ info() {
"$_status_label" "$_status" \
"Exec" "${service_command[*]} ${service_args[*]}" \
"Respawn" "${service_respawn:-false}" \
"Config path" "${service_config}" \
"Config path" "$service_config" \
"Output log" "$service_logfile_out" \
"Error log" "$service_logfile_err"
if _status == 'yes'; then
_info_items += \
@ -386,7 +388,7 @@ restart() {
}
edit() { $EDITOR "$service_config"; }
logs() { $PAGER "$service_logfile"; }
logs() { printf '%s\n' "$service_logfile_out" "$service_logfile_err"; }
## Status is a bit of a special case. It's talkative.
status() {
@ -414,7 +416,8 @@ var service_pid \
service_path \
service_name \
service_args \
service_logfile \
service_logfile_out \
service_logfile_err \
service_ready_flag \
service_enabled_flag \
service_stopped_flag \
@ -446,6 +449,7 @@ var service_ready_timeout = 15
var service_stop_signal = 15
var service_reload_signal = 1
var service_signals = 1 10 12
var service_nologs = 0
var systemd = 0
var systemd_service_path = /etc/systemd/system /run/systemd/system /lib/systemd/system
var ssm_config = 0
@ -568,11 +572,18 @@ svc_pidfile = "$rundir/$service_name.pid"
# Service-level defaults
service_pidfile := "$svc_pidfile"
service_logfile := "$logdir/$service_name.log"
service_logfile_out := "$logdir/${service_name}.out.log"
service_logfile_err := "$logdir/${service_name}.err.log"
service_ready_flag := "$rundir/$service_name.ready"
service_enabled_flag := "$rundir/$service_name.enabled"
service_stopped_flag := "$rundir/$service_name.stopped"
# A shortcut for disabling logging
if service_nologs; then
service_logfile_out = '/dev/null'
service_logfile_err = '/dev/null'
fi
# Let's see if there's a PID
if [[ -f "$service_pidfile" ]]; then
service_pid = "$(<$service_pidfile)"