Soporte & Consultoria

Soporte Remoto y Consultoria skype : ambiorixg12.
Nota no se brinda ningun tipo de consulta o soporte fuera del blog de forma gratuita

domingo, 2 de octubre de 2016

Asterisk logrotate

logrotate

'logger rotate' and logrotate

Asterisk logs files (typically under /var/log/asterisk) need some attention because they can get quite large.

You can do "logger rotate" from the asterisk command line or

/usr/sbin/asterisk -rx 'logger rotate'

from a bash prompt .. and you can add it to a cron job so it does it automatically for you.


logrotate

If however you have a system that uses the logrotate utility, you can get it to rotate without making a special script and you can still have good control over what the system does with your logs.

Here is a sample from /etc/logrotate.d/asterisk on my system

/var/log/asterisk/messages /var/log/asterisk/*log {
missingok
rotate 5
weekly
create 0640 asterisk asterisk
postrotate
/usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
endscript
}

This setup will rotate the files weekly cycling them 5 times so for example, messages will be the newest log file, followed by messages.1, messages.2 all the way to messages.5 (the oldest). If you are not running asterisk as user:group asterisk:asterisk, you can eleminate the create 0640 asterisk asterisk line.

If you're just keeping cdr records in csv files and you're just using them to check against VOIP providers charges (so accuracy isn't a big concern) you can use this logrotate script to rotate them once a month

/var/log/asterisk/cdr-csv/*csv {
missingok
rotate 5
monthly
create 0640 asterisk asterisk
}

logrotate for Debian / Ubuntu

You'd still need to command asterisk 'logger reload' just after moving the log file, or otherwise it will continue to write to the old file.

The current default Debian /etc/logrotate.d/asterisk is:

/var/log/asterisk/cdr-csv/Master.csv /var/log/asterisk/debug /var/log/asterisk/event_log /var/log/asterisk/messages {
weekly
missingok
rotate 4
sharedscripts
postrotate
/usr/sbin/invoke-rc.d asterisk logger-reload
endscript
}

It is not necessary to reload if you use the copytruncate option in the logrotate script, see below.

It is also not necessary to logrotate a log file that has not grown enough in size, see the use of option size below to control this feature. Only files larger than 2000k (2meg) are rotated.

Customized Debian / Ubuntu /etc/logrotate.d/asterisk

/var/log/asterisk/cdr-csv/Master.csv /var/log/asterisk/debug /var/log/asterisk/event_log /var/log/asterisk/messages {
weekly
missingok
rotate 9
size 2000k
copytruncate
endscript
}

No hay comentarios:

Publicar un comentario