#! /bin/bash # Rocky9 compatible # script tunes logging settings to minimize shitty systemd-journald messing up the system . /usr/src/k_framework/main.sh # ---- VARS ----- VERSION="1.0.9" SCRIPT_NAME="journald Tune" # ---- FUNCTIONS ----- # ---- MAIN ----- k_start k_detect_os # in case there is no /etc/machine-id systemd-machine-id-setup if [ ! -f /etc/machine-id ]; then report "/etc/machine-id missing" 1 report " systemd-firstboot --setup-machine-id" fix EXIT_CODE=1 k_exit 1 fi report "Checking /etc/rsyslog.conf" 3 if [ -f /etc/rsyslog.conf ]; then report "/etc/rsyslog.conf present" 0 else report "/etc/rsyslog.conf not present" 1 EXIT_CODE=1 k_exit 1 fi if [[ $ROCKY9 == 1 ]]; then cp -fr /usr/src/k_framework/helpers/rsyslog/rsyslog.conf_ksr_r9 /etc/rsyslog.conf else if cat /etc/rsyslog.conf | grep -q "\$IMJournalRatelimitInterval"; then report "\$IMJournalRatelimitInterval configured" 0 else report "Adding \$IMJournalRatelimitInterval" 3 sed -i "s|imjournal.state\+|imjournal.state\n\n\$IMJournalRatelimitInterval 0|g" /etc/rsyslog.conf fi if cat /etc/rsyslog.conf | grep -q "\$IMUXSockRateLimitInterval"; then report "\$IMUXSockRateLimitInterval configured" 0 else report "Adding \$IMUXSockRateLimitInterval" 3 sed -i "s|imjournal.state\+|imjournal.state\n\n\$IMUXSockRateLimitInterval 0|g" /etc/rsyslog.conf fi if cat /etc/rsyslog.conf | grep -q "\$SystemLogRateLimitBurst"; then report "\$SystemLogRateLimitBurst configured" 0 else report "Adding \$SystemLogRateLimitBurst" 3 sed -i "s|imjournal.state\+|imjournal.state\n\n\$SystemLogRateLimitBurst 0|g" /etc/rsyslog.conf fi if cat /etc/rsyslog.conf | grep -q "\$SystemLogRateLimitInterval"; then report "\$SystemLogRateLimitInterval configured" 0 else report "Adding \$SystemLogRateLimitInterval" 3 sed -i "s|imjournal.state\+|imjournal.state\n\n\$SystemLogRateLimitInterval 0|g" /etc/rsyslog.conf fi fi report "Checking /etc/systemd/journald.conf" 3 if [ -f /etc/systemd/journald.conf ]; then report "/etc/systemd/journald.conf present" 0 else report "/etc/systemd/journald.conf not present" 1 EXIT_CODE=1 k_exit 1 fi report "Setting RateLimitInterval=0" 0 sed -i '/RateLimitInterval/d' /etc/systemd/journald.conf echo "RateLimitInterval=0" >> /etc/systemd/journald.conf report "Setting RateLimitBurst=0" 0 sed -i '/RateLimitBurst/d' /etc/systemd/journald.conf echo "RateLimitBurst=0" >> /etc/systemd/journald.conf report "Setting Storage=volatile" 0 sed -i '/Storage/d' /etc/systemd/journald.conf echo "Storage=volatile" >> /etc/systemd/journald.conf report "Setting Compress=no" 0 sed -i '/Compress/d' /etc/systemd/journald.conf echo "Compress=no" >> /etc/systemd/journald.conf report "Setting MaxRetentionSec=5s" 0 sed -i '/MaxRetentionSec/d' /etc/systemd/journald.conf echo "MaxRetentionSec=5s" >> /etc/systemd/journald.conf report "Checking /var/log/journal" 3 if [ -d /var/log/journal ]; then report "/var/log/journal present" 3 mv /var/log/journal /var/log/journal-disabled if [ -d /var/log/journal ]; then report "Failed to rename /var/log/journal" 1 else report "/var/log/journal disabled" 0 fi else report "/var/log/journal already disabled" 0 fi report "Restarting services" 3 systemctl restart systemd-journald > /dev/null 2>&1 sleep 2 systemctl restart rsyslog > /dev/null 2>&1 k_exit $EXIT_CODE