swmodd: Fix AutoStart, RequestedState for OCI containers

This commit is contained in:
Suvendhu Hansa 2022-11-25 08:36:13 +00:00 committed by Vivek Kumar Dutta
parent 1ba2d5ab89
commit 0d076595f8
2 changed files with 66 additions and 31 deletions

View file

@ -5,12 +5,12 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=swmodd PKG_NAME:=swmodd
PKG_VERSION:=2.1.17 PKG_VERSION:=2.1.18
LOCAL_DEV:=0 LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1) ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=5124ea8051c06e8c3563b384660b08db199c93eb PKG_SOURCE_VERSION:=0617f1017511854b0e3d384799f2bf63800a27c0
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/swmodd.git PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/swmodd.git
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip PKG_MIRROR_HASH:=skip

View file

@ -16,11 +16,12 @@ is_container_running() {
configure_crun_container() { configure_crun_container() {
local name type autostart du_status requested_state url username password local name type autostart du_status requested_state url username password
local BRIDGE BUNDLE local BRIDGE BUNDLE BOOT
local RUNNER="/etc/swmodd/run.sh" local RUNNER="/etc/swmodd/run.sh"
BUNDLE="${2}" BUNDLE="${2}"
BRIDGE="${3}" BRIDGE="${3}"
BOOT="${4}"
config_get name ${1} name "" config_get name ${1} name ""
config_get type ${1} type "" config_get type ${1} type ""
@ -102,36 +103,59 @@ configure_crun_container() {
return 0; return 0;
fi fi
if [ "${autostart}" -eq 0 ]; then if [ "${BOOT}" -eq "1" ]; then
ubus call service delete "{\"name\":\"crun\",\"instance\":\"${name}\"}" if [ "${autostart}" -eq 1 ]; then
# stop the container if not enabled ${RUNNER} -U -b "${BUNDLE}" -n "${name}"
crun kill --all "${name}" 9 result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description")
return 0; if [ "${result}" != "null" ]; then
fi uci_set ocicontainer ${1} description "${result}"
fi
if is_container_running "${name}"; then result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_vendor")
log "Container [$name] req_status [${requested_state}]" if [ "${result}" != "null" ]; then
if [ "${requested_state}" == "Idle" ]; then uci_set ocicontainer ${1} vendor "${result}"
crun pause "${name}" fi
elif [ "${requested_state}" == "Active" ]; then
${RUNNER} -u -n "${name}" -i "${BRIDGE}" result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_version")
crun resume "${name}" if [ "${result}" != "null" ]; then
uci_set ocicontainer ${1} version "${result}"
fi
uci_set ocicontainer ${1} requested_state "Active"
else
uci_set ocicontainer ${1} requested_state "Idle"
return 0;
fi fi
else else
${RUNNER} -U -b "${BUNDLE}" -n "${name}" log "Container [$name] req_status [${requested_state}]"
result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description") if [ "${requested_state}" == "Idle" ]; then
if [ "${result}" != "null" ]; then if is_container_running "${name}"; then
uci_set ocicontainer ${1} description "${result}" crun pause "${name}"
fi else
return 0;
fi
elif [ "${requested_state}" == "Active" ]; then
if is_container_running "${name}"; then
${RUNNER} -u -n "${name}" -i "${BRIDGE}"
crun resume "${name}"
else
${RUNNER} -U -b "${BUNDLE}" -n "${name}"
result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_description")
if [ "${result}" != "null" ]; then
uci_set ocicontainer ${1} description "${result}"
fi
result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_vendor") result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_vendor")
if [ "${result}" != "null" ]; then if [ "${result}" != "null" ]; then
uci_set ocicontainer ${1} vendor "${result}" uci_set ocicontainer ${1} vendor "${result}"
fi fi
result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_version") result=$(cat ${BUNDLE}/${name}/config.json |jq ".annotations.org_opencontainers_image_version")
if [ "${result}" != "null" ]; then if [ "${result}" != "null" ]; then
uci_set ocicontainer ${1} version "${result}" uci_set ocicontainer ${1} version "${result}"
fi
fi
else
return 0;
fi fi
fi fi
@ -144,8 +168,12 @@ configure_crun_container() {
procd_close_instance "${name}" procd_close_instance "${name}"
} }
boot() {
start "bootstrap"
}
start_service() { start_service() {
local bundle bridge local bundle bridge boot
# Check if crun present # Check if crun present
if ! command -v crun >/dev/null 2>&1; then if ! command -v crun >/dev/null 2>&1; then
@ -153,6 +181,12 @@ start_service() {
return 0; return 0;
fi fi
if [ "${1}" == "bootstrap" ]; then
boot=1
else
boot=0
fi
config_load swmodd config_load swmodd
config_get bundle globals oci_bundle_root "" config_get bundle globals oci_bundle_root ""
config_get bridge globals lan_bridge "br-lan" config_get bridge globals lan_bridge "br-lan"
@ -165,8 +199,9 @@ start_service() {
if [ -f "${bundle}/ocicontainer" ]; then if [ -f "${bundle}/ocicontainer" ]; then
UCI_CONFIG_DIR="${bundle}" UCI_CONFIG_DIR="${bundle}"
config_load ocicontainer config_load ocicontainer
config_foreach configure_crun_container du_eu_assoc "${bundle}" "${bridge}" config_foreach configure_crun_container du_eu_assoc "${bundle}" "${bridge}" "${boot}"
uci_commit uci_commit ocicontainer
# Add a timer for DuStateChange! # Add a timer for DuStateChange!
(sleep 5 && ubus -t 5 call swmodules reload) & (sleep 5 && ubus -t 5 call swmodules reload) &
fi fi