How to automatically restart a process every few hours ?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to automatically restart a process every few hours ?
Hello
I'm having a VPS using Ubuntu 10.4 and i would like a guide on how to restart apache2 process every few hours (a time determined by me). I've already searched on google and couldn't find anything for beginners after pretty many searches.
Tried the guide and searched for some other guides with 'every x hours'
user command crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
cron"/tmp/crontab.NkKl0W/crontab":1: bad hour
errors in crontab file, can't install.
tDo you want to retry the same ey
crontab: installing new crontab
"/tmp/crontab.NkKl0W/crontab":1: bad hour
errors in crontab file, can't install.
in crontab i have this
# m h dom mon dow command
0*/2*** /etc/init.d/apache2 restart
...and in addition to what's been posted already your web server is not the type of service that should require regular restarting every few hours. If this is an attempt to stabilize the situation caused by something completely different then you should realize fixing symptoms is not like fixing the cause. If there is then you best create a new thread for it.
Still a newb... but i'd thought i'd post a comment.
Completely agree with unSpawn there... gotta say that fixing the underlying problem is where you should be spending your time.
Also, to the OP: My Centos system keeps cron logs in /var/log/
Which is useful for seeing whether it ran a command... although more specifically, it will email root if there are any problems. Checking your emails - try running "mail" - might help you out a little with cron.
Just my 2c.
If im wrong... hopefully the Regs will let me know.
Make a small script named "apache.sh" with below content;
/etc/init.d/apache2 restart
Now save & exit .
Next move this script in to the "/etc/cron.hourly" folder by "mv" command.
This will run your script hourly basis. & If you want to execute it in some defined interval of time.
* */<No of Hours> * * * /etc/init.d/apache2 restart
save & exit. Now restart your "cron" service.
/etc/init.d/cron restart
Hope this will help you.
Last edited by ashish_neekhra; 01-03-2011 at 05:59 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.