Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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