Created
February 17, 2017 10:56
-
-
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)
This file contains 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 | |
# 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