ejabberd can run for months without needed to be restarted. That's why it is why to define a log file rotation policy. This document describe how to set logrotate for use with ejabberd.
Depending on how ejabberd is started, the steps described here might change a bit. In this example, we suppose you have installed ejabberd with Linux graphical installer, available from ejabberd download page. We make this assumption that ejabberd has been installed in the directory /home/mremond/ejabberd-1.0.0/.
Logrotate
On Linux distributions, the program logrotate is in charge of renaming log files for archiving purpose and for keeping the size of the log file manageable.
The configuration of logrotate is usually defined in the file /etc/logrotate.conf. To enable logrotate for ejabberd, add the following section to the file:
/home/mremond/ejabberd-1.0.0/logs/ejabberd.log { weekly missingok rotate 10 compress delaycompress ifempty nomail sharedscripts postrotate /home/mremond/ejabberd-1.0.0/bin/ejabberdctl default reopen-log > /dev/null endscript }
You should check that the postrotate command is working, otherwise ejabberd might get confused.
To check your setting, you can type the following command. The program will simulate all log rotation actions.
/usr/sbin/logrotate --debug --force /etc/logrotate.conf
You can test your setting by typing the following command. The program will actually execute the log rotation, for the whole system:
/usr/sbin/logrotate --debug --force /etc/logrotate.conf
The program logrotate will be run once a day by the system cron.
Alternative logrotate config
If the ejabberdctl script does not exist on the ejabberd system, the postrotate script can be replaced with a command like:
erl -sname logrotate -s ejabberd_ctl -noshell -setcookie cookie -extra nodename reopen-log > /dev/null
cookie and nodename should be changed to match your local setting.
Be sure to have the file ejabberd_ctl.beam in your Erlang class path. If needed, you can start the previous command with the option -pa Path, with Path being a directory containing ejabberd_ctl.beam.
The resulting logrotate entry might thus become:
/home/mremond/ejabberd-1.0.0/logs/ejabberd.log { daily missingok rotate 10 compress delaycompress ifempty nomail sharedscripts postrotate /usr/local/bin/erl -pa /opt/beam/ -sname logrotate -s ejabberd_ctl -noshell \ -setcookie cookie -extra nodename reopen-log > /dev/null endscript }