Skip to content

Commit 6827dc9

Browse files
authored
Add option to autostart managed containers (#43)
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 <[email protected]>
1 parent cb53f52 commit 6827dc9

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ RUN set -ex; \
2323
bind-tools \
2424
nano \
2525
vim \
26-
envsubst; \
26+
envsubst \
27+
jq; \
2728
chmod -R 777 /tmp
2829

2930
COPY --chmod=775 *.sh /

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ You should set `BIND_ADDRESS` to the IP on which server with ExApps can accept r
7575

7676
`TIMEOUT_SERVER`: timeout for ExApp to start responding to NC request, default: **1800s**
7777

78+
`NC_AUTOSTART_CONTAINERS`: if set, automatically start managed app containers (useful for Podman users)
79+
7880
`NC_HAPROXY_PASSWORD_FILE`: Specifies path to a file containing the password for HAProxy.
7981

8082
> [!NOTE]

start.sh

+9
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,21 @@ fi
5252

5353
echo "HaProxy config:"
5454

55+
start_app_containers() {
56+
if ! [ -z ${NC_AUTOSTART_CONTAINERS+x} ]; then
57+
echo "Autostarting existing app containers per NC_AUTOSTART_CONTAINERS."
58+
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'
59+
fi
60+
}
61+
5562
if [ -f "/certs/cert.pem" ]; then
5663
cat /haproxy.cfg
5764
cat /haproxy_ex_apps.cfg
65+
start_app_containers
5866
haproxy -f /haproxy.cfg -f /haproxy_ex_apps.cfg -db
5967
else
6068
cat /haproxy.cfg
69+
start_app_containers
6170
haproxy -f /haproxy.cfg -db
6271
fi
6372

0 commit comments

Comments
 (0)