Cron job to restart Apache every N hours Ubuntu 10.4

I searched the forums and didn't find anything:

http://forum.linode.com/search.php?keyw … mit=Search">http://forum.linode.com/search.php?keywords=cron+apache+restart&terms=all&author=&sc=1&sf=all&sk=t&sd=d&sr=posts&st=0&ch=300&t=0&submit=Search

Using Ubuntu 10.4, and would like to restart Apache every hour (for example).

This is not optimal solution, but I inherited a mess of a server and in the short term (while we figure out the REAL problem) we would like to recycle Apache once per hour. This does not really have an effect on our users as the site is mostly read only.

I'm a little weak in the CRON department, and would like to figure out a starting point.

Thanks in advance for your help!

-mxadmin

8 Replies

As root run crontab -e then add the following line

0 * * * * * /etc/init/apache2 restart

Save the crontab and then run restart cron

Once you've fixed your problem just remove that line and restart cron again.

I agree with the general approach suggested by obs, but think there are a few typos in there, and would suggest running

crontab -e

and adding the following line

0 * * * * /etc/init.d/apache2 restart

(or you could use the following syntax instead)

@hourly /etc/init.d/apache2 restart

and then save the file and exit the editor. To disable this, just run crontab -e again and remove the line you added, save, and exit.

It should not be necessary to restart cron.

(man 5 crontab will tell you about the available syntax and give examples.)

Are you sure? At some point, Ubuntu got rid of crontab and the necessity to restart anything.

…Ok yeah I hadn't had my morning cup of tea yet when I wrote that….

You're right, I'm remembering some other cron-related change in Ubuntu.

If cron were to go away I'd leave Ubuntu and go to straight Debian or if that didn't work out

I'd go back to some RPM based distro.

If Linode stopped offering VPS service, I'd probably have to ditch them and go to Amazon; if that didn't work out, it's totally OpenVZ time.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct