mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
swmodd: Remove dependency of lxc autoboot
This commit is contained in:
parent
c6d3812b92
commit
dfc004dc6e
4 changed files with 90 additions and 15 deletions
|
|
@ -5,12 +5,12 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=swmodd
|
||||
PKG_VERSION:=2.1.11
|
||||
PKG_VERSION:=2.1.12
|
||||
|
||||
LOCAL_DEV:=0
|
||||
ifneq ($(LOCAL_DEV),1)
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=d3657ecee7a3f6725ff91b0803e1247c0538bd44
|
||||
PKG_SOURCE_VERSION:=9fd50dd2c526c8b58c2d2d62042c261e6a7b65e0
|
||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/swmodd.git
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
||||
PKG_MIRROR_HASH:=skip
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ start_service() {
|
|||
fi
|
||||
|
||||
config_load swmodd
|
||||
config_get bundle globals bundle_root ""
|
||||
config_get bundle globals oci_bundle_root ""
|
||||
config_get bridge globals lan_bridge "br-lan"
|
||||
|
||||
if [ -z "${bundle}" ] || [ -z "${bridge}" ]; then
|
||||
|
|
|
|||
|
|
@ -12,25 +12,76 @@ validate_globals_section()
|
|||
'enabled:bool:1' \
|
||||
'debug:bool:false' \
|
||||
'log_level:uinteger:1' \
|
||||
'bundle_root:string' \
|
||||
'lxc_bundle_root:string' \
|
||||
'oci_bundle_root:string' \
|
||||
'sock:string'
|
||||
}
|
||||
|
||||
validate_container_section() {
|
||||
uci_validate_section swmodd container "${1}" \
|
||||
'name:string' \
|
||||
'type:string' \
|
||||
'autostart:bool:0' \
|
||||
'timeout:uinteger:300'
|
||||
}
|
||||
|
||||
start_lxc_container() {
|
||||
local name type autostart timeout
|
||||
|
||||
validate_container_section "${1}" || {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if [ -z "${name}" ] || [ -z "${type}" ]; then
|
||||
return 0;
|
||||
fi
|
||||
|
||||
if [ "${type}" != "lxc" ]; then
|
||||
return 0;
|
||||
fi
|
||||
|
||||
state=$(lxc-ls -f | tail -n +2 | grep -w "${name}" | cut -d " " -f 2)
|
||||
if [ -z "${state}" ]; then
|
||||
return 0;
|
||||
fi
|
||||
|
||||
if [ "${autostart}" -eq 0 ]; then
|
||||
if [ "${state}" == "RUNNING" ]; then
|
||||
# stop the container if running
|
||||
lxc-stop -n "${name}" -t "${timeout}" &
|
||||
return 0;
|
||||
elif [ "${state}" == "FROZEN" ]; then
|
||||
# first unfreeze then stop
|
||||
lxc-unfreeze -n "${name}"
|
||||
lxc-stop -n "${name}" -t "${timeout}" &
|
||||
return 0;
|
||||
fi
|
||||
else
|
||||
if [ "${state}" == "FROZEN" ]; then
|
||||
# unfreeze the container
|
||||
lxc-unfreeze -n "${name}"
|
||||
elif [ "${state}" == "STOPPED" ]; then
|
||||
# start the container
|
||||
lxc-start -n "${name}"
|
||||
return 0;
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local enabled debug log_level sock bundle_root
|
||||
local enabled debug log_level sock lxc_bundle_root oci_bundle_root
|
||||
|
||||
config_load swmodd
|
||||
|
||||
validate_globals_section || {
|
||||
log "Validation of uci globals failed"
|
||||
return 1;
|
||||
}
|
||||
|
||||
[ "${enabled}" -eq 0 ] && return 0
|
||||
|
||||
[ -z "${bundle_root}" ] && return 0
|
||||
[ -z "${lxc_bundle_root}" ] && mkdir -p "${lxc_bundle_root}"
|
||||
[ -z "${oci_bundle_root}" ] && mkdir -p "${oci_bundle_root}"
|
||||
|
||||
mkdir -p "${bundle_root}"
|
||||
procd_open_instance swmodd
|
||||
procd_set_param command ${PROG}
|
||||
|
||||
|
|
@ -46,6 +97,8 @@ start_service() {
|
|||
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
|
||||
config_foreach start_lxc_container container
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
|
|
|
|||
|
|
@ -2,20 +2,42 @@
|
|||
|
||||
. /lib/functions.sh
|
||||
|
||||
# if bundle_root not define in swmodd, update it with lxc path
|
||||
lxc=""
|
||||
bundle=""
|
||||
lxc_bundle=""
|
||||
oci_bundle=""
|
||||
|
||||
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 bundle globals bundle_root ""
|
||||
if [ -z "${bundle}" ] && [ -n "${lxc}" ]; then
|
||||
uci_set swmodd globals bundle_root ${lxc}
|
||||
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
|
||||
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}
|
||||
uci_commit
|
||||
elif [ -z "${bundle}" ]; then
|
||||
uci_set swmodd globals bundle_root "/tmp/"
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue