-
Notifications
You must be signed in to change notification settings - Fork 17
/
monitor_traffic.sh
executable file
·28 lines (23 loc) · 1.06 KB
/
monitor_traffic.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
#!/bin/bash
# Take the netstat output to estimate if the client is still connected to
# the RStudio server. The 'CLOSE_WAIT' state will be ignored. It
# indicates that the server has received the first FIN signal from the client
# and the connection is in the process of being closed. But that can never happen.
# For some reason there are a few connections open that do not relate the
# client that needs to be connected over the port :80 If we do not have a
# connection open from port 80, kill the server and herewith the docker container.
# For RStudio there is typically one ESTABLISHED connection (get_events HTTP 50s long request)
# and one TIME_WAIT (probably the previous get_events HTTP request)
while true; do
sleep 240
if [ `netstat -t | grep -v CLOSE_WAIT | grep ':80' | wc -l` -lt 2 ]
then
pkill nginx
# We will create new history elements with all data that is relevant,
# this means we can delete everything from /import/
if [[ "$DEBUG" == "false" ]];
then
rm -rf /import/*;
fi
fi
done