mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
swmodd: lxc containers as DU
This commit is contained in:
parent
d1ea18952f
commit
07e1c78029
6 changed files with 156 additions and 87 deletions
|
|
@ -5,13 +5,13 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=swmodd
|
||||
PKG_VERSION:=2.4.2
|
||||
PKG_VERSION:=2.5.0
|
||||
|
||||
LOCAL_DEV:=0
|
||||
ifneq ($(LOCAL_DEV),1)
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/lcm/swmodd.git
|
||||
PKG_SOURCE_VERSION:=ad39d3aa3b69c4efcb9f0230cee17af00fb3337f
|
||||
PKG_SOURCE_VERSION:=e92cad16be73ec3c842371d1992e1d892128b1bd
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
||||
PKG_MIRROR_HASH:=skip
|
||||
endif
|
||||
|
|
@ -83,6 +83,7 @@ define Package/swmodd/install
|
|||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/swmodd $(1)/usr/sbin/swmodd
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/opkg_offline.sh $(1)/usr/share/swmodd/opkg_offline
|
||||
$(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-bundle-path $(1)/etc/uci-defaults/01-fix-bundle-path
|
||||
$(INSTALL_BIN) ./files/etc/uci-defaults/03-execenv-ref $(1)/etc/uci-defaults/03-execenv-ref
|
||||
ifeq ($(CONFIG_PACKAGE_liblxc),y)
|
||||
$(INSTALL_DIR) $(1)/usr/share/lxc/templates/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/templates/lxc-iopsys $(1)/usr/share/lxc/templates/lxc-iopsys
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ boot() {
|
|||
}
|
||||
|
||||
start_service() {
|
||||
local bundle bridge boot
|
||||
local bundle root env bridge boot
|
||||
|
||||
# Check if crun present
|
||||
if ! command -v crun >/dev/null 2>&1; then
|
||||
|
|
@ -218,15 +218,17 @@ start_service() {
|
|||
fi
|
||||
|
||||
config_load swmodd
|
||||
config_get bundle globals oci_bundle_root ""
|
||||
config_get root globals root ""
|
||||
config_get bridge globals lan_bridge "br-lan"
|
||||
config_get timeout globals oci_pull_timeout "10"
|
||||
|
||||
if [ -z "${bundle}" ] || [ -z "${bridge}" ]; then
|
||||
log "Empty bundle path or bridge"
|
||||
env=$(uci -q get swmodd.@execenv[0].name)
|
||||
if [ -z "${root}" ] || [ -z "${bridge}" ]; then
|
||||
log "Base bundle root[$root] or bridge[$bridge] not defined"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
bundle="${root}/${env}"
|
||||
if [ -f "${bundle}/ocicontainer" ]; then
|
||||
UCI_CONFIG_DIR="${bundle}"
|
||||
config_load ocicontainer
|
||||
|
|
@ -235,6 +237,8 @@ start_service() {
|
|||
|
||||
# Add a timer for DuStateChange!
|
||||
(sleep 5 && ubus -t 5 call swmodules reload) &
|
||||
else
|
||||
log "${bundle}/ocicontainer not present"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ validate_globals_section()
|
|||
'enabled:bool:1' \
|
||||
'debug:bool:false' \
|
||||
'log_level:uinteger:1' \
|
||||
'lxc_bundle_root:string' \
|
||||
'oci_bundle_root:string' \
|
||||
'root:string' \
|
||||
'sock:string'
|
||||
}
|
||||
|
||||
|
|
@ -79,7 +78,7 @@ stop_lxc_containers() {
|
|||
}
|
||||
|
||||
start_service() {
|
||||
local enabled debug log_level sock lxc_bundle_root oci_bundle_root
|
||||
local enabled debug log_level sock root
|
||||
|
||||
config_load swmodd
|
||||
|
||||
|
|
@ -89,13 +88,35 @@ start_service() {
|
|||
|
||||
[ "${enabled}" -eq 0 ] && return 0
|
||||
|
||||
if [ ! -d "${lxc_bundle_root}" ]; then
|
||||
log "# Not staring lxc [${lxc_bundle_root}] not present/defined"
|
||||
[ ! -d "/run" ] && ln -fs /var/run /run
|
||||
if [ ! -d "${root}" ]; then
|
||||
log "# Not staring root [${root}] not present/defined"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ ! -d "${oci_bundle_root}" ]; then
|
||||
log "# Not staring oci [${oci_bundle_root}] not present/defined"
|
||||
env_name=""
|
||||
execenvs=$(uci show swmodd | grep "=execenv" | cut -d'=' -f 1 | cut -d'.' -f 2)
|
||||
for env in ${execenvs}; do
|
||||
name=$(uci get swmodd.${env}.name)
|
||||
if [ -n "${name}" ]; then
|
||||
env_name="${name}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${env_name}" ]; then
|
||||
log "# Not starting execenv name [${env_name}] not defined"
|
||||
return 1
|
||||
fi
|
||||
|
||||
bundle_root="${root}"
|
||||
if [ "${root: -1}" != '/' ]; then
|
||||
bundle_root="${root}/"
|
||||
fi
|
||||
|
||||
bundle_root="${bundle_root}${env_name}"
|
||||
if [ ! -d "${bundle_root}" ]; then
|
||||
log "# Not staring execenv [${bundle_root}] not present"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
|
@ -116,15 +137,10 @@ start_service() {
|
|||
procd_close_instance
|
||||
|
||||
# Auto-start the lxc containers
|
||||
if [ -f "${lxc_bundle_root}/lxccontainer" ]; then
|
||||
UCI_CONFIG_DIR="${lxc_bundle_root}"
|
||||
config_load lxccontainer
|
||||
config_foreach start_lxc_container container ${lxc_bundle_root}
|
||||
fi
|
||||
if [ -f "${oci_bundle_root}/ocicontainer" ]; then
|
||||
UCI_CONFIG_DIR="${oci_bundle_root}"
|
||||
if [ -f "${bundle_root}/ocicontainer" ]; then
|
||||
UCI_CONFIG_DIR="${bundle_root}"
|
||||
config_load ocicontainer
|
||||
config_foreach start_lxc_container du_eu_assoc ${oci_bundle_root}
|
||||
config_foreach start_lxc_container du_eu_assoc ${bundle_root}
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,37 +2,48 @@
|
|||
|
||||
. /lib/functions.sh
|
||||
|
||||
lxc=""
|
||||
lxc_bundle=""
|
||||
oci_bundle=""
|
||||
configure_ee_path() {
|
||||
local lxc_bundle oci_bundle name root
|
||||
|
||||
if [ -f "/etc/lxc/lxc.conf" ]; then
|
||||
lxc=$(cat /etc/lxc/lxc.conf |grep "lxc.lxcpath"| cut -d "=" -f 2)
|
||||
fi
|
||||
config_load swmodd
|
||||
config_get lxc_bundle globals lxc_bundle_root ""
|
||||
config_get oci_bundle globals oci_bundle_root ""
|
||||
|
||||
config_load swmodd
|
||||
config_get lxc_bundle globals lxc_bundle_root ""
|
||||
config_get oci_bundle globals oci_bundle_root ""
|
||||
|
||||
if [ -n "${lxc_bundle}" ]; then
|
||||
# if lxc_bundle_root define in swmodd, update it in lxc path
|
||||
mkdir -p /etc/lxc
|
||||
if [ -n "${oci_bundle}" ]; then
|
||||
# if oci_bundle_root define in swmodd, then remove it
|
||||
name=$(echo ${oci_bundle##/*/})
|
||||
root=$(echo ${oci_bundle%/$name})
|
||||
echo "lxc.lxcpath = ${oci_bundle}" > /etc/lxc/lxc.conf
|
||||
elif [ -n "${lxc_bundle}" ]; then
|
||||
# if lxc_bundle_root define in swmodd, then remove it
|
||||
name=$(echo ${lxc_bundle##/*/})
|
||||
root=$(echo ${lxc_bundle%/$name})
|
||||
echo "lxc.lxcpath = ${lxc_bundle}" > /etc/lxc/lxc.conf
|
||||
elif [ -n "${lxc}" ]; then
|
||||
# if lxc_bundle_root not define in swmodd, update it with lxc path
|
||||
uci_set swmodd globals lxc_bundle_root ${lxc}
|
||||
else
|
||||
mkdir -p /etc/lxc
|
||||
echo "lxc.lxcpath = /srv/" > /etc/lxc/lxc.conf
|
||||
uci_set swmodd globals lxc_bundle_root "/srv/"
|
||||
fi
|
||||
elif [ -f /etc/lxc/lxc.conf ]; then
|
||||
bundle_path=$(cat /etc/lxc/lxc.conf | grep "lxc.lxcpath" | cut -d "=" -f 2 | sed 's/[[:blank:]]//g')
|
||||
name=$(echo ${bundle_path##/*/})
|
||||
root=$(echo ${bundle_path%/$name})
|
||||
else
|
||||
name="lxc"
|
||||
root="/srv"
|
||||
echo "lxc.lxcpath = /srv/lxc" > /etc/lxc/lxc.conf
|
||||
fi
|
||||
|
||||
if [ -z "${oci_bundle}" ] && [ -n "${lxc_bundle}" ]; then
|
||||
# if oci_bundle_root not defined in swmodd, update it with lxc_bundle_root if defined
|
||||
uci_set swmodd globals oci_bundle_root ${lxc_bundle}
|
||||
elif [ -z "${oci_bundle}" ] && [ -n "${lxc}" ]; then
|
||||
# if oci_bundle_root not defined in swmodd, update it with lxc path
|
||||
uci_set swmodd globals oci_bundle_root ${lxc}
|
||||
elif [ -z "${oci_bundle}" ]; then
|
||||
uci_set swmodd globals oci_bundle_root "/srv/"
|
||||
fi
|
||||
uci_set swmodd globals oci_bundle_root ""
|
||||
uci_set swmodd globals lxc_bundle_root ""
|
||||
|
||||
# configure root in globals section
|
||||
if ! uci_get swmodd globals root >/dev/null; then
|
||||
uci_set swmodd globals root ${root}
|
||||
fi
|
||||
|
||||
# configure execenv in swmodd
|
||||
if ! uci_get swmodd.@execenv[0].name >/dev/null; then
|
||||
uci_add swmodd execenv execenv_1
|
||||
uci_set swmodd execenv_1 name ${name}
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
configure_ee_path
|
||||
|
|
|
|||
|
|
@ -2,46 +2,41 @@
|
|||
|
||||
. /lib/functions.sh
|
||||
|
||||
config_change=0
|
||||
migrate_from_lxc_to_oci_config() {
|
||||
config_load swmodd
|
||||
|
||||
migrate_lxc() {
|
||||
config_get name "${1}" name ""
|
||||
env_name=$(uci_get swmodd.@execenv[0].name)
|
||||
bundle_root=$(uci_get swmodd.globals.root)
|
||||
|
||||
if [ -z "${name}" ]; then
|
||||
return 0;
|
||||
if [ -z "${bundle_root}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Now lets check if already present in lxccontainer
|
||||
exist=$(uci -q -c "${2}" show lxccontainer | grep ".name='$name'")
|
||||
if [ -z "${exist}" ]; then
|
||||
# Not present, need to migrate
|
||||
sec=$(uci -q -c "${2}" add lxccontainer container)
|
||||
if [ -n "${sec}" ]; then
|
||||
uci -q -c "${2}" set lxccontainer."${sec}".name="${name}"
|
||||
uci -q -c "${2}" set lxccontainer."${sec}".type='lxc'
|
||||
uci -q -c "${2}" set lxccontainer."${sec}".autostart='1'
|
||||
uci -q -c "${2}" set lxccontainer."${sec}".timeout='300'
|
||||
config_change=1
|
||||
if [ -z "${env_name}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if ! command -v crun_create >/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "${bundle_root: -1}" != '/' ]; then
|
||||
bundle_root="${bundle_root}/"
|
||||
fi
|
||||
|
||||
lxcpath="${bundle_root}${env_name}"
|
||||
touch "${lxcpath}/ocicontainer"
|
||||
rm -rf "${lxcpath}/lxccontainer"
|
||||
|
||||
dirs=$(ls -l "${lxcpath}/" 2>/dev/null | grep '^d' | awk '{print $9}')
|
||||
|
||||
for d in ${dirs}; do
|
||||
config_file="${lxcpath}/${d}/config"
|
||||
|
||||
if [ -f "${config_file}" ]; then
|
||||
crun_create -c -r "${bundle_root}" -e "${env_name}" -n "${d}" --no-reload
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
config_load swmodd
|
||||
config_get lxc_bundle globals lxc_bundle_root ""
|
||||
|
||||
if [ -z "${lxc_bundle}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -d "${lxc_bundle}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
touch "${lxc_bundle}"/lxccontainer
|
||||
|
||||
config_load lxc-auto
|
||||
config_foreach migrate_lxc container "${lxc_bundle}"
|
||||
|
||||
if [ $config_change -eq 1 ]; then
|
||||
uci -q -c "${lxc_bundle}" commit lxccontainer
|
||||
fi
|
||||
migrate_from_lxc_to_oci_config
|
||||
|
|
|
|||
42
swmodd/files/etc/uci-defaults/03-execenv-ref
Normal file
42
swmodd/files/etc/uci-defaults/03-execenv-ref
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
set_execenv_ref() {
|
||||
config_get ee_name "${1}" ee_name ""
|
||||
|
||||
if [ "${ee_name}" != "${2}" ]; then
|
||||
uci_set ocicontainer "${1}" ee_name "${2}"
|
||||
fi
|
||||
}
|
||||
|
||||
migrate_execenv_ref() {
|
||||
config_load swmodd
|
||||
|
||||
env_name=$(uci_get swmodd.@execenv[0].name)
|
||||
bundle_root=$(uci_get swmodd.globals.root)
|
||||
|
||||
if [ -z "${bundle_root}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -z "${env_name}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "${bundle_root: -1}" != '/' ]; then
|
||||
bundle_root="${bundle_root}/"
|
||||
fi
|
||||
|
||||
lxcpath="${bundle_root}${env_name}"
|
||||
|
||||
if [ -f "${lxcpath}/ocicontainer" ]; then
|
||||
UCI_CONFIG_DIR="${lxcpath}"
|
||||
config_load ocicontainer
|
||||
config_foreach set_execenv_ref du_eu_assoc ${env_name}
|
||||
fi
|
||||
|
||||
uci -q -c "${lxcpath}" commit ocicontainer
|
||||
}
|
||||
|
||||
migrate_execenv_ref
|
||||
Loading…
Add table
Reference in a new issue