mirror of
https://github.com/openwrt/openwrt.git
synced 2025-03-12 15:34:59 +00:00
base-files: add the possibility to set sysctl via uci
With this change, sysctl parameters can be set via the uci. The following unamed section musst be set in '/etc/config/sysctl'. config sysctl option enable '1' option section 'net.ipv4.fib_multipath_hash_policy' option value '2' If the unamed section gets disabled, then the default value gets set, that was saved during boot. Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
parent
5446a1b179
commit
8767ba8698
@ -49,6 +49,7 @@ define Package/base-files/conffiles
|
|||||||
/etc/config/
|
/etc/config/
|
||||||
/etc/config/network
|
/etc/config/network
|
||||||
/etc/config/system
|
/etc/config/system
|
||||||
|
/etc/config/sysctl
|
||||||
/etc/dropbear/
|
/etc/dropbear/
|
||||||
/etc/ethers
|
/etc/ethers
|
||||||
/etc/group
|
/etc/group
|
||||||
|
@ -36,9 +36,42 @@ apply_defaults() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handle_sysctl() {
|
||||||
|
local cfg="$1"
|
||||||
|
local sysctl="$2"
|
||||||
|
|
||||||
|
local enable section value
|
||||||
|
|
||||||
|
config_get section "$cfg" section
|
||||||
|
[ -z "$section" ] && return
|
||||||
|
|
||||||
|
# check if section should be set and if not reset to default value
|
||||||
|
config_get_bool enable "$cfg" enable '0'
|
||||||
|
if [ "$enable" = '0' ]; then
|
||||||
|
value="$(grep "$section =" /tmp/sysctl-default.conf)"
|
||||||
|
value="${value##*= }"
|
||||||
|
else
|
||||||
|
config_get value "$cfg" value
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "$value" ] && return
|
||||||
|
|
||||||
|
echo "${section}=${value}" >> "$sysctl"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply_uci() {
|
||||||
|
mkdir -p /tmp/run/sysctl.d
|
||||||
|
|
||||||
|
rm -f /tmp/run/sysctl.d/01-uci.conf
|
||||||
|
|
||||||
|
config_load sysctl
|
||||||
|
config_foreach handle_sysctl sysctl "/tmp/run/sysctl.d/01-uci.conf"
|
||||||
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
apply_defaults
|
apply_defaults
|
||||||
[ -f /tmp/sysctl-default.conf ] || sysctl -a 1>/tmp/sysctl-default.conf 2>/dev/null
|
[ -f /tmp/sysctl-default.conf ] || sysctl -a 1>/tmp/sysctl-default.conf 2>/dev/null
|
||||||
|
apply_uci
|
||||||
for CONF in /etc/sysctl.d/*.conf /etc/sysctl.conf /tmp/run/sysctl.d/*.conf; do
|
for CONF in /etc/sysctl.d/*.conf /etc/sysctl.conf /tmp/run/sysctl.d/*.conf; do
|
||||||
[ -f "$CONF" ] && sysctl -e -p "$CONF" >&-
|
[ -f "$CONF" ] && sysctl -e -p "$CONF" >&-
|
||||||
done
|
done
|
||||||
|
Loading…
x
Reference in New Issue
Block a user