LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-21-2008, 12:59 PM   #1
rahedbd
LQ Newbie
 
Registered: May 2008
Posts: 3

Rep: Reputation: 0
Linux service


Hi I have a server which can communicate with clients using TCP protocol. The server may crash anytime, so I need to restart my server automatically, How can I do that?
 
Old 05-21-2008, 01:26 PM   #2
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu ; CentOS ; Raspbian
Posts: 12,613

Rep: Reputation: 69
A watchdog timer? Do you mean have it automatically reboot at specific intervals, auto-reboot after a crash, or send you an automatic email so you can reboot it?

-Chad
 
Old 05-22-2008, 02:08 AM   #3
rahedbd
LQ Newbie
 
Registered: May 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks for ur reply.

I want may be another process look for my server in process list whether it is running or not if it doesn't run then the Monitor process will restart my server. but my problem is that if I restart the process with exec of C then the server can't communicate through the port.


So plz if u have any suggestion let me know.
 
Old 05-22-2008, 04:17 AM   #4
digvijay.gahlot
Member
 
Registered: Mar 2008
Posts: 53

Rep: Reputation: 15
You can make a shell script. The algo may look like this.
while(1)
{
if(!pgrep <Your process name>)
restart your server
sleep <amount of seconds you should wait to recheck>
}

put the script in your rc.local file.

I hope somebody with good scripting knowledge will provide a better ans.
 
Old 05-27-2008, 10:36 AM   #5
DotHQ
Member
 
Registered: Mar 2006
Location: Ohio, USA
Distribution: Red Hat, Fedora, Knoppix,
Posts: 548

Rep: Reputation: 33
Hangcheck timer might do the trick for you. We use it with Oracle DB's and it works for us.
 
Old 05-27-2008, 06:54 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Another alternative is to use cron as the timing mechanism instead of writing a daemon, otherwise that script (post 4) will do an infinite loop and the system won't start.
If you want to write a daemon, use

nohup yourdaemon >/somedir/yourdaemon.log 2>&1 &
 
Old 05-27-2008, 11:02 PM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Ubuntu 12.04, Antix19.3
Posts: 3,794

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by rahedbd View Post
Thanks for ur reply.

I want may be another process look for my server in process list whether it is running or not if it doesn't run then the Monitor process will restart my server. but my problem is that if I restart the process with exec of C then the server can't communicate through the port.


So plz if u have any suggestion let me know.
And what is the error when you try to restart?

If it's a program that you wrote yourself, it's more advisable to have a look why the program crashes and fix it. If it's a program that's written by someone else, inform him/her so it can be fixed.
 
Old 05-29-2008, 07:22 AM   #8
rahedbd
LQ Newbie
 
Registered: May 2008
Posts: 3

Original Poster
Rep: Reputation: 0
thanks chrism01 I have solved my problem using script.

But now my problem is after executing the script that contains

nohup yourdaemon >/somedir/yourdaemon.log 2>&1 & command when I use top command it shows that my server.exe takes always 100% cpu in a dual core machine.

and when I use the kill pid command it can't kill the process.

thanks for any help.
 
Old 05-29-2008, 07:29 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, it's getting started by root if its in rc.local, so you'd have to be root to stop it.
If you look at top, it'll show you who owns the process.
The 100% cpu usage is down to your code, you'll have to debug it.
My cmd just starts it in the background (final &) and detaches from the terminal/current process (nohup).
 
  


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
How to make TCP server a daemon / service much like a dhcpd service? rajat Linux - Networking 1 05-22-2007 01:29 AM
Making a service as a system service Dakkar SUSE / openSUSE 2 07-13-2005 07:36 AM
/sbin/service is empty every weekend and changed to service.1 LineS Linux - General 0 05-24-2004 02:08 AM
Linux PC not getting name service shorttimer Linux - Networking 4 03-13-2003 04:38 PM

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

All times are GMT -5. The time now is 07:05 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