Cron Failure - Any Ideas?

I have a PBX Appliance on 14/Asterisk 13. While logged in via root, I am attempting to test setting up a cron job:

0 5 * * * /usr/sbin/fwconsole reload

In doing so it looks like it is identifying as having missing components. When I look at the modules (Zulu, pm2, etc.) everything is installed and up to date.

Any idea on what I need to do in order to get the reload cron working?

Should I be setting the cron up via the asterisk user instead of root?

Thanks for the help!

Reloading FreePBX

In Process.php line 239:

 The command "runuser 'asterisk' -s '/bin/bash' -c 'cd /var/www/html/admin/m  
 odules/pm2/node && mkdir -p /home/asterisk/.pm2 && mkdir -p /var/www/html/a  
 dmin/modules/pm2/node/logs && export HOME=/home/asterisk && export PM2_HOME  
 =/home/asterisk/.pm2 && export ASTLOGDIR=/var/log/asterisk && export ASTVAR  
 LIBDIR=/var/lib/asterisk && export PATH=$HOME/.node/bin:$PATH && export NOD  
 E_PATH=$HOME/.node/lib/node_modules:$NODE_PATH && export MANPATH=$HOME/.nod  
 e/share/man:$MANPATH && /var/www/html/admin/modules/pm2/node/node_modules/p  
 m2/bin/pm2 jlist'" failed.                                                   

Exit Code: 127(Command not found)

Working directory: /root


Error Output:
sh: runuser: command not found

r args…

bump, we are planning to migrate to a new server, but need something in the interim. Not being able to do a cron has us at an impasse.

You’re on the right track. The cron job is running as root, which doesn’t have all the setup that your asterisk user has.

Here is an article on how to run a cron job as a different user.

Essentially, your cron entry is going to do a su:

0 5 * * * su username -c "/usr/sbin/fwconsole reload"

I will try this, although yesterday I did su into the asterisk user and placed:
0 5 * * * /usr/sbin/fwconsole reload
via crontab -e
It still did not work :frowning:

I’ll try as you suggest though I think there might be something with the nodejs install. Do I need the quotes like you have them?
0 5 * * * su asterisk -c "/usr/sbin/fwconsole reload"

It needs to be quoted, yes, as shown in the article I linked.

1 Like

Thanks! I’ll report back how it goes.

I got closer. This time I received a permission denied error. I switched to the asterisk user properly and put:

0 5 * * * /usr/sbin/fwconsole reload

With no quotes, In the asterisk user crontab, and it worked! Thanks for getting me pointed in the right direction @gbaughma

1 Like

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