Running fwconsole reload from cronjob

Freepbx version 16.

I am running fwconsole with a cronjob to apply config after midnight and it was working for a while. Recently we noticed its not working.
In cron logs I can see this:
22:24:01 XXXXXX-pri CROND[31688]: (root) CMD (fwconsole reload #Apply Config Nightly ) but the red apply config does not go away.

running fwconsole reload manually works.
Any idea why this is happening?

possibly some config changes happened after your “reload” Or may be “reload” got failed.

You can check freepbx logs during your cron time to see if you find anything.

No config change for sure because I am trying to see why this is not working and I am ruing cronjob( changing time to see it is running the command for sure ) and I am not changing configuration. I am checking cron logs.
I will check freepbx logs to see what’s going on and this is happening on two server. Thank you!

This is the error message I have in freepbx log when command is running from cronjob , but running fwconsole reload from CLI , I dont get any error message

[2024-08-06 23:51:01] [freepbx.INFO]: [NOTIFICATION]-[freepbx]-[RCONFFAIL] - ‘fwconsole reload’ failed, config not applied (The command “runuser ‘asterisk’ -s ‘/bin/bash’ -c ‘cd /var/www/html/admin/modules/pm2/node && mkdir -p /home/asterisk/.pm2 && mkdir -p /var/www/html/admin/modules/pm2/node/logs && export HOME=/home/asterisk && export PM2_HOME=/home/asterisk/.pm2 && export ASTLOGDIR=/var/log/asterisk && export ASTVARLIBDIR=/var/lib/asterisk && export PATH=$HOME/.node/bin:$PATH && export NODE_PATH=$HOME/.node/lib/node_modules:$NODE_PATH && export MANPATH=$HOME/.node/share/man:$MANPATH && /var/www/html/admin/modules/pm2/node/node_modules/pm2/bin/pm2 jlist’” failed. Exit Code: 127(Command not found) Working directory: /root Output: ================ Error Output: ================ sh: runuser: command not found )

man runuser

for the reason, runuser is not in the $PATH of the asterisk user and even if it where, /usr/sbin/runuser can only be run by the root user

Do mean this is happening because we are running this command by asterisk user? But cronjob is running fwconsole as root

(root) CMD (fwconsole reload #Apply Config Nightly )

Output: ================ Error Output: ================ sh: runuser: command not found )

sh
which runuser
echo $PATH
runuser
exit

Thank you for your reply, this is what I have :slight_smile:
which runuser
/usr/sbin/runuser
[root@xxxx-pri ~]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

I updated my cronjob and I am using sudo cronjob -e to create this cron job and now, I dont have fail message in freepbx.log. Yet, apply is not done.

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
21 10 * * * root /usr/sbin/fwconsole reload #Apply Config Nightly
~

I updated /etc/crontab
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/sbin:/bin:/usr/sbin:/usr/bin

29 11 * * * root /usr/sbin/fwconsole reload #Apply Config Nightly

~
And this one is working. crontab -e was not working. Thanks for everyone trying to help :slight_smile:

crontab -e should not have a user , you should add the -u user to crontab -e to make sure your editing the correct crontab

crontab -h
crontab -u asterisk -e # for asterisk user
crontab -u root -e # for root user

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