From f99cbfbdfa1ead0f36930ebcd3891c8ae3597fe1 Mon Sep 17 00:00:00 2001 From: Apollon Oikonomopoulos <apoikos@gmail.com> Date: Tue, 23 Jul 2013 17:21:31 +0300 Subject: [PATCH] daemon-util: provide rotate_logs and rotate_all_logs actions Modify daemon-util to allow sending SIGHUP to one or all daemons. This is meant as a utility function to be used in logrotate definitions. Signed-off-by: Apollon Oikonomopoulos <apoikos@gmail.com> Reviewed-by: Guido Trotter <ultrotter@google.com> --- daemons/daemon-util.in | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/daemons/daemon-util.in b/daemons/daemon-util.in index 9481dc043..2be14e9a8 100644 --- a/daemons/daemon-util.in +++ b/daemons/daemon-util.in @@ -311,6 +311,34 @@ stop_all() { done } +# SIGHUP a process to force re-opening its logfiles +rotate_logs() { + if [[ "$#" -lt 1 ]]; then + echo 'Missing daemon name.' >&2 + return 1 + fi + + local name="$1"; shift + local pidfile=$(_daemon_pidfile $name) + local daemonexec=$(_daemon_executable $name) + + if type -p start-stop-daemon >/dev/null; then + start-stop-daemon --stop --signal HUP --quiet \ + --pidfile $pidfile + else + _ignore_error killproc \ + -p $pidfile \ + $daemonexec -HUP + fi +} + +# SIGHUP all processes +rotate_all_logs() { + for i in $(list_stop_daemons); do + rotate_logs $i + done +} + # Reloads the SSH keys reload_ssh_keys() { @RPL_SSH_INITD_SCRIPT@ restart -- GitLab