summaryrefslogtreecommitdiffstats
path: root/libexec/container/auto
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2022-06-05 05:21:57 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2022-06-05 08:23:40 +0000
commit02183cf8a39fe95d999bd5a3c982f2fb10ed0dba (patch)
treef2454b0fadc3618c71c28345968265fb3aecc24a /libexec/container/auto
parentTracking container state in run files in /var/lib/compute-tools. (diff)
downloadcompute-tools-02183cf8a39fe95d999bd5a3c982f2fb10ed0dba.tar.xz
compute-tools-02183cf8a39fe95d999bd5a3c982f2fb10ed0dba.zip
Automatically restoring previous state after reboot by using last-on/last-off config options, thanks to Sakirnth Nagarasa <sakirnth@gmail.com> for the use-case and idea.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
Diffstat (limited to '')
-rwxr-xr-xlibexec/container/auto55
1 files changed, 41 insertions, 14 deletions
diff --git a/libexec/container/auto b/libexec/container/auto
index 461e67d..83c5c50 100755
--- a/libexec/container/auto
+++ b/libexec/container/auto
@@ -109,25 +109,52 @@ case "${FORCE}" in
;;
esac
-case "${ACTION}" in
- stop)
- OPTIONS="${OPTIONS} -f"
- ;;
-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