Solved

how to restart apache via cron

Posted on 2007-04-06
16
3,626 Views
Last Modified: 2012-08-14
I need to setup a cron job in plesk which restarts apache every night. we are trying to resolve an issue.

Im currently typing in the following every morning.

/etc/init.d/httpd start
/etc/init.d/httpd stop

It is plesk 8.1 running on linux
0
Comment
Question by:Cheryl Lander
  • 9
  • 6
16 Comments
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18867669
I don't believe you'll have access to root's crontab through Plesk.  Do you have root access to the server?  If so, edit /etc/crontab and insert the following line:

00 06 * * * root /etc/init.d/httpd restart
0
 

Author Comment

by:Cheryl Lander
ID: 18868210
Ive gone into scheduled tasks on the server page.

Clicked on root (i do have access)

And added the taks you suggested.

i did a test run and it didnt seem to work.

heres what I have.

10      15      *      *      *      /etc/init.d/httpd restart

Shoud I be placing this under the apache option.

0
 

Author Comment

by:Cheryl Lander
ID: 18868215
ive just tried it under the apache option and doesnt work either.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 15

Expert Comment

by:samri
ID: 18868545
hi SWHosting:

your entry
10      15            *                *      *      /etc/init.d/httpd restart
# MIN   HOUR   MDAY  MON  DOW   COMMAND

are you sure you want it to run at 15hr (3.10pm) ?
0
 

Author Comment

by:Cheryl Lander
ID: 18868896
The time of 3.10pm was done as a test to see if it works.

But it didnt.
0
 

Author Comment

by:Cheryl Lander
ID: 18871255
Ive setup cron to email me with any issues relatig to the cron Ive setup using the following.

10      15      *      *      *      /etc/init.d/httpd restart

And this is what I get.

Stopping httpd: [FAILED]
rm: cannot remove `/var/run/httpd.pid': Permission denied

Starting httpd:
touch: cannot touch `/var/lock/subsys/httpd': Permission denied
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18871381
I'm not sure that the Plesk user root is going to be the same as the local system user root.  Do you have CLI access to the server as root?
0
 

Author Comment

by:Cheryl Lander
ID: 18871398
I have full root access the server.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18872452
Did you put that line into a cron job in Plesk, or did you put it in /etc/crontab?  It should be going into /etc/crontab.  Make sure you restart crond before testing.

Since you're using Plesk, you have an easy option available to you to make your server restart every so often.  Look in  Server Preferences for "Apache restart interval"
0
 

Author Comment

by:Cheryl Lander
ID: 18910470
ive just gone into server>scheduled tasks and I dont have an etc

heres my list.

adm
alias
apache
bin
daemon
dbus
ftp
games
gopher
haldaemon
halt
lp
mail
mailman
mailnull
mysql
named
news
nobody
nscd
ntp
operator
popuser
psaadm
psaftp
qmaild
qmaill
qmailp
qmailq
qmailr
qmails
root
rpc
rpm
shutdown
smmsp
sshd
sync
uucp
vcsa
webalizer
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18916044
Look in  Server Preferences for "Apache restart interval".  Set this to however long you like.  It should get the job done for you.

Otherwise, can you log in to the server in any way other than Plesk?
0
 

Author Comment

by:Cheryl Lander
ID: 18917508
I can log in via ssh with root.

So If I set the restart interval to 86400 24 hours / seconds.

is this correct.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18920165
>>> I can log in via ssh with root.

The cron job insertion would be done using that type of login.  You would need to edit the file /etc/crontab to add the job to the system's main cron job manifest.  I BELIEVE the jobs you add in Plesk are run under a user account for Plesk, not the system account.  The error you received when you tried supports that idea.

>>> So If I set the restart interval to 86400 24 hours / seconds.

Yup.  Plesk will automatically restart Apache for you.  This is the alternative to editing /etc/crontab.
0
 

Author Comment

by:Cheryl Lander
ID: 18937639
But  dont have access to the etc/ folder in the cron. See list above.

Also just realised that the restart doesn't relate to restarting the apache server.
0
 
LVL 50

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 18942374
>>> dont have access to the etc/ folder in the cron.

I believe you are misunderstanding.  If you log in via SSH:

# cd /etc
# vi crontab

or

# vi /etc/crontab

You'll need to be logged in as root (or su'd) for the edit to take.  Once you edit the file, restart crond with:

# /etc/init.d/crond restart

>>> just realised that the restart doesn't relate to restarting the apache server.

Can you explain this a little more?
0
 

Author Comment

by:Cheryl Lander
ID: 19697630
This worked.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Fine Tune your automatic Updates for Ubuntu / Debian
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question