mqtt-halt-pack/run-on-pi.sh
2025-02-21 16:58:18 +01:00

39 lines
779 B
Bash
Executable file

#!/bin/bash
cd ~/mqtt-halt-pack || exit
# wait until network is ready
counter=0
max_counter=120
max_restart_counter=20
echo "$(date '+%Y%m%d%H%M%S'): checking connectivity"
while [ $(ping -q -w 3 -c 1 192.168.31.5 > /dev/null && echo 1 || echo 0) -eq 0 ]; do
if [ $counter -eq $max_counter ]; then
echo "$(date '+%Y%m%d%H%M%S') give up..."
exit 1
fi
let counter++
sleep 1
done
echo "$(date '+%Y%m%d%H%M%S'): starting client app"
source venv/bin/activate
restart_counter=0
while [ 1 -eq 1 ]; do
python client/client.py
if [ $restart_counter -eq $max_restart_counter ]; then
echo "$(date '+%Y%m%d%H%M%S') give up restarts..."
exit 1
fi
let restart_counter++
echo "$(date '+%Y%m%d%H%M%S'): restarting client app in 5 seconds..."
sleep 5
done