Ticket #1128 (new)

Opened 5 years ago

Last modified 5 years ago

Ping watchdog for telecontrol

Reported by: Musti Owned by: Musti
Priority: normal Milestone:
Component: telemetry Version:
Keywords: Cc:
Related nodes: Realization state:
Blocking: Effort: normal
Blocked by: Security sensitive: no

Description

Develop a ping watchdog that triggers a reset of a specified channel via readsensor communication script.

Resets after 15min if more then 90% packet loss.

Attachments

ping-watchdog.sh (492 bytes) - added by ziga.z 5 years ago.

Change History

comment:1 Changed 5 years ago by Musti

Solution developed by ziga.z

Pings every second, after 1000pings (or wahtever is set) the script will send reset if more then 90% packet loss or if not restart itself. It does not restart after a reset.

#!/bin/ash
# usage: test.sh 192.168.1.99 5

IP=$1
# IP as first argument

PING_COUNT=1000
# 1000s = 16 min, 40 seconds

PING_TIMEOUT=1
# wait max 1 second for reply

IARG=$2
# readsensor argument

PACKET_LOSS=`ping -c $PING_COUNT -W $PING_TIMEOUT $IP | grep 'packet loss' | cut -d% -f 1 | cut -d" " -f7`
if [ $PACKET_LOSS -gt 90 ]; then
  readsensor -d /dev/ttyS0 -i $IARG -s 0
  sleep 5
  readsensor -d /dev/ttyS0 -i $IARG -s 1
else
  sleep 10
  `which ash` $0 "$@"
fi

comment:2 Changed 5 years ago by kostko

This line seems suspect:

`which ash` $0 "$@"

I see that you want to run the watchdog over and over, but you are instantiating more and more shell script interpreters as the parent process never finishes. This is bad as it uses more and more resources.

Why don't you use a loop – something like:

while (( 1 )); do
  PACKET_LOSS=`ping ...`
  if [ $PACKET_LOSS -gt 90 ]; then
    readsensor ...
    sleep 5
    readsensor ...
    break
  else
    sleep 10
  fi
done

Changed 5 years ago by ziga.z

Note: See TracTickets for help on using tickets.