toastie89 2 months ago
commit
20443dda32
4 changed files with 79 additions and 0 deletions
  1. 11 0
      README.md
  2. 3 0
      conf/.gitignore
  3. 12 0
      startup-containers.service
  4. 53 0
      startup.sh

+ 11 - 0
README.md

@@ -0,0 +1,11 @@
+# Docker startup helper scripts 
+
+`startup.sh` starts/stops/pulls all containers expected to run on the current host.
+The script expects a list of absolut paths to docker-compose.yml files in /opt/docker/startup/$HOSTNAME.
+
+`startup-containers.service` is a oneshot systemd service which runs `startup.sh up`.
+To install the service run:
+```
+cp startup-containers.service /etc/systemd/system/
+systemctl enable startup-containers.service
+```

+ 3 - 0
conf/.gitignore

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

+ 12 - 0
startup-containers.service

@@ -0,0 +1,12 @@
+[Unit]
+Description=Startup docker containers
+Requires=docker.service
+After=docker.service
+
+[Service]
+Type=oneshot
+WorkingDirectory=/opt/docker/startup
+ExecStart=/opt/docker/startup/startup.sh up
+
+[Install]
+WantedBy=multi-user.target

+ 53 - 0
startup.sh

@@ -0,0 +1,53 @@
+#!/bin/bash
+
+if [ -f /opt/docker/startup/$HOSTNAME ]; then echo "OK: Container list found"; else echo "NOK: No container list found" && exit 1; fi
+
+source /opt/docker/startup/$HOSTNAME
+
+up() {
+for service in $services
+  do
+    cd $service
+    docker compose up -d
+    # docker compose down
+    # docker network prune
+    # docker compose pull
+    # docker compose up -d
+  done
+}
+
+down() {
+for service in $services
+  do
+    cd $service
+    docker compose down
+  done
+}
+
+pull() {
+for service in $services
+  do
+    cd $service
+    docker compose pull
+  done
+}
+
+
+
+case "$1" in
+        up)
+            up 
+            ;;
+         
+        down)
+            down 
+            ;;
+         
+        pull)
+            pull 
+            ;;
+         
+        *)
+            echo $"Usage: $0 {up|down|pull}"
+            exit 1
+esac