-
-
Save Yavari/498fe01d1cf672e28a8feac555cec6e4 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
This file contains hidden or 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 | |
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 PGPPASSWORD=$POSTGRES_PASS psql -h guac-postgress -U $POSTGRES_USER -c '\q') ]]; 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 guacamole/guacamole /opt/guacamole/bin/initdb.sh --postgres > /tmp/initdb.sql) | |
OUTPUT=$(docker run --rm -e PGPASSWORD="${POSTGRES_PASS}" -v /tmp:/tmp --link guac-postgres postgres psql -h guac-postgres -U ${POSTGRES_USER} ${POSTGRES_DB} -f /tmp/initdb.sql) | |
rm -f 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 guacamole/guacd) | |
# start guac container | |
if [[ "" != $(docker ps -a | grep guacamole/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 guacamole/guacamole) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment