Skip to content

Instantly share code, notes, and snippets.

@davidoram
Created May 22, 2018 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidoram/4995f6769b8a5f930ea9613fe4b65d20 to your computer and use it in GitHub Desktop.
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
#!/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