From 2beba0b4961be4c52058436e56246149031e6a36 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Sat, 19 Oct 2019 22:27:23 -0600 Subject: [PATCH] update scripts from relevant repos --- ab-nginx-php.sh | 9 ++++---- ab-nginx.sh | 11 +++++----- ab-openldap.sh | 56 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 49 insertions(+), 27 deletions(-) diff --git a/ab-nginx-php.sh b/ab-nginx-php.sh index ee8d049..900b8a5 100755 --- a/ab-nginx-php.sh +++ b/ab-nginx-php.sh @@ -35,7 +35,8 @@ scriptHelp () { printf "'normally': Run in detached mode with nginx automatically launched and\n" printf "logging to stdout. If you specified certificates, nginx will serve over SSL\n" printf "by default.\n" - printf "Note: This container removes itself upon exit.\n\n" + printf "Note: Containers (except shell) are always set to restart 'unless-stopped'. You\n" + printf "must remove them manually if desired.\n\n" printf "${magenta}The script has the following parameters:\n" printf "${cyan}(parameter in cyan) ${yellow}(default in yellow)${norm}\n\n" printf "${cyan}-n|--name${norm}\n" @@ -181,7 +182,7 @@ if [ -z "$SSL_CERT" ]; then else # exec normally printf "${cyan}\nRunning NGINX on %s...${norm}\n" "$container_name" - docker run --rm -d --name ${container_name} \ + docker run -d --name ${container_name} \ --env-file ab-nginx-php.params \ $vmount \ -p ${HTTP_PORT}:80 \ @@ -205,7 +206,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = FALSE ]; then else # exec normally printf "${cyan}\nRunning NGINX on %s (TLS 1.2)...${norm}\n" "$container_name" - docker run --rm -d --name ${container_name} \ + docker run -d --name ${container_name} \ --env-file ab-nginx-php.params \ $vmount \ -v "$SSL_CERT":/certs/fullchain.pem:ro \ @@ -232,7 +233,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = TRUE ]; then else # exec normally printf "${cyan}\nRunning NGINX on %s (TLS 1.3)...${norm}\n" "$container_name" - docker run --rm -d --name ${container_name} \ + docker run -d --name ${container_name} \ --env-file ab-nginx-php.params \ $vmount \ -v "$SSL_CERT":/certs/fullchain.pem:ro \ diff --git a/ab-nginx.sh b/ab-nginx.sh index b8750a0..d90fa6c 100755 --- a/ab-nginx.sh +++ b/ab-nginx.sh @@ -35,7 +35,8 @@ scriptHelp () { printf "'normally': Run in detached mode with nginx automatically launched and\n" printf "logging to stdout. If you specified certificates, nginx will serve over SSL\n" printf "by default.\n" - printf "Note: This container removes itself upon exit.\n\n" + printf "Note: Containers (except shell) are always set to restart 'unless-stopped'. You\n" + printf "must remove them manually if desired.\n\n" printf "${magenta}The script has the following parameters:\n" printf "${cyan}(parameter in cyan) ${yellow}(default in yellow)${norm}\n\n" printf "${cyan}-n|--name${norm}\n" @@ -181,7 +182,7 @@ if [ -z "$SSL_CERT" ]; then else # exec normally printf "${cyan}\nRunning NGINX on %s...${norm}\n" "$container_name" - docker run --rm -d --name ${container_name} \ + docker run -d --name ${container_name} \ --env-file ab-nginx.params \ $vmount \ -p ${HTTP_PORT}:80 \ @@ -205,7 +206,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = FALSE ]; then else # exec normally printf "${cyan}\nRunning NGINX on %s (TLS 1.2)...${norm}\n" "$container_name" - docker run --rm -d --name ${container_name} \ + docker run -d --name ${container_name} \ --env-file ab-nginx.params \ $vmount \ -v "$SSL_CERT":/certs/fullchain.pem:ro \ @@ -232,7 +233,7 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = TRUE ]; then else # exec normally printf "${cyan}\nRunning NGINX on %s (TLS 1.3)...${norm}\n" "$container_name" - docker run --rm -d --name ${container_name} \ + docker run -d --name ${container_name} \ --env-file ab-nginx.params \ $vmount \ -v "$SSL_CERT":/certs/fullchain.pem:ro \ @@ -246,4 +247,4 @@ fi ### exit gracefully -exit 0 \ No newline at end of file +exit 0 diff --git a/ab-openldap.sh b/ab-openldap.sh index fc862ac..3db9790 100755 --- a/ab-openldap.sh +++ b/ab-openldap.sh @@ -41,7 +41,10 @@ scriptHelp () { printf "'normally': Run in detached mode with openLDAP automatically launched and\n" printf "logging to stdout. If you specified certificates, openLDAP will require a TLS\n" printf "connection. All modes of operation allow you to enter the container and\n" - printf "connect directly using UNIX sockets also.\n\n" + printf "connect directly using UNIX sockets also.\n" + printf "Containers run in SHELL mode are ALWAYS removed upon exit as they are meant for\n" + printf "testing only. By default, containers run without '--rm' will be restarted\n" + printf "automatically unless they are manually stopped via 'docker stop...'\n\n" printf "${magenta}The script has the following parameters:\n" printf "${cyan}(parameter in cyan) ${yellow}(default in yellow)${norm}\n\n" printf "${cyan}-n|--name${norm}\n" @@ -113,7 +116,7 @@ while [ $# -gt 0 ]; do ;; --rm|--remove) # remove container on exit - remove="--rm" + remove=1 ;; -s|--shell) # start shell instead of default CMD @@ -142,7 +145,7 @@ while [ $# -gt 0 ]; do done -# cleanup and running containers and volumes +# cleanup any running containers and volumes if [ $clean = true ]; then # get all ab-openldap containers containers=$(docker ps -a --no-trunc --filter "label=org.label-schema.name=ab-openldap" --format "{{ .Names }}") @@ -171,25 +174,32 @@ elif [ -z "$TLS_CERT" ]; then if [ $shell = true ]; then # exec shell printf "${cyan}\nRunning SHELL on %s...${norm}\n" "$container_name" - docker run ${remove} -it --name ${container_name} \ + docker run --rm -it --name ${container_name} \ --env-file ab-openldap.params \ -p 389:389 -p 636:636 \ docker.asifbacchus.app/ldap/ab-openldap:latest /bin/sh else # exec normally printf "${cyan}\nRunning OPENLDAP on %s...${norm}\n" "$container_name" - docker run ${remove} -d --name ${container_name} \ - --env-file ab-openldap.params \ - -p 389:389 -p 636:636 \ - --restart unless-stopped \ - docker.asifbacchus.app/ldap/ab-openldap:latest + if [ "$remove" -eq 1 ]; then + docker run --rm -d --name ${container_name} \ + --env-file ab-openldap.params \ + -p 389:389 -p 636:636 \ + docker.asifbacchus.app/ldap/ab-openldap:latest + else + docker run -d --name ${container_name} \ + --env-file ab-openldap.params \ + -p 389:389 -p 636:636 \ + --restart unless-stopped \ + docker.asifbacchus.app/ldap/ab-openldap:latest + fi fi # run with TLS elif [ "$TLS_CERT" ] && [ "$TLS_KEY" ] && [ "$TLS_CHAIN" ]; then if [ $shell = true ]; then # exec shell printf "${cyan}\nRunning SHELL on %s (TLS)...${norm}\n" "$container_name" - docker run ${remove} -it --name ${container_name} \ + docker run --rm -it --name ${container_name} \ --env-file ab-openldap.params \ -v "$TLS_CERT":/certs/fullchain.pem:ro \ -v "$TLS_KEY":/certs/privkey.pem:ro \ @@ -199,14 +209,24 @@ elif [ "$TLS_CERT" ] && [ "$TLS_KEY" ] && [ "$TLS_CHAIN" ]; then else # exec normally printf "${cyan}\nRunning OPENLDAP on %s (TLS)...${norm}\n" "$container_name" - docker run ${remove} -d --name ${container_name} \ - --env-file ab-openldap.params \ - -v "$TLS_CERT":/certs/fullchain.pem:ro \ - -v "$TLS_KEY":/certs/privkey.pem:ro \ - -v "$TLS_CHAIN":/certs/chain.pem:ro \ - -p 389:389 -p 636:636 \ - --restart unless-stopped \ - docker.asifbacchus.app/ldap/ab-openldap:latest + if [ "$remove" -eq 1 ]; then + docker run --rm -d --name ${container_name} \ + --env-file ab-openldap.params \ + -v "$TLS_CERT":/certs/fullchain.pem:ro \ + -v "$TLS_KEY":/certs/privkey.pem:ro \ + -v "$TLS_CHAIN":/certs/chain.pem:ro \ + -p 389:389 -p 636:636 \ + docker.asifbacchus.app/ldap/ab-openldap:latest + else + docker run -d --name ${container_name} \ + --env-file ab-openldap.params \ + -v "$TLS_CERT":/certs/fullchain.pem:ro \ + -v "$TLS_KEY":/certs/privkey.pem:ro \ + -v "$TLS_CHAIN":/certs/chain.pem:ro \ + -p 389:389 -p 636:636 \ + --restart unless-stopped \ + docker.asifbacchus.app/ldap/ab-openldap:latest + fi fi fi