Rc.local and @cron not running a script as requested

I have tried everything I can find on the Linux forums about this, so have brought it back to see if it is a FreePBX (or Asterisk) issue.
FreePBX 14.0.5.2.
Asterisk 13.19.1
As has been noted elsewhere, after a system reboot, the phones often need to be re-started to avoid some tricky BLF behaviour. I want to automate the phone restart after an overnight episode of system reboot (usually after a power failure.)

Thanks to help from others on this forum, I have the script to run the phone restart:
asterisk -rx “pjsip send notify restart-yealink endpoint [ext numbers]” (after a modification of the sip_notify_custom.conf)
I have been able to write that into an executable file which runs from the CLI and restarts all the phones every time, without fail.

All of the advice is to either run this in rc.local (/etc/rc.d/rc.local) by adding the line to end of the file.
When I do that, and then run rc.local from the CLI, the phones re-start. But when I actually reboot, the phones do not restart.
So I tried crontrab (as root) and added @crontab /root/rebootphones.cron Again, the phones do not restart at reboot even though the rebootphones.cron file works when run from the CLI ( and even though it still shows up in the cron log)
Adding sleep 120 (ie @reboot sleep 120 /root/rebootphones.cron) doesn’t fix it.
I also moved it to a different folder in usr but same outcome.
As an experiment, in the crontab file I tried * 20 * * * rebootphones.cron And that actually worked!
I would prefer to use rc.local as that seems more what is intended for this kind of job. But neither that nor the cron works for me.

It looks like I will have the option of running a daily 6am cronjob to do this task, but I would rather only do it when I need to ie after a reboot.

Any one who can set me straight gets a chocolate frog.

In your rc.local, you need to start the script disconnected (so it doesn’t stop the boot sequence) and in the beginning, add something that make sure Asterisk has finished starting. You can use a really long “sleep” or loop on a “ps” check to see if you can spot Asterisk running. The script won’t do anything if Asterisk is still starting (or hasn’t started yet), and there’s no guarantee after a reboot that it’s going to start instantaneously.

In your crontab, make sure you are using the full pathname for fwconsole in the script. Just because your login session has fwconsole in the path is no promise crond will get it.

There should be a crond.log somewhere, take a look at that and see if you get any kind of indication on what’s failing.

Dave, you are a legend.
For those looking for a solution to this, these are the lines I have added to /etc/rc.d/rc.local:

fwconsole restart
sleep 30s
asterisk -rx “pjsip send notify reboot-yealink endpoint 101 102 103 104…”

exit 0

Exactly one minute after a system reboot, the phones rebooted. Finally I can sleep.
NB a modification is also required in sip_notify_custom.conf for the Yealink phones.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.