From 0d4bfa938cdd38a64e2e2cda2e8e7968e3e3179c Mon Sep 17 00:00:00 2001 From: "Alex Ellis (OpenFaaS Ltd)" Date: Wed, 19 Feb 2025 11:26:02 +0000 Subject: [PATCH] Add script to patch DigitalOcean for journal Signed-off-by: Alex Ellis (OpenFaaS Ltd) --- cmd/install.go | 5 +++-- hack/enable-journal.sh | 48 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 hack/enable-journal.sh diff --git a/cmd/install.go b/cmd/install.go index d2ca3b6..b01075d 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -93,8 +93,9 @@ Check the status of the faasd service with: sudo journalctl -u faasd --lines 100 -f Login with: - sudo -E cat /var/lib/faasd/secrets/basic-auth-password | faas-cli login -s -`) + sudo -E cat /var/lib/faasd/secrets/basic-auth-password | faas-cli login -s`) + + fmt.Println("") return nil } diff --git a/hack/enable-journal.sh b/hack/enable-journal.sh new file mode 100644 index 0000000..33b2c40 --- /dev/null +++ b/hack/enable-journal.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Copyright OpenFaaS Ltd 2025 + +# This script is for use with Droplets created on DigitalOcean, it will +# ensure that systemd-journald is configured to log to disk and that +# rsyslog is configured to read from systemd-journald. + +# Without this change, no logs will be available in the journal, and only +# /var/log/syslog will be populated. + +set -e + +echo "Checking systemd-journald logs..." +JOURNAL_STATUS=$(journalctl --no-pager -n 10 2>&1) + +if echo "$JOURNAL_STATUS" | grep -q "No journal files were found"; then + echo "No journal files found. Fixing logging configuration..." +else + echo "Journald appears to be logging. No changes needed." + exit 0 +fi + +# Backup original config before making changes +sudo cp /etc/systemd/journald.conf /etc/systemd/journald.conf.bak + +# Ensure Storage is persistent +sudo sed -i '/^#Storage=/c\Storage=persistent' /etc/systemd/journald.conf + +# Ensure logs are not forwarded only to syslog +sudo sed -i '/^#ForwardToSyslog=/c\ForwardToSyslog=no' /etc/systemd/journald.conf + +# Restart systemd-journald +echo "Restarting systemd-journald..." +sudo systemctl restart systemd-journald + +# Check if rsyslog already loads imjournal +if ! grep -q 'module(load="imjournal")' /etc/rsyslog.conf; then + echo "Adding imjournal module to rsyslog..." + echo 'module(load="imjournal" StateFile="/var/lib/rsyslog/imjournal.state")' | sudo tee -a /etc/rsyslog.conf +fi + +# Restart rsyslog to apply changes +echo "Restarting rsyslog..." +sudo systemctl restart rsyslog + +echo "Done. Checking if logs appear in journald..." +journalctl --no-pager -n 10