# Need to have cron restart apache every hour

## audiodef

I've tried a couple of things to get cron to restart apache every hour, as it seems to hang frequently lately (yes, I know I should fix the actual problem, and I will, but I have too much on my plate right now). 

I have fcron. What script should I use to force apache to restart every hour, and where do I put this script?

----------

## eccerr0r

Unfortunately I don't use fcron.

For vixie-cron, which may be similar to fcron (if it also uses sys-process/cronbase which it very well might), it might be as simple as adding a script file that looks like (for openrc, not valid for systemd)

 */etc/cron.hourly/apache-restarter wrote:*   

> #!/bin/bash
> 
> /etc/init.d/apache2 restart
> 
> 

 

----------

## Jaglover

This was the first hit in Google:

http://unix.stackexchange.com/questions/881/ensure-a-process-is-always-running

I personally use daemontools to keep processes that tend to crash running.

----------

## eccerr0r

Need to keep in mind the difference between a dying process and a hanging process...

I also question my solution whether that initscript will kill all children, you might need to do

 */etc/cron.hourly/apache-restarter-version-2 wrote:*   

> #!/bin/bash
> 
> /etc/init.d/apache2 stop
> 
> killall apache2
> ...

 

Ugh...Very ugly...

Fix your apache, not bandage it!  :Very Happy: 

----------

## audiodef

I appreciate the replies. Thanks! I agree, fixing it is best. I'll look into it some more.   :Smile: 

----------

## skunk

did you try lowering MaxRequestsPerChild?

restarting apache is a ugly hack and it won't always work because sometimes hung apache processes take a long time to get killed...

----------

## audiodef

That might help. What would a good value other than 0 or 10000 be?

----------

## skunk

anything in between? try with 2000...

----------

## eccerr0r

I would think you would want something like 4 or 5 at most... 

But I don't know the nature of the problem you're having...

----------

## Navar

Are you having DoS due to slow http attacks?

----------

## audiodef

I noticed that stable Apache, PHP and MySQL in Portage were all well behind the official latest stable releases from those projects (latest stable MySQL isn't even in Portage), so I upgraded all those. I'm going to see if that takes care of things.

----------

