Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Just want someone to confirm this is the correct cron configuration to have the server restart Apache every Sunday night. I have never done a cron command which had a space in it, so want to make sure it's correct.

0 3 * * 0 /bin/sh /usr/sbin/apachectl restart
share|improve this question

2 Answers 2

up vote 3 down vote accepted

To begin with, why are you restarting Apache on a cron - furthermore why with a SIGKILL (restart) statement rather than SIGHUP (graceful)

This is a much "friendlier" means of restarting Apache, so that you don't kill off existing sessions.

/usr/sbin/apachectl graceful

Your cron will kill and start Apache at 3am on Sunday.

Bear in mind, different OS'es have different possible notation for Sunday on a crontab - it could be any of:

0 3 * * sun
0 3 * * 0
0 3 * * 7

And if you don't want to be harassed via email, you can discard STERR and STOUT by appending this to the end of your command

> /dev/null 2>&1
share|improve this answer
    
Thanks. I know it's not the best thing but there is some Apache connection which keeps crashing the server, so hoping this is a temp fix until we can migrate off. –  Louis W Jun 27 '12 at 17:58
1  
A better solution (short of fixing the root cause) would be to use a watchdog application like monit –  MageStackDay Needs You ... Jun 27 '12 at 18:46

Looks fine to me, I guess. You might want to redirect output somewhere, even if it's just /dev/null. Otherwise cron will start trying to email you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.