-
Notifications
You must be signed in to change notification settings - Fork 2
/
pp_respawn
42 lines (30 loc) · 1.14 KB
/
pp_respawn
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
#!/bin/bash
# Program: pp_respawn
# Purpose: helper script for starting up and respawning the software for the power plant
DSSC="dssc.py"
while true; do
timestamp=`date "+%Y-%m-%d %H:%M:%S"`
echo "$0: Startup ($timestamp)"
# socat server for communication with volkszaehler
#
echo "$0: Checking for socat server."
port=`netstat -tulpen 2>/dev/null | grep socat | awk '{ print $4}' | awk -F ':' '{print $2}'`
if [ "$port" != "12345" ]; then
echo "$0: No socat server found listening at port 12345"
echo " - creating file /tmp/dpm86_current_power.txt"
touch /tmp/dpm86_current_power.txt
echo " - starting socat server"
nohup socat TCP4-LISTEN:12345,reuseaddr,fork EXEC:"cat /tmp/dpm86_current_power.txt",nofork,end-close &
else
echo "$0: Socat seems to listening at port 12345."
fi
# dssc
#
echo "$0: Killing maybe leftover dssc instances ($DSSC)."
killall -TERM $DSSC 2>/dev/null
echo "$0: Starting steering software ($DSSC)"
./$DSSC
timestamp=`date "+%Y-%m-%d %H:%M:%S"`
echo "$0: steering software died ($timestamp)"
done
# this is the last line :-)