Browse Source

moved to .env

toastie89 1 year ago
parent
commit
d5bec77eeb
5 changed files with 32 additions and 15 deletions
  1. 1 1
      conf/docker.example.com
  2. 1 0
      .gitignore
  3. 11 3
      README.md
  4. 0 3
      conf/.gitignore
  5. 19 8
      startup.sh

+ 1 - 1
conf/docker.example.com

@@ -1,4 +1,4 @@
-services="
+docker.example.com="
   /opt/docker/reverse-proxy
   /opt/docker/ejabberd
 "

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+.env

+ 11 - 3
README.md

@@ -1,12 +1,20 @@
 # Docker startup helper scripts 
 
-`startup.sh` starts/stops/pulls all containers expected to run on a docker host.
-The script expects a list of absolut paths to docker-compose.yml files in /opt/docker/startup/conf/$HOSTNAME.
+`startup.sh` brings containers up/down or pulls images with `docker compose`.
+The script looks for an environment variable named as per the hostname of the machine
+containing a list with absolute paths to `docker-compose.yml` files.
+Those variables can be defined in `.env`. 
 
-`container-startup.service` is a oneshot systemd service which runs `startup.sh up` after boot. Stop/restart are explicitely not part of the service as those actions are [handled by the docker daemon](https://docs.docker.com/config/containers/start-containers-automatically/).
+`container-startup.service` is a one-shot systemd service which runs `startup.sh up` after boot.
+Stop and restart are explicitly not part of the service as those actions are
+[handled by the docker daemon](https://docs.docker.com/config/containers/start-containers-automatically/).
 
 To install the service run:
 ```
+cp .env.template .env
+# add a variable named as per the hostname of the machine
+# with the list of your docker-compose.yml files
+vi .env
 cp container-startup.service /etc/systemd/system/
 systemctl enable container-startup.service
 ```

+ 0 - 3
conf/.gitignore

@@ -1,3 +0,0 @@
-*
-!.gitignore
-!docker.example.com

+ 19 - 8
startup.sh

@@ -1,18 +1,28 @@
 #!/bin/bash
 
-if [ -f /opt/docker/startup/conf/$HOSTNAME ]; then echo "OK: Container list found"; else echo "NOK: No container list found" && exit 1; fi
+if [ -f /opt/docker/startup/.env ]
+then
+  echo "OK: .env file found"
+  source /opt/docker/startup/.env
+else
+ echo '.env is missing, please consult README.md' && exit 1
+fi
+
+# test if a variable with the hostname of the machine,
+# as defined in $HOSTNAME, exists
+if [ ! -z "${!HOSTNAME}" ]
+then
+  echo "OK: Container list found in \$$HOSTNAME"
+else
+  echo "NOK: No container list found for $HOSTNAME" && exit 1
+fi
 
-source /opt/docker/startup/conf/$HOSTNAME
 
 up() {
-for service in $services
+for service in ${!HOSTNAME}
   do
     cd $service
-    docker compose up -d
-    # docker compose down
-    # docker network prune
-    # docker compose pull
-    # docker compose up -d
+    docker compose up -d --remove-orphans
   done
 }
 
@@ -51,3 +61,4 @@ case "$1" in
             echo $"Usage: $0 {up|down|pull}"
             exit 1
 esac
+