From cc626be7285888ec7032022f1fa6879553e0c226 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Thu, 19 Mar 2026 18:38:42 -0700 Subject: [PATCH] service: Capture stdout/stderr when running as systemd unit - Avoid duplicate log messages by not logging to console when running as systemd unit. - Retain normal logging when running on the terminal. Tests: - When running as systemd unit, output to stdin/stdout is captured in systemd journal and visible with 'sudo freedombox-logs'. - When running on terminal manually with 'sudo --user plinth ./run --develop' both log messages and stdout/stderr prints() are visible. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- data/usr/lib/systemd/system/plinth.service | 2 -- plinth/log.py | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/data/usr/lib/systemd/system/plinth.service b/data/usr/lib/systemd/system/plinth.service index 85a6abda7..3133e2c61 100644 --- a/data/usr/lib/systemd/system/plinth.service +++ b/data/usr/lib/systemd/system/plinth.service @@ -17,8 +17,6 @@ RestartSec=5 ExecReload=/bin/kill -HUP $MAINPID User=plinth Group=plinth -StandardOutput=null -StandardError=null NotifyAccess=main # Uploaded files in /var/tmp/ are shared with FreedomBox privileged service by # joining namespaces. diff --git a/plinth/log.py b/plinth/log.py index d77a66d5d..02d23c917 100644 --- a/plinth/log.py +++ b/plinth/log.py @@ -5,6 +5,7 @@ Setup logging for the application. import logging import logging.config +import sys import typing import warnings @@ -158,5 +159,11 @@ def get_configuration(): } } } + if not sys.stdin.isatty(): + # If running on a console, say due to user manually starting it, then + # log everything to console. However, if we are running as a systemd + # unit then no need to log to console. This allows us to capture + # stdout/stderr in systemd unit without repeating the log messages. + configuration['root']['handlers'].remove('console') return configuration