Solved

how to restart apache via cron

Posted on 2007-04-06
16
3,565 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
 
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Notice: Undefined variable 5 56
VMWare 6 crashing 14 57
a free alternative to cpanel? 1 39
Codiing Non-Existent Links 4 30
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now