Last active
February 24, 2020 21:23
-
-
Save mcast/18202ce200c658628481 to your computer and use it in GitHub Desktop.
kill a forwarded TCP connection for https://github.com/cooperative-computing-lab/cctools/issues/714
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# emacs | |
*~ | |
# logs | |
parrot.log |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# make a connection | |
ls -l $1 | |
# zap & try again | |
./kill_socat_child.sh | |
ls -l $1 | |
ret=$? | |
when=$(date +'%T.%3N') | |
echo "$when: exit code $ret" | |
# wait DISCONNECT_TIMEOUT + 5 && try again | |
echo "[now I sleep for the presumed value of DISCONNECT_TIMEOUT]" | |
sleep 305 | |
when=$(date +'%T.%3N') | |
echo "$when: done waiting" | |
ls -l $1 | |
ret=$? | |
when=$(date +'%T.%3N') | |
echo "$when: exit code $ret" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Assuming a port-forwarder like | |
# socat -d -d tcp4-listen:11247,fork,reuseaddr tcp4-connect:irods-host:1247 | |
# | |
# kill the connection, without stopping the listener | |
# Written to Ubuntu Precise / procps 3.2.8 / coreutils 8.13 | |
socats=$( pidof socat ) | |
# expect a parent (listener) and a child (the connection to kill) | |
child=$( ps -o pid= --ppid "$socats" ) | |
if [ -n "$child" ]; then | |
when=$(date +'%T.%3N') | |
kill -INT $child | |
echo "$when: killed $child" | |
else | |
echo "found nothing to kill (socat pids = $socats)" >&2 | |
exit 2 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# config for local server | |
export irodsEnvFile=~/.irods/irodsenv-test | |
server=irods-cgp-dev | |
export PATH=~/build/bin/:$PATH | |
echo '== what is it?' | |
which parrot_run | |
parrot_run --version | |
echo '== start port forward' | |
killall -INT socat | |
socat -d -d tcp4-listen:11247,fork,reuseaddr tcp4-connect:$server:1247 & | |
sleep 2 | |
echo '== run parrot_run action.sh' | |
export PARROT_DEBUG_FLAGS="fatal error notice process pstree irods remote time pid" | |
parrot_run -o parrot.log ./action.sh /irods/localhost:11247/ | |
echo '== tidy up' | |
killall -INT socat | |
echo '== show log parts' | |
perl -ne 'print if (m{ process: execve: /bin/ls succeeded} && print "[...]\n") .. m{ process: pid \d+ exited }' parrot.log | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment