how to restart apache via cron

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
Cheryl LanderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
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
Cheryl LanderAuthor Commented:
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
Cheryl LanderAuthor Commented:
ive just tried it under the apache option and doesnt work either.
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

samriCommented:
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
Cheryl LanderAuthor Commented:
The time of 3.10pm was done as a test to see if it works.

But it didnt.
0
Cheryl LanderAuthor Commented:
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
Steve BinkCommented:
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
Cheryl LanderAuthor Commented:
I have full root access the server.
0
Steve BinkCommented:
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
Cheryl LanderAuthor Commented:
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
Steve BinkCommented:
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
Cheryl LanderAuthor Commented:
I can log in via ssh with root.

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

is this correct.
0
Steve BinkCommented:
>>> 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
Cheryl LanderAuthor Commented:
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
Steve BinkCommented:
>>> 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cheryl LanderAuthor Commented:
This worked.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.