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. Thanks in advance |
Use cron ?
|
crontab + killall
|
Thank you for the answer
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 |
You need spaces between the values you filled in.
Code:
0 */2 * * * /etc/init.d/apache2 restart |
damn, couldn't figure there was a space in all guides i've found
Works now, thanks a lot for helping |
Quote:
|
how do i know if the chron job does it's work ?
because till now it seems it didn't restarted apache. where i can see if it's working ? Thank you |
Add to your crontab the following line:
Code:
* * * * * touch /tmp/crontab.test |
Heya Guys,
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. :) |
Hey Devisz,
Simply you can do one thing, 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. |
Hello and thank you for your answers
I've managed to test it thorugh a output txt file and works fine Have a nice day and thanks again for the help |
All times are GMT -5. The time now is 03:32 PM. |