I have ejabberd installed on a box I built, along with bandersnatch for logging of instant messages. Bandersnatch did not have a logging mechanism other than to screen, so I just dumped the output to /var/log/bandersnatch.log - AFAIK, the process needs to be restarted in order to release the log file. Further, ejabberd does not respond to a SIG_HUP by re-opening it's log file and instead requires a command to be executed. ([cmd=]ejabberdctl reopen-log[/cmd] for those interested.)
Since newsyslog does not have the ability to do anything but send a HUP signal to a process identified by a PID file, I decided to make something to get around this limitation. The following is the simple script that I came up with for ejabberd - simply change two of the variables as described to use it for another such program.
Since newsyslog does not have the ability to do anything but send a HUP signal to a process identified by a PID file, I decided to make something to get around this limitation. The following is the simple script that I came up with for ejabberd - simply change two of the variables as described to use it for another such program.
Code:
#!/usr/local/bin/bash
###############################################################################
# #
# Shell script to allow a command to be executed upon receipt of a signal. #
# Designed to allow newsyslog to execute a command for software that either #
# does not have a PID file or does not respond to a SIG_HUP signal and #
# requires an external command to reopen its log file. #
# #
###############################################################################
# #
# Ruler's Common-Sense License: #
# #
# You may use this script however you want to, but I don't warrant it to #
# be good for anything in particular, though it happens to work well for #
# me. (I hate putting BS like this in, but I hate more being sued.) If #
# you use this script, you must keep this license and credit to me in it #
# in the form of this block, even if you modify it for your own use. If #
# you want to send me money for it, fantastic! Send me a private message #
# on the freebsd.org forums and I'll give you my PayPal address. :-) Even #
# just a simple 'thank you' would be nice. If not, that's fine too. All #
# hate mail/spam is sent directly to /dev/null #
# - Jim, AKA Ruler2112 #
# #
###############################################################################
# #
# History: #
# #
# 2010-02-11 by Ruler2112 Wrote initial version. #
# 2010-02-11 by Ruler2112 Released on freebsd.org forums. #
# #
###############################################################################
###############################################################################
# Variable Declaration Section #
# Set these variables to customize this script's behavior. #
###############################################################################
# What happens when a HUP signal is received.
HUP_ACTION="/usr/local/sbin/ejabberdctl reopen-log"
# How many seconds to pause between signal checks. This will be the maximum
# amount of time between the time a signal is received and when the associated
# action occurs. The lower this is, the more CPU time this script will use
# Higher values will decrease the amount of CPU power this script will consume
# but also increases the likelihood of a significant wait betwwen the sending
# of the signal and when the appropriate action is executed.
WAIT_TIME=3
# The name of a PID file that this script will generate. Use this in
# /etc/newsyslog.conf THIS SCRIPT WILL SILENTLY OVERWRITE THIS FILE,
# BE 100% CERTAIN THAT IT'S NOT AN IMPORTANT FILE!!! I recommend using
# something in /var/run and naming it indirect-<name> for safety.
MY_PID_FILE="/var/run/indirect-ejabberd"
###############################################################################
# !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! #
###############################################################################
# This is the Beginning of the Script #
# #
# Do not change anything below this line unless you know what you're doing! #
###############################################################################
/bin/echo $$ > "$MY_PID_FILE"
trap "$HUP_ACTION" SIGHUP
trap "/bin/rm -f \"$MY_PID_FILE\";exit 0" SIGINT SIGTERM
while true; do
/bin/sleep $WAIT_TIME
done