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?
|
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 |
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. |
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. |
Hangcheck timer might do the trick for you. We use it with Oracle DB's and it works for us.
|
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 & |
Quote:
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. |
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. |
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. |