-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctrl-flt
71 lines (69 loc) · 1.75 KB
/
ctrl-flt
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash -l
#Change following three to actual values
RPATH=/home/durrans/flt
SCRNM=flt
PROGNM=driver-flight-logger.py
TS=$(date +%Y%m%d_%H:%M:%S)
i=0
case $1 in
start)
while ! [ -f "$RPATH"/"$PROGNM" ] ; do
((i++))
if [[ $i -eq 12 ]]; then #stop after trying for 2 mins
break
fi
#echo "$RPATH/$PROGNM not available waiting"
sleep 10
done
cd $RPATH
if pgrep -f "python ./$PROGNM" > /dev/null 2>&1; then
echo "[$TS] $PROGNM is already running"
else
/usr/bin/screen -h 500 -S $SCRNM -dm python ./$PROGNM
if [ $? = 0 ] ; then
echo "[$TS] $PROGNM started"
else
echo "[$TS] $PROGNM failed to start"
fi
fi;;
stop)
kill $(pgrep -f "python ./$PROGNM") 2> /dev/null
if [ $? = 0 ]
then
echo "[$TS] $PROGNM stopped"
else
echo "[$TS] $PROGNM was not running"
fi;;
restart)
#Stop
kill $(pgrep -f "python ./$PROGNM") 2> /dev/null
if [ $? = 0 ]
then
echo "[$TS] $PROGNM stopped"
else
echo "[$TS] $PROGNM was not running"
fi
#then Start
while ! [ -f "$RPATH"/"$PROGNM" ] ; do
((i++))
if [[ $i -eq 12 ]]; then #stop after trying for 2 mins
break
fi
#echo "$RPATH/$PROGNM not available waiting"
sleep 10
done
cd $RPATH
if pgrep -f "python ./$PROGNM" > /dev/null 2>&1; then
echo "[$TS] $PROGNM is already running"
else
/usr/bin/screen -h 500 -S $SCRNM -dm python ./$PROGNM
if [ $? = 0 ] ; then
echo "[$TS] $PROGNM started"
else
echo "[$TS] $PROGNM failed to start"
fi
fi;;
*)
echo "usage: ctrl-flt start|stop|restart"
exit 1;;
esac