Page 1 of 1
Restart Apache2 each day via CRON ?
Posted: Wed Aug 20, 2014 8:38 am
by quatroweb
Anyone knows how I get the Apache2 to restart each day at example 03:00 AM ?
I have already tried to make a CRON job with the following data:
00 03 * * *
sudo /usr/local/vesta/bin/v-restart-web
The Cron Daemon gives me following message:
sudo: no tty present and no askpass program specified Sorry, try again.
sudo: no tty present and no askpass program specified Sorry, try again.
sudo: no tty present and no askpass program specified Sorry, try again.
sudo: 3 incorrect password attempts
Any ideas how I set this up correctly via the cron interface?
Re: Restart Apache2 each day via CRON ?
Posted: Wed Aug 20, 2014 1:34 pm
by Kyon
Hello quatroweb,
Try do add this cron in the root crontab and don't use the sudo.
Regards,
Re: Restart Apache2 each day via CRON ?
Posted: Wed Aug 20, 2014 11:29 pm
by quatroweb
Hi Kyon and thanks for your answer.
I tried what you mentioned and got following result:
Added the cron job with the root login to vestacp, but without sudo like this: /usr/local/vesta/bin/v-restart-web
And got this respond from Daemon:
/bin/sh: 1: /usr/local/vesta/bin/v-restart-web: Permission denied
After I tried with sudo like: sudo /usr/local/vesta/bin/v-restart-web
And got this respond from Daemon:
/usr/local/vesta/bin/v-restart-web: line 13: /func/main.sh: No such file or directory
/usr/local/vesta/bin/v-restart-web: line 14: /conf/vesta.conf: No such file or directory
It looks like the second time with sudo that it actually got permission, but don't have such directories?
Am I doing something wrong or miss something?
Re: Restart Apache2 each day via CRON ?
Posted: Thu Aug 21, 2014 7:16 am
by Kyon
Hi,
Added the cron job with the root login to vestacp,
Not with vestap but with the linux tool. In command line, as root user, you can type "crontab -e" and add the cron line without sudo but if your second test with sudo work, go to the next point ->, it's just for information :p.
/usr/local/vesta/bin/v-restart-web: line 13: /func/main.sh: No such file or directory
/usr/local/vesta/bin/v-restart-web: line 14: /conf/vesta.conf: No such file or directory
This mean that the environment variable "VESTA" is missing.
Try something like "export VESTA=/usr/local/vesta/;sudo /usr/local/vesta/bin/v-restart-web".
Re: Restart Apache2 each day via CRON ?
Posted: Fri Sep 05, 2014 3:35 am
by quatroweb
This is my cron jobs created by default in VestaCP
15 02 * * * sudo /usr/local/vesta/bin/v-update-sys-queue disk
10 00 * * * sudo /usr/local/vesta/bin/v-update-sys-queue traffic
30 03 * * * sudo /usr/local/vesta/bin/v-update-sys-queue webstats
*/5 * * * * sudo /usr/local/vesta/bin/v-update-sys-queue backup
10 05 * * * sudo /usr/local/vesta/bin/v-backup-users
20 00 * * * sudo /usr/local/vesta/bin/v-update-user-stats
*/5 * * * * sudo /usr/local/vesta/bin/v-update-sys-rrd
Each day I go to Services in VestaCP, but I want the apache2 to restart automatically without have to do it manually.
The question is, how do I add one more cron job in the file /var/spool/cron/admin for restarting the apache each day at 3 AM ?
Re: Restart Apache2 each day via CRON ?
Posted: Fri Sep 05, 2014 12:19 pm
by imperio
Try to use this command in vestacp cron
Code: Select all
export VESTA=/usr/local/vesta/;sudo /usr/local/vesta/bin/v-restart-service apache2
Code: Select all
00
03
*
*
*
export VESTA=/usr/local/vesta/;sudo /usr/local/vesta/bin/v-restart-service apache2
Re: Restart Apache2 each day via CRON ?
Posted: Fri Sep 05, 2014 12:30 pm
by quatroweb
Worked like a charm!! Thanks a lot..
Re: Restart Apache2 each day via CRON ?
Posted: Tue Sep 16, 2014 3:20 pm
by quatroweb
Anyone know how to restart the OS (example: Ubuntu) from cron?
I want to restart the hole Ubuntu 12.04, like you can actually do in Services in VestaCP at the top.
What I have at the moment is only for apache2:
Code: Select all
export VESTA=/usr/local/vesta/;sudo /usr/local/vesta/bin/v-restart-service apache2
Any suggestions, advice's, best practices etc.?
Re: Restart Apache2 each day via CRON ?
Posted: Sun Sep 21, 2014 3:32 pm
by imperio
You should use
system crontab for this
Re: Restart Apache2 each day via CRON ?
Posted: Sun May 31, 2020 4:17 pm
by joeygeo
For 6 years - nobody cared to answer this... so here it is:
sudo /usr/local/vesta/bin/v-restart-system yes
Use above command in cron, and it should work without errors... for some reason, using /sbin/reboot does not work, even though the vesta script v-restart-system is internally using /sbin/reboot !!!