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 <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2026-03-19 18:38:42 -07:00 committed by James Valleroy
parent c0d603af07
commit cc626be728
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 7 additions and 2 deletions

View File

@ -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.

View File

@ -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