LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-30-2010, 11:50 AM   #1
Devisz
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Rep: Reputation: 0
Question 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
 
Old 12-30-2010, 11:54 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Use cron ?
 
Old 12-30-2010, 12:37 PM   #3
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
crontab + killall
 
Old 12-30-2010, 12:47 PM   #4
Devisz
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 12-30-2010, 01:25 PM   #5
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
You need spaces between the values you filled in.

Code:
0 */2 * * *  /etc/init.d/apache2 restart
 
Old 12-30-2010, 01:29 PM   #6
Devisz
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 0
damn, couldn't figure there was a space in all guides i've found

Works now, thanks a lot for helping
 
Old 12-30-2010, 01:34 PM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by Devisz View Post
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.
 
1 members found this post helpful.
Old 12-30-2010, 04:11 PM   #8
Devisz
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
Old 12-31-2010, 12:42 PM   #9
w1k0
Senior Member
 
Registered: May 2008
Location: Poland
Distribution: Slackware (personalized Window Maker), Mint (customized MATE)
Posts: 1,309

Rep: Reputation: 234Reputation: 234Reputation: 234
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.
 
Old 01-01-2011, 04:57 AM   #10
TheVillageIdiot
LQ Newbie
 
Registered: Sep 2003
Posts: 9

Rep: Reputation: 0
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.
 
Old 01-03-2011, 05:55 AM   #11
ashish_neekhra
Member
 
Registered: Nov 2007
Posts: 67

Rep: Reputation: 4
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.

Last edited by ashish_neekhra; 01-03-2011 at 05:59 AM.
 
Old 01-05-2011, 04:21 PM   #12
Devisz
LQ Newbie
 
Registered: Dec 2010
Posts: 5

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
kill process more than 3 hours old from shell command saiyen2002 Programming 7 11-16-2010 04:33 AM
Automatically restart killed process i_nomad Red Hat 2 10-27-2008 07:56 AM
need help to write script to check the process health and automatically restart it dragondad Programming 3 11-01-2006 12:23 PM
Need to kill process 48 hours old captnz Programming 5 09-30-2004 03:07 AM
After restart time jumps 7 hours mlbaker Linux - General 4 03-22-2003 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration