Created
May 22, 2018 03:43
-
-
Save davidoram/4995f6769b8a5f930ea9613fe4b65d20 to your computer and use it in GitHub Desktop.
Create a UNIX socket connected to a TCP socket. Useful for connecting a rails app to a postgres instance that has been dockerized
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/bash | |
set -e | |
if [ $# -ne 3 ]; then | |
echo "Usage:" | |
echo "" | |
echo " `basename $0` <unix socket file> <host> <listen port>" | |
echo "" | |
echo "For example:" | |
echo "" | |
echo " `basename $0` /tmp/.s.PGSQL.5432 localhost 5432" | |
echo "" | |
echo "Will create a Unix socket at '/tmp/.s.PGSQL.5432' and connect it to TCP socket on 'localhost:5432'" | |
echo "" | |
exit | |
fi | |
SOCK=$1 | |
HOST=$2 | |
PORT=$3 | |
socat -d -d -d -lf ${HOME}/tmp/socat.log UNIX-LISTEN:${SOCK},reuseaddr,fork TCP:${HOST}:${PORT} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment