From d2d33bd76b729cda35412d77a72042af15eba923 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sat, 22 Feb 2020 22:21:40 +0100 Subject: [PATCH] Added shutdown scripts. Added HTTP_X_FORWARDED_FOR in reverse-proxy configuration. Added mounting volumes with openstack. Auto-creation of networks. --- docker-compose.yml | 11 +++-------- down.sh | 22 ++++++++++++++++++++++ reverse-proxy.config.php | 2 ++ start_or_update.sh | 26 ++++++++++++++++++++++++++ stop.sh | 2 +- 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100755 down.sh create mode 100755 start_or_update.sh diff --git a/docker-compose.yml b/docker-compose.yml index b47f2c9..cd56648 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: nextcloud: container_name: nextcloud-full - image: nextcloud:16.0.6 + image: nextcloud:17.0.3 build: ./docker/.examples/dockerfiles/full/apache/ restart: unless-stopped networks: @@ -14,8 +14,8 @@ services: expose: - "80/tcp" volumes: - - nextcloud:/var/www/html:Z - - ./supervisord.conf:/etc/supervisor/supervisord.conf + - /mnt/volumes/nextcloud/data:/var/www/html:Z + - ./supervisord.conf:/supervisord.conf - ./run_elasticsearch.sh:/run_elasticsearch.sh networks: @@ -28,8 +28,3 @@ networks: mailnet: external: true - -volumes: - - nextcloud: - external: true diff --git a/down.sh b/down.sh new file mode 100755 index 0000000..ff09c5c --- /dev/null +++ b/down.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +sudo docker-compose kill -s SIGTERM +COUNT=1 +ATTEMPT=0 + +while [ $COUNT -ne 0 ] && [ $ATTEMPT -lt 10 ] +do + sleep 1 + COUNT=$(sudo docker-compose top | wc -l) + ATTEMPT=$(( $ATTEMPT + 1 )) +done + +if [ $COUNT -eq 0 ] +then + sudo docker-compose down + exit 0 +else + echo "ERROR: Some containers are still running" + sudo docker-compose ps + exit 1 +fi diff --git a/reverse-proxy.config.php b/reverse-proxy.config.php index 1932b90..2ef3046 100644 --- a/reverse-proxy.config.php +++ b/reverse-proxy.config.php @@ -1,4 +1,6 @@ 'https', + 'trusted_proxies' => array('172.19.0.2'), + 'forwarded_for_headers' => array('HTTP_X_FORWARDED_FOR'), ); diff --git a/start_or_update.sh b/start_or_update.sh new file mode 100755 index 0000000..4fcb274 --- /dev/null +++ b/start_or_update.sh @@ -0,0 +1,26 @@ +#!/bin/bash +for NETWORK in mailnet mysqlnet reverse-proxy +do + sudo docker network inspect ${NETWORK} && continue + sudo docker network create ${NETWORK} + sudo docker network inspect ${NETWORK} || \ + { echo "ERROR: could not create network ${NETWORK}, exiting."; exit 1; } +done + +test -f ~/openrc.sh || { echo "ERROR: ~/openrc.sh not found, exiting."; exit 1; } +source ~/openrc.sh +INSTANCE=$(~/env_py3/bin/openstack server show -c id --format value $(hostname)) +for VOLUME in nextcloud +do + mkdir -p /mnt/volumes/${VOLUME} + if ! mountpoint -q /mnt/volumes/${VOLUME} + then + VOLUME_ID=$(/home/yohan/env_py3/bin/openstack volume show ${VOLUME} -c id --format value) + test -e /dev/disk/by-id/*${VOLUME_ID:0:20} || nova volume-attach $INSTANCE $VOLUME_ID auto + sleep 3 + sudo mount /dev/disk/by-id/*${VOLUME_ID:0:20} /mnt/volumes/${VOLUME} + mountpoint -q /mnt/volumes/${VOLUME} || { echo "ERROR: could not mount /mnt/volumes/${VOLUME}, exiting."; exit 1; } + fi +done + +sudo -E bash -c 'docker-compose up -d --build' diff --git a/stop.sh b/stop.sh index ff09c5c..f2f0bea 100755 --- a/stop.sh +++ b/stop.sh @@ -13,7 +13,7 @@ done if [ $COUNT -eq 0 ] then - sudo docker-compose down + sudo docker-compose stop exit 0 else echo "ERROR: Some containers are still running"