Some help needed with my init script
I've got a script which continually pings two IP addresses, in the event of either failing, a piece of software is restarted and details are logged. This is meant to run as a background process and only allow single instances of the ping one liner'. Specifically this does not work - can someone help me troubleshoot - thanks.
Code:
ROUTER="10.161.1.1 10.161.1.2" |
What are the symptoms of "does not work"?
|
When I exit the script running from ssh, the ping stops. The behaviour is not the same when run via init; not sure if this is a suitable way to run it...
|
There are two issues I can see:
|
The ping actually keeps the link up. I'll give your suggestions a try though and tell you if it still works, thanks :)
|
Quote:
Like I wrote above, your script should simply regularly call ping -c 1 -w seconds host in a loop, not keep pinging on the background. Whenever the command fails, restart opennhrp, then re-start the pinging loop. The optimal delay (sleep in the loop) depends on what you consider a failure -- a single ping might get lost now and then, so maybe three or four successive failures constitute a downed link? --, and the maximum interval between pings when keeping the connection alive. Remember that in your script, the true maximum ping interval is the ping timeout PLUS the sleep duration. Do you want to see a skeleton Bash script I'd personally start with? |
OK, it seems to instantly terminate when I run this and then enter a loop; output is as follows (infinitely):
Code:
/etc/init.d/pingcheck: line 5: 16133 Terminated setsid nohup /bin/ping -c 1 -w 5 $IP < /dev/null > /dev/null 2> /dev/null |
Found potentially another problem, if the init script is started while opennhrp is being restarted (no pings running) then it will start an additional instance. I'm interested in your skeleton script, although don't want to have to rework my entire script... The basics are very similar, ping one host, then ping another if both fail restart something and try again after a short delay.
|
First, you need to separate your init script and the actual daemon.
Assume you have /etc/pingcheck.conf with Code:
# This is pingcheck configuration file, Code:
#!/bin/bash The "all pings successful" if clause is actually not needed. I included it to make it easier for you to edit or add conditions to suit your needs; this way the success case is explicitly handled correctly. In the init script, use ps -o pid= -C pingcheck to get the PID of the running daemon. It will return nothing if the daemon is not running. To terminate the script, just send it a TERM signal; i.e. Code:
pid=$(ps -o pid= -C pingcheck) Code:
sudo sh -c '( setsid /usr/local/bin/pingcheck </dev/null >/dev/null 2>/dev/null & )' Code:
( setsid /usr/local/bin/pingcheck </dev/null >/dev/null 2>/dev/null & ) |
Wow - thanks for your help :) I'll give it a shot.
|
Quote:
The init script needed to start, restart, stop, or query the status of the daemon is very simple, very similar to your original init script. If the daemon script works for you, then we can easily edit your init script to control the daemon script instead. |
This worked a treat, big thanks for your help.
|
All times are GMT -5. The time now is 07:41 AM. |