From 05c53d25786bb2683f1ceeaa6bf3ee5fbea52a97 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 29 Jun 2021 14:10:59 -0400 Subject: [PATCH 1/2] overlay/05core: Set systemd LogColor=false We deploy on servers. The ANSI colors codes in the console output often end up in e.g. log files where they both make the logs hard to read *and* they make log files invalid UTF-8. This file needs to be created in both the real root and the initramfs, so extend our `99journald-conf` to be `99systemd-conf`. --- .../00-journal-log-forwarding.conf | 0 .../dracut/modules.d/99systemd-conf/10-coreos-nocolor.conf | 6 ++++++ .../{99journal-conf => 99systemd-conf}/module-setup.sh | 3 +++ .../usr/lib/systemd/system.conf.d/10-coreos-nocolor.conf | 6 ++++++ 4 files changed, 15 insertions(+) rename overlay.d/05core/usr/lib/dracut/modules.d/{99journal-conf => 99systemd-conf}/00-journal-log-forwarding.conf (100%) create mode 100644 overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/10-coreos-nocolor.conf rename overlay.d/05core/usr/lib/dracut/modules.d/{99journal-conf => 99systemd-conf}/module-setup.sh (65%) create mode 100644 overlay.d/05core/usr/lib/systemd/system.conf.d/10-coreos-nocolor.conf diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/99journal-conf/00-journal-log-forwarding.conf b/overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/00-journal-log-forwarding.conf similarity index 100% rename from overlay.d/05core/usr/lib/dracut/modules.d/99journal-conf/00-journal-log-forwarding.conf rename to overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/00-journal-log-forwarding.conf diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/10-coreos-nocolor.conf b/overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/10-coreos-nocolor.conf new file mode 100644 index 0000000000..e750ac813c --- /dev/null +++ b/overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/10-coreos-nocolor.conf @@ -0,0 +1,6 @@ +# We deploy on servers. The ANSI colors codes in the console +# output often end up in e.g. log files where they both +# make the logs hard to read *and* they make log files +# invalid UTF-8. +[Manager] +LogColor=false diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/99journal-conf/module-setup.sh b/overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/module-setup.sh similarity index 65% rename from overlay.d/05core/usr/lib/dracut/modules.d/99journal-conf/module-setup.sh rename to overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/module-setup.sh index e6626b2899..8955515cb1 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/99journal-conf/module-setup.sh +++ b/overlay.d/05core/usr/lib/dracut/modules.d/99systemd-conf/module-setup.sh @@ -1,4 +1,5 @@ #!/bin/bash +# Configuration for systemd in the initramfs. # -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*- # ex: ts=8 sw=4 sts=4 et filetype=sh @@ -7,6 +8,8 @@ depends() { } install() { + inst_simple "$moddir/10-coreos-nocolor.conf" \ + "/etc/systemd/system.conf.d/00-coreos-nocolor.conf" inst_simple "$moddir/00-journal-log-forwarding.conf" \ "/etc/systemd/journald.conf.d/00-journal-log-forwarding.conf" } diff --git a/overlay.d/05core/usr/lib/systemd/system.conf.d/10-coreos-nocolor.conf b/overlay.d/05core/usr/lib/systemd/system.conf.d/10-coreos-nocolor.conf new file mode 100644 index 0000000000..e750ac813c --- /dev/null +++ b/overlay.d/05core/usr/lib/systemd/system.conf.d/10-coreos-nocolor.conf @@ -0,0 +1,6 @@ +# We deploy on servers. The ANSI colors codes in the console +# output often end up in e.g. log files where they both +# make the logs hard to read *and* they make log files +# invalid UTF-8. +[Manager] +LogColor=false From c961c5672a1bf82669a2762e982ab294627be70b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 29 Jun 2021 18:11:33 -0400 Subject: [PATCH 2/2] overlay/99emergency-timeout: Set SYSTEMD_COLORS=0 for `journalctl` Also suppress colors here since `journalctl` defaults to coloring if it thinks it can, and the way we're explicitly forwarding the journal bypasses the logic for systemd's default console coloring that we inject via default config. (Long term, I think it would make sense probably to move this "failed in the initramfs" handling into systemd itself and not be in custom shell script we carry) --- .../usr/lib/dracut/modules.d/99emergency-timeout/timeout.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/99emergency-timeout/timeout.sh b/overlay.d/05core/usr/lib/dracut/modules.d/99emergency-timeout/timeout.sh index 85fb3d761d..f7cee78bb8 100644 --- a/overlay.d/05core/usr/lib/dracut/modules.d/99emergency-timeout/timeout.sh +++ b/overlay.d/05core/usr/lib/dracut/modules.d/99emergency-timeout/timeout.sh @@ -56,7 +56,10 @@ EOF echo "Displaying logs from failed units: ${failed}" for unit in ${failed}; do # 10 lines should be enough for everyone - journalctl -b --no-pager --no-hostname -u ${unit} -n 10 + # For color suppression, see https://github.com/coreos/fedora-coreos-config/pull/1079 + # and 10-coreos-nocolor.conf. Our console logs often end up saved into + # files and the ANSI codes just look like corruption (and are invalid UTF-8). + SYSTEMD_COLORS=0 journalctl -b --no-pager --no-hostname -u ${unit} -n 10 done fi