Hah! I think we got it! Thank you so much!
But first. I think I know what you were getting at, but I don't think that code does what you intended. Your code only executes the ping command if the original precmd does not exist. I want to execute it regardless, and might as well do it first, since we can stop as soon as we know it if we have to stop.
So - what I changed it to is this:
Code:
old_start_precmd="$start_precmd"
start_precmd="ping_test"
ping_test() {
ping -W 3000 -qnc 1 8.8.8.8 || return 1
if [ -n "$old_start_precmd" ]
then
$old_start_precmd || return 1
fi
}
That works, but then I thought I'd optimize it a bit. I only need to do the ping test for the first of the four dependent services. Also, if the link should happen to come up during this time, I don't want it to try to start the later services because they depend on the earlier ones. So, I ran rcorder to verify the sequence, which is as follows:
pf 78
ntpdate 115
named 118
ntpd 141
{As a side note, I also get a warning/error from rcorder:
rcorder: file `/usr/local/etc/rc.d/saslauthd' is before unknown provision `imap' - is this something that should be reported?}
Then I created two environment files - one for doing a ping test, and the others doing a file test based on the ping test.
linkprecmdping
Code:
old_start_precmd="$start_precmd"
start_precmd="linkping_test"
linkping_test() {
if ping -W 3000 -qnc 1 8.8.8.254 > /tmp/linkpingfile ; then
rm /tmp/linkpingfile
else
return 1;
fi
if [ -n "$old_start_precmd" ]
then
$old_start_precmd || return 1
fi
}
and
linkprecmdfile
Code:
old_start_precmd="$start_precmd"
start_precmd="linkfile_test"
linkfile_test() {
if [ -e /tmp/linkpingfile ] ; then
return 1;
fi
if [ -n "$old_start_precmd" ]
then
$old_start_precmd || return 1
fi
}
The end of my /etc/rc.conf file now looks like this:
rc.conf
Code:
pf_env_file="/root/linkprecmdping"
ntpdate_env_file="/root/linkprecmdfile"
named_env_file="/root/linkprecmdfile"
ntpd_env_file="/root/linkprecmdfile"
With the "bad" IP address in the ping test, we get
root@casper:~ # service pf start
root@casper:~ # service ntpdate start
root@casper:~ # service named start
/usr/local/etc/rc.d/named: WARNING: failed precmd routine for named
root@casper:~ # service ntpd start
/etc/rc.d/ntpd: WARNING: failed precmd routine for ntpd
root@casper:~ #
With the "good" IP address in the ping test, we get
root@casper:/home/john # service pf start
Enabling pf.
root@casper:~ # service ntpdate start
Setting date via ntp.
30 Jan 15:26:01 ntpdate[22262]: step time server 193.29.63.226 offset +0.000223 sec
root@casper:~ # service named start
Starting named.
root@casper:~ # service ntpd start
Starting ntpd.
In support of this, I have
ppp.linkup
Code:
CenturyLink:
!bg /root/linkupservices
and /root/linkupservices
Code:
service pf start
service ntpdate start
service named start
service ntpd start
Running out of time and ambition today, but I'll try this with the actual PPP link tomorrow.
Again - thanks!!!