Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to restart apache via cron

Posted on 2007-04-06
16
Medium Priority
?
3,715 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 6
16 Comments
 
LVL 51

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
AWS Certified Solutions Architect - Associate

This course has been developed to provide you with the requisite knowledge to not only pass the AWS CSA certification exam but also gain the hands-on experience required to become a qualified AWS Solutions architect working in a real-world environment.

 
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 51

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 51

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 51

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 51

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 51

Accepted Solution

by:
Steve Bink earned 2000 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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

670 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