LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to automatically restart a process every few hours ? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-automatically-restart-a-process-every-few-hours-853303/)

Devisz 12-30-2010 11:50 AM

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

AlucardZero 12-30-2010 11:54 AM

Use cron ?

yooy 12-30-2010 12:37 PM

crontab + killall

Devisz 12-30-2010 12:47 PM

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

AlucardZero 12-30-2010 01:25 PM

You need spaces between the values you filled in.

Code:

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

Devisz 12-30-2010 01:29 PM

damn, couldn't figure there was a space in all guides i've found

Works now, thanks a lot for helping

unSpawn 12-30-2010 01:34 PM

Quote:

Originally Posted by Devisz (Post 4208007)
how to restart apache2 process every few hours

...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.

Devisz 12-30-2010 04:11 PM

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

w1k0 12-31-2010 12:42 PM

Add to your crontab the following line:

Code:

* * * * * touch /tmp/crontab.test
and check the date of /tmp/crontab.test file after a few minutes.

TheVillageIdiot 01-01-2011 04:57 AM

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. :)

ashish_neekhra 01-03-2011 05:55 AM

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.

Devisz 01-05-2011 04:21 PM

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.