summaryrefslogtreecommitdiffstats
path: root/libexec/container/auto
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/container/auto')
-rwxr-xr-xlibexec/container/auto51
1 files changed, 42 insertions, 9 deletions
diff --git a/libexec/container/auto b/libexec/container/auto
index de5f292..83c5c50 100755
--- a/libexec/container/auto
+++ b/libexec/container/auto
@@ -1,6 +1,6 @@
#!/bin/sh
-# Copyright (C) 2014-2021 Daniel Baumann <daniel.baumann@open-infrastructure.net>
+# Copyright (C) 2014-2022 Daniel Baumann <daniel.baumann@open-infrastructure.net>
#
# SPDX-License-Identifier: GPL-3.0+
#
@@ -111,17 +111,50 @@ esac
for FILE in "${CONFIG}"/*.conf
do
- if grep -Eqs "^ *cnt.auto=force-true" "${FILE}"
+ if ! grep -Eqs "^ *cnt.container-server=${HOST}" "${FILE}"
then
- OPTIONS="${OPTIONS} -f"
+ continue
fi
- if grep -Eqs "^ *cnt.auto=(force-true|true)" "${FILE}" && grep -Eqs "^ *cnt.container-server=${HOST}" "${FILE}"
- then
- CONTAINER="$(basename ${FILE} .conf)"
-
- cnt ${ACTION} -n ${CONTAINER} ${OPTIONS} || true
- fi
+ CONTAINER="$(basename ${FILE} .conf)"
+ CNT_AUTO="$(grep -Es "^ *cnt.auto=" ${FILE} | awk -F= '{ print $2 }')"
+
+ case "${ACTION}" in
+ start)
+ case "${CNT_AUTO}" in
+ force-true)
+ OPTIONS="${OPTIONS} -f"
+
+ cnt ${ACTION} -n ${CONTAINER} ${OPTIONS} || true
+ ;;
+
+ last-on)
+ if grep -qs start "/var/lib/${SOFTWARE}/state/${CONTAINER}.run" || \
+ [ ! -e "/var/lib/${SOFTWARE}/state/${CONTAINER}.run" ]
+ then
+ cnt start -n ${CONTAINER} ${OPTIONS} -f || true
+ fi
+ ;;
+
+ last-off)
+ if grep -qs start "/var/lib/${SOFTWARE}/state/${CONTAINER}.run"
+ then
+ cnt start -n ${CONTAINER} ${OPTIONS} -f || true
+ fi
+ ;;
+
+ true)
+ cnt ${ACTION} -n ${CONTAINER} ${OPTIONS} || true
+ ;;
+ esac
+ ;;
+
+ stop)
+ OPTIONS="${OPTIONS} -f --stateless"
+
+ cnt ${ACTION} -n ${CONTAINER} ${OPTIONS} || true
+ ;;
+ esac
done
# Post hooks