blob: ac913021f0f9283b7729a3192293c7557b6595da [file] [log] [blame]
#!/bin/sh
#
# Try to detect when the optical link gets into an unrecoverable state and
# attempt to reboot the system to recover it.
# Workaround for b/32097608 until a better solution can be found.
. /etc/utils.sh
GPON_ALARM_FILE="/sys/devices/platform/gpon/info/alarmGpon"
GPON_INFO_FILE="/sys/devices/platform/gpon/info/infoGpon"
WARN1_TIME=60 # seconds
WARN2_TIME=120 # seconds
REBOOT_TIME=180 # seconds
is_optical_link_up() {
if [ ! -e "$GPON_INFO_FILE" ]; then
echo "$GPON_INFO_FILE does not exist yet!"
return 1
fi
x=$(cat "$GPON_INFO_FILE" | grep "ONU STATE")
contains "$x" "OPERATION"
}
START_TIME=$(date +%s)
while true; do
if [ ! -e "$GPON_ALARM_FILE" ]; then
echo "$GPON_ALARM_FILE does not exist yet! Optical stack not running?"
exit 1
fi
los_bit=$(cat "$GPON_ALARM_FILE" | grep "LOS")
if contains "$los_bit" "ON"; then
echo "LOS alarm is ON! Cable unplugged? Stopping the reboot timer!"
exit 1
fi
if is_optical_link_up; then
echo "Optical link is up! Stopping the reboot timer!"
exit 1
fi
# Default sleep for 30 seconds then sleep for a random interval up to an
# additional 30 seconds.
sleep 30
sleep $(randint 30)
CURR_TIME=$(($(date +%s) - START_TIME))
if [ "$CURR_TIME" -ge "$REBOOT_TIME" ]; then
echo "Optical link is STILL DOWN after $CURR_TIME seconds..."
echo "OPTICAL WATCHDOG IS REBOOTING THE SYSTEM NOW!"
reboot
elif [ "$CURR_TIME" -ge "$WARN2_TIME" ]; then
echo "Optical link NOT UP after $CURR_TIME seconds! Will reboot soon..."
elif [ "$CURR_TIME" -ge "$WARN1_TIME" ]; then
echo "Optical link is not up after $CURR_TIME seconds..."
fi
done
# Make sure that babysitter always restarts us.
exit 1