Compare commits

...

1 Commits

Author SHA1 Message Date
Sukru Senli
2cfb81644a swmodd: 2.3.4 2023-09-11 16:17:58 +02:00
6 changed files with 203 additions and 66 deletions

View File

@@ -1,53 +1,83 @@
menu "Configuration"
config SWMODD_REGISTRY_PULL_SUPPORT
bool "Add support to pull images from container image registries (i.e: docker.io, quay.io)"
depends on PACKAGE_swmodd
default n
select PACKAGE_skopeo
select PACKAGE_umoci
config SWMODD_LXC_SUPPORT
bool "Handles LXC based containers"
default y
config SWMODD_LXC_SUPPORT
bool "Handles LXC based containers"
depends on PACKAGE_swmodd
default y
select PACKAGE_lxc
select PACKAGE_lxc-attach
select PACKAGE_lxc-auto
select PACKAGE_lxc-cgroup
select PACKAGE_lxc-checkconfig
select PACKAGE_lxc-common
select PACKAGE_lxc-config
select PACKAGE_lxc-configs
select PACKAGE_lxc-console
select PACKAGE_lxc-create
select PACKAGE_lxc-destroy
select PACKAGE_lxc-execute
select PACKAGE_lxc-freeze
select PACKAGE_lxc-hooks
select PACKAGE_lxc-info
select PACKAGE_lxc-init
select PACKAGE_lxc-ls
select PACKAGE_lxc-device
select PACKAGE_lxc-start
select PACKAGE_lxc-stop
select PACKAGE_lxc-templates
select PACKAGE_lxc-top
select PACKAGE_lxc-unfreeze
select PACKAGE_lxc-unprivileged
select PACKAGE_lxc-unshare
select PACKAGE_lxc-user-nic
select PACKAGE_lxc-usernsexec
select PACKAGE_lxc-wait
config SWMODD_OCI_SUPPORT
bool "Handles OCI containers"
default y
depends on PACKAGE_swmodd
select PACKAGE_crun
config SWMODD_OCI_SUPPORT
bool "Handles OCI containers"
depends on PACKAGE_swmodd
default y
select PACKAGE_crun
config SWMODD_REGISTRY_PULL_SUPPORT
bool "Add support to pull images from container image registries (i.e: docker.io, quay.io)"
default n
depends on PACKAGE_swmodd
select PACKAGE_skopeo
select PACKAGE_umoci
config SWMODD_KERNEL_OPTIONS
bool "Enable kernel support for LXC and OCI containers"
depends on PACKAGE_swmodd
default y
select LXC_KERNEL_OPTIONS
select LXC_BUSYBOX_OPTIONS
select LXC_SECCOMP
select LXC_NETWORKING
select KERNEL_CGROUPS
select KERNEL_CGROUP_SCHED
select KERNEL_CGROUP_DEVICE
select KERNEL_CGROUP_FREEZER
select KERNEL_CGROUP_CPUACCT
select KERNEL_CGROUP_NET_PRIO
select KERNEL_NET_CLS_CGROUP
select KERNEL_NAMESPACES
select KERNEL_DEVPTS_MULTIPLE_INSTANCES
select KERNEL_POSIX_MQUEUE
select KERNEL_FAIR_GROUP_SCHED
select KERNEL_RT_GROUP_SCHED
select KERNEL_MEMCG
select KERNEL_MEMCG_KMEM
select KERNEL_CPUSETS
select PACKAGE_kmod-ikconfig
help
Select needed kernel options for LXC and CRUN related utilities. Options
include cgroups, namespaces and other miscellaneous options. These
options unfortunately can not be installed as a module.
config SWMODD_KERNEL_OPTIONS
bool "Enable kernel support for LXC and OCI containers"
default y
select KERNEL_CGROUPS
select KERNEL_CGROUP_SCHED
select KERNEL_CGROUP_DEVICE
select KERNEL_CGROUP_FREEZER
select KERNEL_CGROUP_CPUACCT
select KERNEL_CGROUP_NET_PRIO
select KERNEL_NET_CLS_CGROUP
select KERNEL_NAMESPACES
select KERNEL_DEVPTS_MULTIPLE_INSTANCES
select KERNEL_POSIX_MQUEUE
select KERNEL_FAIR_GROUP_SCHED
select KERNEL_RT_GROUP_SCHED
select KERNEL_MEMCG
select KERNEL_MEMCG_KMEM
select KERNEL_CPUSETS
select PACKAGE_kmod-ikconfig
help
Select needed kernel options for LXC and CRUN related utilities. Options
include cgroups, namespaces and other miscellaneous options. These
options unfortunately can not be installed as a module.
config SWMODD_NETWORKING
bool "Enable networking support for LXC/OCI containers"
default y
select PACKAGE_kmod-veth
select PACKAGE_kmod-macvlan
help
Enable "veth pair device" and "macvlan"
endmenu
config SWMODD_NETWORKING
bool "Enable networking support for LXC/OCI containers"
depends on PACKAGE_swmodd
default y
select PACKAGE_kmod-veth
select PACKAGE_kmod-macvlan
help
Enable "veth pair device" and "macvlan"

