#!/usr/bin/env bash

echo
echo "*** Configuring logrotate for Asterisk ***"
echo

cat > /etc/logrotate.d/asterisk <<-EOF
/var/log/asterisk/*log /var/log/asterisk/full /var/log/asterisk/messages /var/log/asterisk/debug {
   notifempty
   missingok
   rotate 7
   daily
   dateext
   compress
   sharedscripts
   create 0640 asterisk asterisk
   su asterisk asterisk
   postrotate
       /usr/sbin/asterisk -rx 'logger reload' > /dev/null 2> /dev/null
   endscript
}
/var/log/asterisk/cdr-csv/*csv {
  notifempty
  missingok
  rotate 5
  monthly
  create 0640 asterisk asterisk
  su asterisk asterisk
} 
EOF

cat > /etc/logrotate.d/pbxmanager <<-EOF
/var/log/uniserver.log /etc/webmin/asterisk/debug.log {
   notifempty
   missingok
   rotate 7
   daily
   dateext
   compress
   sharedscripts
   create 0640 asterisk asterisk
   postrotate
        /bin/systemctl restart uniserver  > /dev/null 2> /dev/null
   endscript
}
EOF

cat > /etc/logrotate.d/syslog <<-EOF
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    missingok
    notifempty
    rotate 14
    daily
    dateext
    create 0644 root root
    compress
    sharedscripts
    postrotate
        /bin/kill -HUP \`cat /var/run/syslogd.pid 2> /dev/null\` 2> /dev/null || true
    endscript
}
EOF
