old-www/LDP/LG/issue32/tag_ping.html

253 lines
10 KiB
HTML

<!--startcut ======================================================= -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html><head>
<META NAME="generator" CONTENT="lgazmail v1.1preB">
<TITLE>The Answer Guy 32:
Conditional Execution Based on Host Availability
</TITLE>
<!-- ORIGINAL SUBJECT:
Online Status Detector
JTD SUBTITLE:
-->
</head>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#A000A0"
ALINK="#FF0000">
<H4>"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<H1 align="center"><A NAME="answer">
<img src="../gx/dennis/qbubble.gif" alt="" border="0" align="middle">
<a href="./index.html">The Answer Guy</a>
<img src="../gx/dennis/bbubble.gif" alt="" border="0" align="middle">
</A></H1>
<BR>
<H4 align="center">By James T. Dennis,
<a href="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</a>
<BR>Starshine Technical Services, <A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H4>
<p><hr><p>
<!--endcut ========================================================= -->
<H3><img src="../gx/dennis/qbub.gif" alt="(?)"
width="50" height="28" align="left" border="0"
>Conditional Execution Based on Host Availability</H3>
<p><strong>From the L.U.S.T Mailing List on 07 Aug 1998 </strong></p>
<!-- begin body -->
<pre>#!/path/to/perl
$ping = `ping -c 1 10.10.10.10`;
exec ("program") if $ping =~ /100\% packet loss/;
</pre>
<blockquote><img src="../gx/dennis/bbub.gif" height="28" width="50"
alt="(!)" border="0"
>What's wrong with a simple:
</blockquote>
<blockquote><blockquote><code
>ping -c 1 $target &amp;&amp; $do_something $target || $complain
</code></blockquote></blockquote>
<blockquote>... where you fill <tt>$do_something</tt> and <tt>$complain</tt> with
commands that you actually want to run on success or failure
of the '<tt>ping</tt>'.
</blockquote>
<blockquote>That's what shell "conditional execution operators"
(<tt>&amp;&amp;</tt> and <tt>||</tt>) are <EM>for</EM> after all.
</blockquote>
<strong><p><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0">or something similar with a shell script...
or, a quick socket program (probably a <EM>little</EM> easier on the system)
<br>john
</p></strong>
<blockquote><img src="../gx/dennis/bbub.gif" height="28" width="50"
alt="(!)" border="0">I don't know why any other socket operations would be
"easier on the system" than a single '<tt>ping</tt>' (ICMP echo request).
</blockquote>
<em><font color="navy"></blockquote>
<blockquote>&gt; Hi, </blockquote>
<blockquote>&gt; I'm looking for a program that can ping a host, and based on whether or not
<br>&gt; the host is unreachable execute a program. Anyone know of something like
<br>&gt; this, (or how to write one...)?
</blockquote>
<blockquote>&gt; Thanks for any help.
<br>&gt; -Corey
</blockquote>
</blockquote></font></em>
<!-- end body -->
<P> <hr width="40%" align="center"> <P>
<!-- ............................. -->
<H3><img src="../gx/dennis/qbub.gif" alt="(?)"
width="50" height="28" align="left" border="0"
>Failover and High Availability for Web Servers</H3>
<p><strong>From L.U.S.T List on 12 Aug 1998 </strong></p>
<!-- begin body -->
<strong><p>Re a command like: </p></strong>
<p><strong><code>ping -c 1 $host &amp;&amp; do_if_up || do_if_unreachable_or_down
</code></strong><p>
<em><font color="navy">
<strong><p>&gt; The orginal poster asked a very simple question with
<br>&gt; a very simple answer. He (or she) did not go into any
<br>&gt; details about his (or her) requirements.
</p></strong>
</font></em>
<p><strong>Jim,
</strong></p>
<p><strong>Thanks for your spirited post. It made my morning... <IMG SRC="../gx/dennis/smily.gif" ALT=":)" height="24" width="20" align="middle"> It's a
sure bet that if you ask a bunch of technical guys a simple
question, you're going to get about 10 different, complicated, and
lengthy answers.
</strong></p>
<p><strong>But, we do live in the real world, and the simplest answer is often
the best. Although I liked John Lampe's perl script because of its
flexibility, I think I'll be using the shell conditionals that you
proposed.
</strong></p>
<p><strong>In case you're curious, here's what I actually want to do... I have
a web server over here, and it's pretty important that it remains
up. PC's are cheap, so why buy one when you can have two for twice
the price? <IMG SRC="../gx/dennis/smily.gif" ALT=":)" height="24" width="20" align="middle"> I use IP aliasing for my important machine names,
"www" "mail" etc. I'd like the backup machine to ping the primary
machine. Should the primary machine stop responding, I'd like the
backup machine to run another script and pick up the important
aliases. As soon as the primary machine goes back up, the secondary
machine will drop the aliases and go back to its "waiting" state...
</strong></p>
<p><strong>The only part of this little mess I didn't know how to do was
execute a script based on the result of a ping... So that was all
that I asked. <IMG SRC="../gx/dennis/smily.gif" ALT=":)" height="24" width="20" align="middle"> Maybe next time I'll just lay out the whole thing
so nobody starts guessing.
</strong></p>
<p><strong>Anyhow, thanks to everyone who offered advice. I'm now able to
complete this project.
</strong></p>
<strong><p>-Corey
</p></strong>
<blockquote><img src="../gx/dennis/bbub.gif" height="28" width="50"
alt="(!)" border="0"
>This set of requirements is pretty common --- common enough
to have a name: "failover"
</blockquote>
<blockquote>I'd suggest that you assign each of these two systems
<EM>two</EM> IP addresses (one on each can be from RFC1918 ---
something like <tt>192.168.1.*</tt>). We'll call that the "control
address" and the one that the web server is on the "service
address." Now, when you detect a failure on the service address
you take it over (address assumption). You can then
get messages from the control address to let your failover
host know that the other system is back up and running
--- which is when you relinquish control of that address.
</blockquote>
<blockquote>Naturally you can expect some discontinuities in sessions that
were running at failover point. Luckily normal HTTP is
pretty robust and stateless --- so it should be O.K. for that.
If you are running complex systems of CGI scripts which maintain
state via local temp files, you might have some problems with
this simple failover approach.
</blockquote>
<blockquote>Look for the "High Availability HOWTO" for some other ideas
on this.
</blockquote>
<blockquote>In addition I recommend that you look at the <tt>panic=</tt> kernel
parameter and that you consider running your web servers
out of your inittab (so that 'init' will automatically
respawn them as necessary). You can also consider configuring
the built-in watchdog support (re-compile your kernel) and
even installing a hardware watchdog timer card.
</blockquote>
<blockquote>A WDT (watchdog timer) is basically a "deadman's switch" for
your computer. Once initialized it must be updated periodically
(by the kernel or some daemon) or it will trigger the reset
line on your system bus.
</blockquote>
<!-- end body -->
<!--startcut ======================================================= -->
<P> <hr> <P>
<H5 align="center"><a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 1998, James T. Dennis <BR>
Published in <I>Linux Gazette</I> Issue 32 September 1998</H5>
<P> <hr> <P>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<table width="98%"><tr valign="center" align="center">
<td rowspan="3"><A HREF="./lg_answer32.html"><IMG
SRC="../gx/dennis/answernew.gif"
ALT="[ Answer Guy Index ]"></A></td>
<td><A HREF="tag_phreak.html">phreak</A>
<td><A HREF="tag_abandon.html">abandon</A>
<td><A HREF="tag_javaterm.html">javaterm</A>
<td><A HREF="tag_BBS.html">BBS</A>
<td><A HREF="tag_flaws.html">flaws</A>
<td><A HREF="tag_doslinux.html">doslinux</A>
<td><A HREF="tag_resume.html">resume</A>
</tr><tr valign="center" align="center">
<td><A HREF="tag_softwindows.html">softwindows</A>
<td><A HREF="tag_convert.html">convert</A>
<td><A HREF="tag_apache.html">apache</A>
<td><A HREF="tag_emulate.html">emulate</A>
<td><A HREF="tag_database.html">database</A>
<td><A HREF="tag_distrib.html">distrib</A>
<td><A HREF="tag_proxy.html">proxy</A>
</tr><tr valign="center" align="center">
<td><A HREF="tag_disable.html">disable</A>
<td><A HREF="tag_DVI.html">DVI</A>
<td><A HREF="tag_superblock.html">superblock</A>
<td><A HREF="tag_serial.html">serial</A>
<td><A HREF="tag_permission.html">permission</A>
<td><A HREF="tag_detach.html">detach</A>
<td><A HREF="tag_cdr.html">cdr</A>
</tr><tr valign="center" align="center">
<td><A HREF="tag_rs422.html">rs422</A>
<td><A HREF="tag_modem.html">modem</A>
<td><A HREF="tag_notfound.html">notfound</A>
<td><A HREF="tag_tuning.html">tuning</A>
<td><A HREF="tag_libc5.html">libc5</A>
<td><A HREF="tag_startup.html">startup</A>
<td><A HREF="tag_clock.html">clock</A>
<td><A HREF="tag_ping.html">ping</A>
</tr><tr valign="center" align="center">
<td><A HREF="tag_accounts.html">accounts</A>
<td><A HREF="tag_lilo.html">lilo</A>
<td><A HREF="tag_NDS.html">NDS</A>
<td><A HREF="tag_95slow.html">95slow</A>
<td><A HREF="tag_nonlinux.html">nonlinux</A>
<td><A HREF="tag_progenv.html">progenv</A>
<td><A HREF="tag_cluster.html">cluster</A>
<td><A HREF="tag_ftpd.html">ftpd</A>
</tr></table>
<P> <hr> <P>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-->
<A HREF="./index.html"><IMG SRC="../gx/indexnew.gif"
ALT="[ Table Of Contents ]"></A>
<A HREF="../index.html"><IMG SRC="../gx/homenew.gif"
ALT="[ Front Page ]"></A>
<A HREF="lg_bytes32.html"><IMG SRC="../gx/back2.gif"
ALT="[ Previous Section ]"></A>
<A HREF="./stemen.html"><IMG SRC="../gx/fwd.gif"
ALT="[ Next Section ]"></A>
<!--::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::-->
</body>
</html>
<!--endcut ========================================================= -->