LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux service (https://www.linuxquestions.org/questions/linux-newbie-8/linux-service-643839/)

rahedbd 05-21-2008 12:59 PM

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?

MasterC 05-21-2008 01:26 PM

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

rahedbd 05-22-2008 02:08 AM

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.

digvijay.gahlot 05-22-2008 04:17 AM

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.

DotHQ 05-27-2008 10:36 AM

Hangcheck timer might do the trick for you. We use it with Oracle DB's and it works for us.

chrism01 05-27-2008 06:54 PM

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 &

Wim Sturkenboom 05-27-2008 11:02 PM

Quote:

Originally Posted by rahedbd (Post 3161114)
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.

rahedbd 05-29-2008 07:22 AM

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.

chrism01 05-29-2008 07:29 PM

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


All times are GMT -5. The time now is 08:24 AM.