|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Configure rsyslog to forward the IPA ramdisk's logs to a remote syslog |
| 4 | +# collector during cleaning/inspection/deploy. |
| 5 | +# |
| 6 | +# The destination is read from the kernel command line so the image stays |
| 7 | +# site-agnostic (one shared IPA image across all sites). Ironic passes it via |
| 8 | +# [redfish]kernel_append_params / [pxe]pxe_append_params in each deploy site's |
| 9 | +# ironic/values.yaml, e.g. syslog_server=10.46.100.83 (optionally with |
| 10 | +# syslog_port=514). This mirrors how the stock dynamic-login element reads |
| 11 | +# rootpwd=/sshkey= from /proc/cmdline. |
| 12 | +# |
| 13 | +# rsyslog reads the systemd journal (imjournal), so everything IPA logs to the |
| 14 | +# journal is forwarded. Forwarding is RFC3164 over TCP by default (reliable); |
| 15 | +# the OTEL syslog receiver listens on both UDP and TCP 514. |
| 16 | + |
| 17 | +# dib-lint: disable=set setu setpipefail indent |
| 18 | +if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then |
| 19 | + set -x |
| 20 | +fi |
| 21 | +set -e |
| 22 | + |
| 23 | +CMDLINE=$(</proc/cmdline) |
| 24 | + |
| 25 | +SYSLOG_SERVER="" |
| 26 | +if [[ $CMDLINE =~ syslog_server=\"?([^\"[:space:]]+)\"? ]]; then |
| 27 | + SYSLOG_SERVER="${BASH_REMATCH[1]}" |
| 28 | +fi |
| 29 | + |
| 30 | +# No target configured -> leave rsyslog at its defaults (local only) and exit |
| 31 | +# cleanly so this never blocks boot. |
| 32 | +if [ -z "$SYSLOG_SERVER" ]; then |
| 33 | + echo "undercloud-rsyslog: no syslog_server= on kernel cmdline, skipping remote forwarding" |
| 34 | + exit 0 |
| 35 | +fi |
| 36 | + |
| 37 | +SYSLOG_PORT="514" |
| 38 | +if [[ $CMDLINE =~ syslog_port=\"?([0-9]+)\"? ]]; then |
| 39 | + SYSLOG_PORT="${BASH_REMATCH[1]}" |
| 40 | +fi |
| 41 | + |
| 42 | +# Protocol: @@ = TCP (reliable), @ = UDP. Default to TCP; allow syslog_proto=udp. |
| 43 | +PREFIX="@@" |
| 44 | +if [[ $CMDLINE =~ syslog_proto=udp ]]; then |
| 45 | + PREFIX="@" |
| 46 | +fi |
| 47 | + |
| 48 | +cat > /etc/rsyslog.d/99-undercloud-remote.conf <<EOF |
| 49 | +# Managed by undercloud-rsyslog element (generated at boot from kernel cmdline). |
| 50 | +# Pull from the systemd journal and forward everything to the remote collector. |
| 51 | +module(load="imjournal" StateFile="imjournal.state") |
| 52 | +
|
| 53 | +# rsyslog starts before DHCP finishes, so the first connection attempts fail. |
| 54 | +# The in-memory queue holds messages while the action is suspended, and a short, |
| 55 | +# capped resume interval makes forwarding start soon after the network is up. |
| 56 | +action( |
| 57 | + type="omfwd" |
| 58 | + target="${SYSLOG_SERVER}" |
| 59 | + port="${SYSLOG_PORT}" |
| 60 | + protocol="$([ "$PREFIX" = "@@" ] && echo tcp || echo udp)" |
| 61 | + action.resumeRetryCount="-1" |
| 62 | + action.resumeInterval="2" |
| 63 | + action.resumeIntervalMax="10" |
| 64 | + queue.type="linkedList" |
| 65 | + queue.saveOnShutdown="off" |
| 66 | + queue.size="50000" |
| 67 | +) |
| 68 | +EOF |
| 69 | + |
| 70 | +echo "undercloud-rsyslog: forwarding journal to ${PREFIX}${SYSLOG_SERVER}:${SYSLOG_PORT}" |
| 71 | + |
| 72 | +# Do NOT restart rsyslog here. This unit is ordered Before=rsyslog.service, so |
| 73 | +# rsyslog picks up the drop-in on its first start. Calling systemctl restart from |
| 74 | +# here would deadlock until the unit's start timeout. |
0 commit comments