From e4ca53ae54a2b54d8c594249f52d67c843800c8c Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Wed, 26 Feb 2020 17:43:43 +0100 Subject: [PATCH] Moved image building from docker-compose to startup script. --- docker-compose.yml | 2 +- down.sh | 22 ++++++++++++++++++++++ start_or_update.sh | 10 ++++++++-- stop.sh | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100755 down.sh diff --git a/docker-compose.yml b/docker-compose.yml index 2cb6d0b..d9c03f9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: openvpn-server: image: openvpn-server:$VERSION_OPENVPN_SERVER - build: "https://git.scimetis.net/yohan/docker-OpenVPN-server.git" + #build: "https://git.scimetis.net/yohan/docker-OpenVPN-server.git" ports: - 1194:1194/udp volumes: 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/start_or_update.sh b/start_or_update.sh index d1f880b..e342c9e 100755 --- a/start_or_update.sh +++ b/start_or_update.sh @@ -19,6 +19,12 @@ sudo chown -R root. conf server.conf # --force-recreate is used to recreate container when crontab file has changed unset VERSION_OPENVPN_SERVER -VERSION_OPENVPN_SERVER=$(git ls-remote https://${GIT_SERVER}/yohan/docker-OpenVPN-server.git| head -1 | cut -f 1|cut -c -10) \ - sudo -E bash -c 'docker-compose up -d --force-recreate' +export VERSION_OPENVPN_SERVER=$(git ls-remote https://${GIT_SERVER}/yohan/docker-OpenVPN-server.git| head -1 | cut -f 1|cut -c -10) +mkdir -p ~/build +git clone https://git.scimetis.net/yohan/docker-OpenVPN-server.git ~/build/docker-OpenVPN-server +sudo docker build -t openvpn-server:$VERSION_OPENVPN_SERVER ~/build/docker-OpenVPN-server + +sudo -E bash -c 'docker-compose up -d --force-recreate' + +rm -rf ~/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"