Compare commits

...

4 Commits

Author SHA1 Message Date
Philip Meulengracht 1f8f97c438
Merge 684f4d25c8 into 7b9dc72c3c 2024-09-13 12:36:59 +02:00
Philip Meulengracht 684f4d25c8
test: ignore intentional shellchecks warnings 2022-11-21 13:01:06 +01:00
Philip Meulengracht edcbc020fb
test: add test to prove journal namespaces can now be flushed to /var 2022-11-21 12:42:03 +01:00
Philip Meulengracht ee1d8dc924
src/journal: allow namespaces to be flushed to /var 2022-11-21 12:41:23 +01:00
5 changed files with 80 additions and 3 deletions

View File

@ -1320,9 +1320,6 @@ int server_flush_to_var(Server *s, bool require_flag_file) {
if (!IN_SET(s->storage, STORAGE_AUTO, STORAGE_PERSISTENT))
return 0;
if (s->namespace) /* Flushing concept does not exist for namespace instances */
return 0;
if (!s->runtime_journal) /* Nothing to flush? */
return 0;

View File

@ -0,0 +1 @@
../TEST-01-BASIC/Makefile

View File

@ -0,0 +1,10 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -e
TEST_DESCRIPTION="test flushing log namespaces"
# shellcheck source=test/test-functions
. "${TEST_BASE_DIR:?}/test-functions"
do_test "$@"

View File

@ -0,0 +1,13 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
[Unit]
Description=TESTSUITE-77-FLUSH-LOG-NAMESPACES
Before=getty-pre.target
Wants=getty-pre.target
Wants=systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket
After=systemd-journald@foobar.socket systemd-journald-varlink@foobar.socket
[Service]
ExecStartPre=rm -f /failed /testok
ExecStart=/usr/lib/systemd/tests/testdata/units/%N.sh
Type=oneshot
LogTarget=foobar

56
test/units/testsuite-77.sh Executable file
View File

@ -0,0 +1,56 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1-or-later
set -eux
# first test is to make sure that /var/log/journal is not created
# by starting a new journal namespace if the journald config has
# Storage=auto
cat << EOF > /etc/systemd/journald@foobar.conf
[Journal]
Storage=auto
EOF
# for the above to work, we need to use a service drop-in to override
# the default LogsDirectory, otherwise Storage=auto will not work.
mkdir -p /etc/systemd/system/systemd-journald@foobar.service.d
cat << EOF > /etc/systemd/system/systemd-journald@foobar.service.d/00-test.conf
[Service]
LogsDirectory=
EOF
# reload systemd to detect the new drop-in
systemctl daemon-reload
# ensure /var/log/journal does not exist
rm -rf /var/log/journal
systemd-run --wait -p LogNamespace=foobar echo "hello world"
if [[ -d /var/log/journal ]]; then
echo "/var/log/journal was created with Storage=auto" >/failed
exit 1
fi
# now the runtime journal should exist, and when we create the
# persistent journal path /var/log/journal, the runtime journal
# should be flushed and moved out of /run
# expect /var/log/journal/%m.foobar
mkdir -p /var/log/journal
MACHINE_ID=$(cat /etc/machine-id)
# allow a few seconds for the flush to occur due to machine speeds
WAS_FLUSHED=false
# shellcheck disable=SC2034,SC2015
for i in {1..5}; do [ -d "/var/log/journal/$MACHINE_ID.foobar" ] && WAS_FLUSHED=true && break || sleep 1; done
if ! $WAS_FLUSHED; then
echo "/var/log/journal/$MACHINE_ID.foobar did not get created" >/failed
exit 1
fi
# after the flush of the runtime journal it should have been cleaned up
if [[ -d "/run/log/journal/$MACHINE_ID.foobar" ]]; then
echo "/run/log/journal/$MACHINE_ID.foobar was not flushed" >/failed
exit 1
fi
echo OK >/testok
exit 0