Skip to content

Instantly share code, notes, and snippets.

@sirupsen
Created September 3, 2014 14:52

Revisions

  1. sirupsen created this gist Sep 3, 2014.
    24 changes: 24 additions & 0 deletions resiliency.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #!/bin/bash

    if [[ -z $1 ]]; then
    echo -e "\x1b[31mMust supply src + dest port"
    exit 1
    fi

    echo -e "\x1b[32mForwarded port $2 --> $1\x1b[33m"
    sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport $2 -j REDIRECT --to-ports $1

    read -e -p "Hit enter to kill port redirect.."

    echo "Killing iptables forward.."
    sudo iptables -t nat -D OUTPUT 1

    PID=$(ps aux | grep -i [r]ails | awk '{print $2}')
    FD=$(sudo lsof -p $PID | grep $2 | awk '{print $4}')

    if [[ -z $FD ]]; then
    echo -e "\x1b[31mNo FD found"
    exit 1
    fi

    echo "p close($FD)" | sudo gdb -p $PID