From b29e32df30f5cfed250a347cc63c147d13b65a90 Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Sat, 12 Mar 2022 16:23:18 -0600 Subject: [PATCH] rootfs: Get syslog servers from DHCP options Instead of parsing the kernel command line to find the destination(s) where syslog messages should be forwarded, we can use a *dhcpcd* hook to get them from the DHCP lease. --- cmdline.txt | 2 +- rootfs/overlay/etc/dhcpcd.conf | 2 ++ .../usr/lib/dhcpcd/dhcpcd-hooks/60-syslog | 28 +++++++++++++++++++ .../systemd/system/gen-rsyslog-conf.service | 7 ----- .../after-network-online.conf | 2 ++ .../gen-rsyslog-conf.service | 1 - .../overlay/usr/libexec/gen-rsyslog-conf.sh | 12 -------- 7 files changed, 33 insertions(+), 21 deletions(-) create mode 100644 rootfs/overlay/usr/lib/dhcpcd/dhcpcd-hooks/60-syslog delete mode 100644 rootfs/overlay/usr/lib/systemd/system/gen-rsyslog-conf.service create mode 100644 rootfs/overlay/usr/lib/systemd/system/rsyslog.service.d/after-network-online.conf delete mode 120000 rootfs/overlay/usr/lib/systemd/system/rsyslog.service.wants/gen-rsyslog-conf.service delete mode 100755 rootfs/overlay/usr/libexec/gen-rsyslog-conf.sh diff --git a/cmdline.txt b/cmdline.txt index 21320e6..32d518e 100644 --- a/cmdline.txt +++ b/cmdline.txt @@ -1 +1 @@ -audit=0 panic=5 console=ttyAMA0 root=nbd:rosalina.pyrocufflink.blue:jenkinsagent rsyslog.dest=rosalina.pyrocufflink.blue sshkeys.root=http://rosalina.pyrocufflink.blue/~dustin/id_ed25519.pub +audit=0 panic=5 console=ttyAMA0 root=nbd:rosalina.pyrocufflink.blue:jenkinsagent sshkeys.root=http://rosalina.pyrocufflink.blue/~dustin/id_ed25519.pub diff --git a/rootfs/overlay/etc/dhcpcd.conf b/rootfs/overlay/etc/dhcpcd.conf index 7ee8c1a..e61eec7 100644 --- a/rootfs/overlay/etc/dhcpcd.conf +++ b/rootfs/overlay/etc/dhcpcd.conf @@ -39,6 +39,8 @@ option ntp_servers # on the server to actually work. option rapid_commit +option log_servers + # A ServerID is required by RFC2131. require dhcp_server_identifier diff --git a/rootfs/overlay/usr/lib/dhcpcd/dhcpcd-hooks/60-syslog b/rootfs/overlay/usr/lib/dhcpcd/dhcpcd-hooks/60-syslog new file mode 100644 index 0000000..f377917 --- /dev/null +++ b/rootfs/overlay/usr/lib/dhcpcd/dhcpcd-hooks/60-syslog @@ -0,0 +1,28 @@ +#!/bin/sh + +gen_action() { + echo 'action(' + echo ' type="omfwd"' + printf ' Target="%s"\n' "${1}" + echo ' Port="514"' + echo ' template="RSYSLOG_SyslogProtocol23Format"' + echo ')' +} + +changed=false +if [ -n "${interface}" ] && [ -d /run/rsyslog.d ]; then + if [ -n "${new_log_servers}" ]; then + echo '# Generated by dhcpcd' > /run/rsyslog.d/dhcpcd."${interface}".conf + for s in ${new_log_servers}; do + gen_action "${s}" >> /run/rsyslog.d/dhcpcd."${interface}".conf + done + changed=true + elif [ -n "${old_log_servers}" ]; then + rm -f /run/rsyslog.d/dhcpcd."${interface}".conf + changed=true + fi +fi + +if ${changed}; then + systemctl try-restart rsyslog +fi diff --git a/rootfs/overlay/usr/lib/systemd/system/gen-rsyslog-conf.service b/rootfs/overlay/usr/lib/systemd/system/gen-rsyslog-conf.service deleted file mode 100644 index 62081b2..0000000 --- a/rootfs/overlay/usr/lib/systemd/system/gen-rsyslog-conf.service +++ /dev/null @@ -1,7 +0,0 @@ -[Unit] -Description=Generate rsyslog.conf -Before=rsyslog.service - -[Service] -Type=oneshot -ExecStart=/usr/libexec/gen-rsyslog-conf.sh diff --git a/rootfs/overlay/usr/lib/systemd/system/rsyslog.service.d/after-network-online.conf b/rootfs/overlay/usr/lib/systemd/system/rsyslog.service.d/after-network-online.conf new file mode 100644 index 0000000..758b827 --- /dev/null +++ b/rootfs/overlay/usr/lib/systemd/system/rsyslog.service.d/after-network-online.conf @@ -0,0 +1,2 @@ +[Unit] +After=network-online.target diff --git a/rootfs/overlay/usr/lib/systemd/system/rsyslog.service.wants/gen-rsyslog-conf.service b/rootfs/overlay/usr/lib/systemd/system/rsyslog.service.wants/gen-rsyslog-conf.service deleted file mode 120000 index d670be7..0000000 --- a/rootfs/overlay/usr/lib/systemd/system/rsyslog.service.wants/gen-rsyslog-conf.service +++ /dev/null @@ -1 +0,0 @@ -../gen-rsyslog-conf.service \ No newline at end of file diff --git a/rootfs/overlay/usr/libexec/gen-rsyslog-conf.sh b/rootfs/overlay/usr/libexec/gen-rsyslog-conf.sh deleted file mode 100755 index 340a0e1..0000000 --- a/rootfs/overlay/usr/libexec/gen-rsyslog-conf.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -e - -# shellcheck disable=SC2046 -set -- $(cat /proc/cmdline) -while [ $# -ge 1 ]; do - case "$1" in - rsyslog.dest=*) - printf '*.* @%s\n' "${1#*=}" >> /run/rsyslog.d/remote.conf - ;; - esac - shift -done