From 669091ff94cea4e0a7f7819290a274708dd96278 Mon Sep 17 00:00:00 2001 From: AJ Jordan Date: Sun, 16 Mar 2025 21:08:53 -0400 Subject: [PATCH] Add option to autostart managed containers This is useful for Podman, where containers are not autostarted on boot like they are under the Docker daemon. The usual way to solve this problem under Podman is to use systemd, but it's annoying to create a systemd unit for every ExApps-managed container by hand. Signed-off-by: AJ Jordan --- Dockerfile | 3 ++- README.md | 2 ++ start.sh | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f3279d3..e4c90ef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,8 @@ RUN set -ex; \ bind-tools \ nano \ vim \ - envsubst; \ + envsubst \ + jq; \ chmod -R 777 /tmp COPY --chmod=775 *.sh / diff --git a/README.md b/README.md index 49c3e24..c4acba7 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,8 @@ You should set `BIND_ADDRESS` to the IP on which server with ExApps can accept r `TIMEOUT_SERVER`: timeout for ExApp to start responding to NC request, default: **1800s** +`NC_AUTOSTART_CONTAINERS`: if set, automatically start managed app containers (useful for Podman users) + `NC_HAPROXY_PASSWORD_FILE`: Specifies path to a file containing the password for HAProxy. > [!NOTE] diff --git a/start.sh b/start.sh index 9f91d86..b546007 100644 --- a/start.sh +++ b/start.sh @@ -52,12 +52,21 @@ fi echo "HaProxy config:" +start_app_containers() { + if ! [ -z ${NC_AUTOSTART_CONTAINERS+x} ]; then + echo "Autostarting existing app containers per NC_AUTOSTART_CONTAINERS." + curl --silent --globoff -XGET --unix-socket /run/docker.sock 'http://localhost/containers/json?filters={"status":["exited"]}' | jq -r '.[] | select(.Names[0] | startswith("/nc_app_")) | .Id' | xargs -I% curl --silent --globoff -XPOST --fail-with-body --unix-socket /run/docker.sock 'http://localhost/containers/%/start' + fi +} + if [ -f "/certs/cert.pem" ]; then cat /haproxy.cfg cat /haproxy_ex_apps.cfg + start_app_containers haproxy -f /haproxy.cfg -f /haproxy_ex_apps.cfg -db else cat /haproxy.cfg + start_app_containers haproxy -f /haproxy.cfg -db fi