View File

@@ -5,13 +5,13 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=swmodd
PKG_VERSION:=2.2.4
PKG_VERSION:=2.3.4
LOCAL_DEV:=0
ifneq ($(LOCAL_DEV),1)
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/lcm/swmodd.git
PKG_SOURCE_VERSION:=25cbdf268e803eeed4f840419825512724df055d
PKG_SOURCE_VERSION:=d29418d26e630894079de73fae66bf04b5db0ab3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
endif
@@ -28,8 +28,9 @@ define Package/swmodd
CATEGORY:=Utilities
SUBMENU:=TRx69
TITLE:= Software Modules Daemon
MENU:=1
DEPENDS:=+libuci +libubox +ubus +libuuid +opkg +libcurl \
+PACKAGE_liblxc:liblxc +@BUSYBOX_CONFIG_BUSYBOX \
+PACKAGE_lxc:lxc +PACKAGE_liblxc:liblxc +@BUSYBOX_CONFIG_BUSYBOX \
+@BUSYBOX_CONFIG_FEATURE_SHOW_SCRIPT +@BUSYBOX_CONFIG_SCRIPT \
+swmodd-cgroup +jq +libbbfdm-api
endef
@@ -54,12 +55,12 @@ TARGET_CFLAGS += \
-D_GNU_SOURCE \
-Wall -Werror
ifeq ($(CONFIG_PACKAGE_crun),y)
ifeq ($(CONFIG_SWMODD_OCI_SUPPORT),y)
MAKE_FLAGS += \
SWMOD_CRUN="yes"
endif
ifeq ($(CONFIG_PACKAGE_liblxc),y)
ifeq ($(CONFIG_SWMODD_LXC_SUPPORT),y)
MAKE_FLAGS += \
SWMOD_LXC="yes"
endif
@@ -76,23 +77,24 @@ define Package/swmodd/install
$(INSTALL_DIR) $(1)/usr/lib/bbfdm
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/usr/share/swmodd/
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/init.d/swmodd $(1)/etc/init.d/swmodd
$(INSTALL_BIN) ./files/etc/config/swmodd $(1)/etc/config/swmodd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/swmodd $(1)/usr/sbin/swmodd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/libswmodd.so $(1)/usr/lib/bbfdm/libswmodd.so
$(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
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
$(INSTALL_BIN) ./files/etc/uci-defaults/02-migrate-lxc $(1)/etc/uci-defaults/02-migrate-lxc
endif
ifeq ($(CONFIG_PACKAGE_crun),y)
$(INSTALL_DIR) $(1)/etc/swmodd
$(INSTALL_DIR) $(1)/etc/uci-defaults
$(INSTALL_BIN) ./files/etc/swmodd/run.sh $(1)/etc/swmodd/run.sh
$(INSTALL_BIN) ./files/etc/init.d/crun $(1)/etc/init.d/crun
$(INSTALL_BIN) ./files/etc/config/crun $(1)/etc/config/crun
$(INSTALL_BIN) $(PKG_BUILD_DIR)/scripts/crun_create $(1)/usr/sbin/crun_create
$(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-bundle-path $(1)/etc/uci-defaults/01-fix-bundle-path
endif
endef

View File

@@ -14,6 +14,34 @@ is_container_running() {
return $?
}
configure_lxc_container() {
local requested_state name ctype du_status BUNDLE
ctype="${1}"
name="${2}"
requested_state="${3}"
du_state="${4}"
BUNDLE="${5}"
if [ "${ctype}" != "lxc" ]; then
return 0;
fi
if [ "${du_status}" = "Uninstalling" ]; then
lxc-stop -q -k "${name}"
if [ -d "${BUNDLE:?}/${name:?}" ]; then
rm -rf "${BUNDLE:?}/${name:?}"
fi
fi
if [ "${requested_state}" = "Idle" ]; then
lxc-stop -q -k "${name}"
elif [ "${requested_state}" = "Active" ]; then
lxc-start -q "${name}" >/dev/null 2>&1
fi
}
configure_crun_container() {
local name type autostart du_status requested_state url username password
local BRIDGE BUNDLE BOOT
@@ -38,6 +66,7 @@ configure_crun_container() {
fi
if [ "${type}" != "crun" ]; then
configure_lxc_container "${type}" "${name}" "${requested_state}" "${du_status}" "${BUNDLE}"
return 0;
fi

View File

@@ -6,6 +6,11 @@ STOP=01
USE_PROCD=1
PROG=/usr/sbin/swmodd
log()
{
logger -t swmodd.init "$*"
}
validate_globals_section()
{
uci_validate_section swmodd swmodd "globals" \
@@ -18,15 +23,23 @@ validate_globals_section()
}
start_lxc_container() {
local root
config_get name "${1}" name ""
config_get type "${1}" type ""
config_get autostart "${1}" autostart "0"
config_get timeout "${1}" timeout "300"
root="${2}"
if [ -z "${name}" ] || [ -z "${type}" ]; then
return 0;
fi
# workaround to install lxc container with installdu and autostart them
if [ -f "${root}/$name/config" ]; then
type=lxc
fi
if [ "${type}" != "lxc" ]; then
return 0;
fi
@@ -39,12 +52,12 @@ start_lxc_container() {
if [ "${autostart}" == "0" ]; then
if [ "${state}" == "RUNNING" ]; then
# stop the container if running
lxc-stop -n "${name}" -t "${timeout}" &
lxc-stop -k -n "${name}" &
return 0;
elif [ "${state}" == "FROZEN" ]; then
# first unfreeze then stop
lxc-unfreeze -n "${name}"
lxc-stop -n "${name}" -t "${timeout}" &
lxc-stop -k -n "${name}" &
return 0;
fi
else
@@ -59,6 +72,12 @@ start_lxc_container() {
fi
}
stop_lxc_containers() {
for f in `lxc-ls`; do
lxc-stop -k -n $f >/dev/null 2>&1;
done
}
start_service() {
local enabled debug log_level sock lxc_bundle_root oci_bundle_root
@@ -70,9 +89,15 @@ start_service() {
[ "${enabled}" -eq 0 ] && return 0
# Create the bundle paths if not present
[ -n "${lxc_bundle_root}" ] && mkdir -p "${lxc_bundle_root}"
[ -n "${oci_bundle_root}" ] && mkdir -p "${oci_bundle_root}"
if [ ! -d "${lxc_bundle_root}" ]; then
log "# Not staring lxc [${lxc_bundle_root}] not present/defined"
return 1
fi
if [ ! -d "${oci_bundle_root}" ]; then
log "# Not staring oci [${oci_bundle_root}] not present/defined"
return 1
fi
procd_open_instance swmodd
procd_set_param command ${PROG}
@@ -94,8 +119,17 @@ start_service() {
if [ -f "${lxc_bundle_root}/lxccontainer" ]; then
UCI_CONFIG_DIR="${lxc_bundle_root}"
config_load lxccontainer
config_foreach start_lxc_container container
config_foreach start_lxc_container container ${lxc_bundle_root}
fi
if [ -f "${oci_bundle_root}/ocicontainer" ]; then
UCI_CONFIG_DIR="${oci_bundle_root}"
config_load ocicontainer
config_foreach start_lxc_container du_eu_assoc ${oci_bundle_root}
fi
}
stop_service() {
stop_lxc_containers
}
reload_service() {

View File

@@ -21,23 +21,18 @@ if [ -n "${lxc_bundle}" ]; then
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}
uci_commit
else
mkdir -p /etc/lxc
echo "lxc.lxcpath = /srv/" > /etc/lxc/lxc.conf
uci_set swmodd globals lxc_bundle_root "/srv/"
uci_commit
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}
uci_commit
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}
uci_commit
elif [ -z "${oci_bundle}" ]; then
uci_set swmodd globals oci_bundle_root "/srv/"
uci_commit
fi

View File

@@ -0,0 +1,47 @@
#!/bin/sh
. /lib/functions.sh
config_change=0
migrate_lxc() {
config_get name "${1}" name ""
if [ -z "${name}" ]; 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
fi
fi
}
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