-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwatchdog.sh
executable file
·53 lines (40 loc) · 1.16 KB
/
watchdog.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Watchdog script for Ryde with Longmynd
# Initialise
RESTART_REQUIRED=NO
# Do not start script until Ryde has had time to startup
sleep 15
while true
do
# Check Ryde is running
pgrep -f rydeplayer >/dev/null 2>/dev/null
RESULT="$?"
if [ "$RESULT" -ne 0 ]; then
RESTART_REQUIRED=YES
fi
# Check the Ryde watchdog file if it exists
if test -f "/home/pi/tmp/rydePlayer.pid"; then
# Check that the Ryde Watchdog file has been updated in the last 10 seconds
CURRENT_SECONDS=`date +%s`
LAST_MODIFIED_SECONDS=`stat -c "%Y" /home/pi/tmp/rydePlayer.pid`
if [ $(($CURRENT_SECONDS-$LAST_MODIFIED_SECONDS)) -gt 10 ]; then
RESTART_REQUIRED=YES
fi
fi
# Check if restart required and action
if [ "$RESTART_REQUIRED" = "YES" ]; then
# Kill existing python3 and longmynd processes
sudo killall python3
sudo killall longmynd
sleep 5
# Restart rydeplayer
/home/pi/ryde-build/rx.sh &
# Wait 10 seconds for restart
sleep 10
# Reinitialise
RESTART_REQUIRED=NO
fi
# Wait 5 seconds before next check
sleep 5
done
exit