[arch-projects] [INITSCRIPTS][PATCH] Load sysctl config files from sysctl.d

Sebastien Luttringer seblu at seblu.net
Wed Aug 31 05:39:16 EDT 2011

This patch implement loading of sysctl config files as described in

This is a very conveniant way of configuring sysctl option for sysadmin
which can drop sysctl config files inside this directory to enable some

Dropping a file like disableipv6.conf inside this directory will disable ipv6
$ cat disableipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1

There is atm no package which use this functionnality

NOTE: /etc/sysctl.d/ and /usr/lib/sysctl.d/ should be added in procps

NOTE: maybe this feature should be added as a daemon for procps package
allowing user to reload configs files by calling rc.d reload procps
 rc.multi      |   22 +++++++++++++++++++++-
 tmpfiles.conf |    1 +
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/rc.multi b/rc.multi
index 16fa83a..5974a35 100755
--- a/rc.multi
+++ b/rc.multi
@@ -6,11 +6,31 @@
 . /etc/rc.conf
 . /etc/rc.d/functions
+shopt -s nullglob
 run_hook multi_start
-# Load sysctl variables if sysctl.conf is present
+# Load sysctl variables from sysctl.conf (backward compatibility)
 [[ -r /etc/sysctl.conf ]] && sysctl -q -p &>/dev/null
+# Load sysctl variables (new style)
+# http://0pointer.de/public/systemd-man/sysctl.d.html
+declare -a sysctl_d=(
+	/usr/lib/sysctl.d
+	/etc/sysctl.d
+	/run/sysctl.d
+declare -A sysctl_c
+for _d in "${sysctl_d[@]}"; do
+	[[ -d "$_d" ]] || continue
+	for _f in "$_d"/*.conf; do
+		sysctl_c[${_f##*/}]="$_f"
+	done
+for _f in "${sysctl_c[@]}"; do
+	sysctl -q -p "$_f" &>/dev/null
 # Start daemons
 for daemon in "${DAEMONS[@]}"; do
 	case ${daemon:0:1} in
diff --git a/tmpfiles.conf b/tmpfiles.conf
index 7dd1358..61081d0 100644
--- a/tmpfiles.conf
+++ b/tmpfiles.conf
@@ -4,6 +4,7 @@
 D /tmp              1777 root root
 D /run/daemons      0755 root root
+D /run/sysctl.d     0755 root root
 d /tmp/.X11-unix    1777 root root
 d /tmp/.ICE-unix    1777 root root
Sebastien "Seblu" Luttringer

More information about the arch-projects mailing list