#!/bin/bash

if [ `netstat -t | grep -v CLOSE_WAIT | grep ':8787' | wc -l` -lt 3 ]
then
    if [ -e "/tmp/monitor_run" ];
    then
        pkill tail
        # We will create new history elements with all data that is relevant,
        # this means we can delete everything from /import/
        # rm /import/ -rf
    fi
fi

touch /tmp/monitor_run

#!/bin/bash

# Take the netstat output the 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 :8787 If we do not have a
# connection open from port 8787, kill the server and herewith the docker container.

while true; do
    sleep 60

    if [ `netstat -t | grep -v CLOSE_WAIT | grep ':8787' | wc -l` -lt 3 ]
    then
        pkill ipython
        # 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 /import/ -rf;
        fi
    fi

done

Update with latest from upstream
Update with latest from upstream
