Vesta Control Panel - Forum

Community Forum

Skip to content

Advanced search
  • Quick links
    • Main site
    • Github repo
    • Google Search
  • FAQ
  • Login
  • Register
  • Board index Main Section General Discussion
  • Search

Restart Apache2 each day via CRON ?

General questions about VestaCP
Post Reply
  • Print view
Advanced search
10 posts • Page 1 of 1
quatroweb
Posts: 31
Joined: Wed Aug 20, 2014 8:21 am

Restart Apache2 each day via CRON ?
  • Quote

Post by quatroweb » Wed Aug 20, 2014 8:38 am

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?
Top

Kyon
Posts: 19
Joined: Tue Jul 29, 2014 9:11 am

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by Kyon » Wed Aug 20, 2014 1:34 pm

Hello quatroweb,

Try do add this cron in the root crontab and don't use the sudo.

Regards,
Top

quatroweb
Posts: 31
Joined: Wed Aug 20, 2014 8:21 am

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by quatroweb » Wed Aug 20, 2014 11:29 pm

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?
Top

Kyon
Posts: 19
Joined: Tue Jul 29, 2014 9:11 am

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by Kyon » Thu Aug 21, 2014 7:16 am

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".
Top

quatroweb
Posts: 31
Joined: Wed Aug 20, 2014 8:21 am

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by quatroweb » Fri Sep 05, 2014 3:35 am

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 ?
Top

imperio
VestaCP Team
Posts: 7000
Joined: Sat Dec 01, 2012 12:37 pm
Contact:
Contact imperio
Website

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by imperio » Fri Sep 05, 2014 12:19 pm

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
Top

quatroweb
Posts: 31
Joined: Wed Aug 20, 2014 8:21 am

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by quatroweb » Fri Sep 05, 2014 12:30 pm

Worked like a charm!! Thanks a lot..
Top

quatroweb
Posts: 31
Joined: Wed Aug 20, 2014 8:21 am

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by quatroweb » Tue Sep 16, 2014 3:20 pm

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.?
Top

imperio
VestaCP Team
Posts: 7000
Joined: Sat Dec 01, 2012 12:37 pm
Contact:
Contact imperio
Website

Re: Restart Apache2 each day via CRON ?
  • Quote

Post by imperio » Sun Sep 21, 2014 3:32 pm

You should use system crontab for this

Code: Select all

/sbin/reboot
Top

joeygeo
Posts: 1
Joined: Sun May 31, 2020 4:14 pm

Os: Ubuntu 17x
Web: apache + nginx
Re: Restart Apache2 each day via CRON ?
  • Quote

Post by joeygeo » Sun May 31, 2020 4:17 pm

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 !!!
Top


Post Reply
  • Print view

10 posts • Page 1 of 1

Return to “General Discussion”



  • Board index
  • All times are UTC
  • Delete all board cookies
  • The team
Powered by phpBB® Forum Software © phpBB Limited
*Original Author: Brad Veryard
*Updated to 3.2 by MannixMD
 

 

Login  •  Register

I forgot my password