Skip to content

Instantly share code, notes, and snippets.

@chrisruffalo
Created April 11, 2018 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisruffalo/c64a312f2fd8f013cad41d2468d430e5 to your computer and use it in GitHub Desktop.
Save chrisruffalo/c64a312f2fd8f013cad41d2468d430e5 to your computer and use it in GitHub Desktop.
A script that will allow a docker host to start a guacd system of hosts and initialize the postgres database all in one go
#!/bin/bash
POSTGRES_USER=guac
POSTGRES_PASS=guac
POSTGRES_DB=guac
# create storage for postgres container
NEW_VOLUME=false
if [[ "" == $(docker volume ls | grep guac-postgres-volume) ]]; then
printf "Creating a new volume for guac-postgres...\n"
OUTPUT=$(docker volume create --name guac-postgres-volume)
NEW_VOLUME=true
fi
# start postgres
if [[ "" != $(docker ps -a | grep guac-postgres) ]]; then
printf "Deleting running guac-postgres container...\n"
OUTPUT=$(docker rm -f guac-postgres)
fi
printf "Starting guac-postgres...\n"
OUTPUT=$(docker run -d --name guac-postgres -e POSTGRES_PASSWORD="${POSTGRES_PASS}" -e POSTGRES_USER="${POSTGRES_USER}" -e POSTGRES_DB="${POSTGRES_DB}" -v guac-postgres-volume:/var/lib/postgresql/data postgres)
# wait for postgres to start
until [[ "" != $(docker exec -t guac-postgres ss -tnlp | grep 5432) ]]; do
printf "Waiting for guac-postgres port to come alive...\n"
sleep 1
done
# init db if new volume
if [ true = "${NEW_VOLUME}" ]; then
printf "Creating schema in guac-postgres database...\n"
OUTPUT=$(docker run --rm glyptodon/guacamole /opt/guacamole/bin/initdb.sh --postgres > /tmp/guac-initdb.sql)
OUTPUT=$(docker run --rm -e PGPASSWORD="${POSTGRES_PASS}" -v /tmp/guac-initdb.sql:/guac-initdb.sql --link guac-postgres postgres psql -h guac-postgres -U ${POSTGRES_USER} ${POSTGRES_DB} -f /guac-initdb.sql)
rm -f /tmp/guac-initdb.sql
printf "Reminder: the default username/password is 'guacadmin'\n"
fi
# start guacd container
if [[ "" != $(docker ps -a | grep guacd) ]]; then
printf "Deleting runnging guacd container...\n"
OUTPUT=$(docker rm -f guacd)
fi
printf "Starting guacd...\n"
OUTPUT=$(docker run -d --name guacd glyptodon/guacd)
# start guac container
if [[ "" != $(docker ps -a | grep guacamole) ]]; then
printf "Deleting running guacamole container...\n"
OUTPUT=$(docker rm -f guacamole)
fi
printf "Starting guacamole...\n"
OUTPUT=$(docker run --name guacamole --link guacd:guacd --link guac-postgres:postgres -e POSTGRES_DATABASE="${POSTGRES_DB}" -e POSTGRES_USER="${POSTGRES_USER}" -e POSTGRES_PASSWORD="${POSTGRES_PASS}" -d -p 18080:8080 glyptodon/guacamole)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment