-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathvara_monitor
More file actions
172 lines (157 loc) · 4.88 KB
/
vara_monitor
File metadata and controls
172 lines (157 loc) · 4.88 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
VERSION=1
#############################################################################################
# VARA running on wine will not release and reopen the ports
# after a connection is made over a network.
# This script will monitor vara for ports not reopening correctly.
# Once a port failure is detected, it will close and re open VARA which
# is a crude way to reset the ports but the only one that works for now.
# VARA FM is the default modem but you can use VARA HF by calling
# it when the script is started. To start FM mode, simply run
# ./vara_monitor
# to start HF mode, modify the command and start with
# ./vara_monitor HF
#
# This script is specifically designed to run on the Raspberry Pi
# and will not work on other versions of Linux.
#
# 19NOV2022 KM4ACK
##############################################################################################
# user variables##############################################################################
WAIT_TIME=240 #seconds to wait so connections can finish before restarting VARA.
#Note: this time is doubled automatically for HF connections.
#Increasing this time allows for longer connections but also
#increases the time between restarts. Change the WAIT_TIME to
#suit your individual needs. Default is 240 seconds for FM and
#480 seconds (8 minutes) for HF
RIG_CONTROL=YES #YES/NO. If set to YES this script
#assumes FLRIG is configured for rig control.
# End user variables #########################################################################
#start of main script
#set modem start and give user feedback if HF
if [ $1 = "HF" ]; then
MODEM_START="HF"
clear;echo;echo
echo "Doubling connection timeout \"WAIT_TIME\""
WAIT_TIME=$(echo $(($WAIT_TIME*2)))
echo "WAIT_TIME is now $WAIT_TIME seconds"
sleep 5
else
MODEM_START="FM"
fi
clear;echo;echo
if [ "$RIG_CONTROL" = 'YES' ]; then
#verify FLRIG is running
FLRIG_RUN=$(pidof flrig)
while [ -z "$FLRIG_RUN" ]; do
echo "Please start FLRIG"
sleep 1
FLRIG_RUN=$(pidof flrig)
clear;echo;echo
done
echo "FLRIG seems to be running...standby"
#give FLRIG a few of seconds to start
for i in {03..01}
do
tput cup 2 36
echo -n "$i"
sleep 1
done
fi
MAIN(){
if [ "$RIG_CONTROL" = 'YES' ]; then
#start rigctld if not running
if [ -z `pidof rigctld` ]; then
/usr/local/bin/rigctld -m 4 &
fi
fi
clear;echo;echo
#verify vara has been started
VARA_RUN=$(ps aux | grep wine | grep -i vara | head -1 | awk '{print $2}')
while [ -z "$VARA_RUN" ]; do
echo "Configured for VARA $MODEM_START"
echo "**Modem not running**"
echo "Please start the modem"
sleep 1
VARA_RUN=$(ps aux | grep wine | grep -i vara | head -1 | awk '{print $2}')
clear;echo;echo
done
echo "VARA seems to be running...standby"
#wait for vara modem to start
for i in {15..01}
do
tput cup 2 35
echo -n "$i"
sleep 1
done
#setup time variables
seconds=1
minutes=0
hours=0
#monitor ports which will close after a network connection
#both ports 8300 & 8301 needed but we only need to check for one of them.
VARA_CK=$(sudo netstat -tunlp | grep 8300)
while [ -n "$VARA_CK" ]; do
clear;echo;echo
echo "##########################"
echo "# KM4ACK VARA Monitor v${VERSION} #"
echo "##########################"
echo "Monitoring VARA ports"
echo "press ctrl+c to stop"
echo "Elasped time - ${hours}:${minutes}:${seconds}"
VARA_CK=$(sudo netstat -tunlp | grep 8300)
((seconds++))
if [ $seconds = 60 ]; then
((minutes++))
seconds=0
fi
if [ $minutes = 60 ]; then
((hours++))
minutes=0
seconds=0
fi
sleep 1
done
clear;echo;echo
#give connections time to complete before restarting vara
#this timeout is defined above as WAIT_TIME
echo "Port closure detected!"
echo "Starting reset procedure"
for i in $(eval echo "{$WAIT_TIME..01}")
do
tput cup 3 25
echo -n "$i"
sleep 1
done
#kill current vara session
clear;echo;echo
echo "Done waiting, hope the connection was finished"
echo "If not, increate the WAIT_TIME which is currently $WAIT_TIME seconds"
echo "killing VARA $MODEM_START"
#get PID's of VARA & kill
FIRST=$(ps aux | grep wine | grep -i vara | head -1 | awk '{print $2}')
SECOND=$(ps aux | grep wine | grep -i vara | tail -1 | awk '{print $2}')
kill -9 $FIRST > /dev/null 2>&1 &
kill -9 $SECOND > /dev/null 2>&1 &
sleep 3
clear;echo;echo
#wait 61 seconds before restarting. This gives the ports time to clear
#so they are ready for the next run
echo "restarting VARA $MODEM_START in"
for i in {61..01}
do
tput cup 2 22
echo -n "$i"
sleep 1
done
#restart the correct modem
if [ "$MODEM_START" = 'HF' ]; then
/usr/local/bin/wine $HOME/.wine/drive_c/VARA/VARA.exe > /dev/null 2>&1 &
elif [ "$MODEM_START" = 'FM' ]; then
/usr/local/bin/wine $HOME/.wine/drive_c/VARA\ FM/VARAFM.exe > /dev/null 2>&1 &
fi
}
#run this script in a loop
while true; do
MAIN
done