I have always found that its a good idea to reboot Asterisk every now and again. However I found that sometimes my cron job got stuck or Asterisk didn’t restart cleanly.
This is my original, standard cron job.
0 0 * * * root /usr/sbin/asterisk -rx ‘core restart gracefully’
So I write a little script to check if there are any open channels and if not restart now.
0 0 * * * root /root/asterisk_restart.sh > /dev/null
#!/bin/bash while : do CHANNELS=$(asterisk -rx "core show channels concise") if [ -n "$CHANNELS" ]; then asterisk -rx "core restart now" break fi sleep 1 done
Simple, but rather handy. I have been running this script now on all my Asterisk servers and its work without fault each day.