NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
rc.local nightmare
Hi all,
I am using a raspberrypi and NetBSD 10-BETA and as we all know the flaky
bwfm wifi driver is not very stable. Sometimes network fails and
"ifconfig bwfm0 down" and "ifconfig bwfm0 up" does not fix it, so the
raspberrypi remains unreachable from SSH, needing a physical reboot.
I have written a little script that checks ping to a known site and
reboots the machine if it fails after several retries:
*******************************************
netbsd-nuc# cat /etc/rc.local
# $NetBSD: rc.local,v 1.32 2008/06/11 17:14:52 perry Exp $
# originally from: @(#)rc.local 8.3 (Berkeley) 4/28/94
#
# This file is (nearly) the last thing invoked by /etc/rc during a
# normal boot, via /etc/rc.d/local.
#
# It is intended to be edited locally to add site-specific boot-time
# actions, such as starting locally installed daemons.
#
# An alternative option is to create site-specific /etc/rc.d scripts.
#
echo -n 'Starting local daemons:'
# Add your local daemons here, eg:
#
#if [ -x /path/to/daemon ]; then
# /path/to/daemon args
#fi
if [ -x /root/nettest ]; then
/root/nettest &
fi
echo '.'
*******************************************
This is the script:
*******************************************
netbsd-nuc# cat /root/nettest
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
# Define the IP address or hostname to test connectivity to
TARGET="www.netbsd.org"
# Define the number of retries before rebooting
RETRIES=2
# Define the time interval (in seconds) between each retry
INTERVAL=10
# Counter to keep track of failed attempts
FAILED=0
# Function to test network connectivity
check_connectivity() {
if ping -c 1 $TARGET > /dev/null 2>&1; then
echo "Network connectivity to $TARGET is OK."
return 0
else
echo "Network connectivity to $TARGET is not available."
return 1
fi
}
# Main loop
while [ $FAILED -lt $RETRIES ]; do
if check_connectivity; then
# If connectivity is successful, reset the failed counter
FAILED=0
else
# If connectivity fails, increment the failed counter
FAILED=$((FAILED + 1))
echo "Retry $FAILED of $RETRIES..."
fi
sleep $INTERVAL
done
# If we reach here, all connectivity retries failed, so reboot the machine
echo "All connectivity retries failed..."
echo "logging date and uptime..."
touch /root/network_conn_test.log
echo "reboot at:" >> /root/network_conn_test.log
date >> /root/network_conn_test.log
uptime >> /root/network_conn_test.log
echo "All connectivity retries failed. Rebooting..."
shutdown -r now
*******************************************
The script works fine if I run manually:
#/root/nettest
or even If I do this it works fine:
#service local restart
But If I reboot the machine the script starts during booting but I dies
very soon.
I do not understand what is happening here. I know that the proper way
is writing a rc.d service but I am just curious to know the reason.
Thanks so much.
Regards.
Ramiro.
Home |
Main Index |
Thread Index |
Old Index