Skip to content

Instantly share code, notes, and snippets.

@sandys
Created February 17, 2017 10:56
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 sandys/e2f238babe922daa4f5edd7ce9b69e1a to your computer and use it in GitHub Desktop.
Save sandys/e2f238babe922daa4f5edd7ce9b69e1a to your computer and use it in GitHub Desktop.
how to write a supervisord compatible shell script for pgbouncer (which can restart gracefully)
#!/bin/bash
# inspired by http://veithen.github.io/2014/11/16/sigterm-propagation.html
if [ -z "$DBNAME" ]; then
echo "Environment variable DBNAME is not set!!!"
exit 1
else
sed -i 's|DBNAME|'"$DBNAME"'|' /etc/pgbouncer/pgbouncer.ini
fi
if [ -z "$USER" ]; then
echo "Environment variable USER is not set!!!"
exit 1
else
sed -i 's|USER|'"$USER"'|' /etc/pgbouncer/pgbouncer.ini
fi
if [ -z "$PASSWORD" ]; then
echo "Environment variable PASSWORD is not set!!!"
exit 1
else
sed -i 's|PASSWORD|'"$PASSWORD"'|' /etc/pgbouncer/pgbouncer.ini
fi
trap 'kill -TERM $PID' TERM INT
pgbouncer -u pgbouncer /etc/pgbouncer/pgbouncer.ini&
PID=$!
wait $PID
trap - TERM INT
wait $PID
EXIT_STATUS=$?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment