iopsys-feed/map-topology/files/etc/init.d/topologyd
2023-01-12 09:47:28 +05:30

93 lines
1.7 KiB
Bash
Executable file

#!/bin/sh /etc/rc.common
START=97
STOP=21
USE_PROCD=1
IS_CFG_VALID=1
validate_topology_config() {
uci_validate_section topology topology "topology" \
'enabled:bool:true' \
'depth:range(0,16)' \
'interval:range(0,65535)' \
'maxlog:range(0,128)' \
[ "$?" -ne 0 ] && {
logger -s -t "topology" "Validation of topology UCI file failed"
return 1
}
return 0
}
validate_global_section() {
uci_validate_section hosts global "global" \
'ageing_timer:uinteger' \
'reboot_persistent:bool'
[ "$?" -ne 0 ] && {
logger -s -t "hosts" "Validation of global section failed"
IS_CFG_VALID=0
return 1
}
return 0
}
validate_host_section() {
local section="$1"
uci_validate_section hosts $section "${1}" \
'macaddr:macaddr' \
'interface_type:or("wifi","eth")' \
'active:bool' \
'active_last_change:string'
[ "$?" -ne 0 ] && {
logger -s -t "hosts" "Validation of host section $section failed"
IS_CFG_VALID=0
return 1
}
return 0
}
validate_hosts_config() {
IS_CFG_VALID=1
validate_global_section &&
config_foreach validate_host_section host
[ "$IS_CFG_VALID" -ne 1 ] && {
logger -s -t "topology" "Validation of hosts UCI file failed"
return 1
}
return 0
}
start_service() {
config_load "topology"
validate_topology_config || return 1;
config_load "hosts"
validate_hosts_config || return 1;
if [ -f "/proc/sys/net/netfilter/nf_conntrack_timestamp" ]; then
echo 1 >/proc/sys/net/netfilter/nf_conntrack_timestamp
fi
procd_open_instance
procd_set_param command "/usr/sbin/topologyd"
procd_set_param respawn
# procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
service_triggers()
{
procd_add_reload_trigger "network"
}
reload_service() {
procd_send_signal "topologyd"
}