From: Zbigniew Jędrzejewski-Szmek Date: Fri, 7 Nov 2025 14:43:34 +0000 (+0100) Subject: journald: allow default storage mode to be configured X-Git-Tag: v259-rc1~72^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7af88c1e1ef9e9549671e7d8e45c10964aad2b7a;p=thirdparty%2Fsystemd.git journald: allow default storage mode to be configured So far the idea was that the default is 'auto', and if appropriate, the distribution will create /var/log/journal/ to tell journald to use persistent mode. This doesn't work well with factory resets, because after a factory reset obviously /var/log is gone. That old default was useful when journald was new and people were reluctant to enable persistent mode and instead relied on rsyslog and such for the persistent storage. But nowadays that is rarer, and anyway various features like user journals only work with persistent storage, so we want people to enable this by default. Add an option to flip the default and distributions can opt in. The default default value remains unchanged. (I also tested using tmpfiles to instead change this, since we already set access mode for /var/log/journal through tmpfiles. Unfortunately, tmpfiles runs too late, after journald has already started, so if tmpfiles creates the directory, it'll only be used after a reboot. This probably could be made to work by adding a new service to flush the journal, but that becomes complicated and we lose the main advantage of simplicity.) Resolves https://bugzilla.redhat.com/show_bug.cgi?id=1387796. --- diff --git a/man/custom-entities.ent.in b/man/custom-entities.ent.in index 6338ad13f96..1f3ecefe614 100644 --- a/man/custom-entities.ent.in +++ b/man/custom-entities.ent.in @@ -10,6 +10,7 @@ + diff --git a/man/journald.conf.xml b/man/journald.conf.xml index 1d615b110dc..322fe6d17b6 100644 --- a/man/journald.conf.xml +++ b/man/journald.conf.xml @@ -1,6 +1,9 @@ + "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ + +%entities; +]> /var/log/journal directory exists, and volatile otherwise (the existence of the directory controls the storage mode). none turns off all storage, all log data received will be dropped (but forwarding to other targets, such as the console, - the kernel log buffer, or a syslog socket will still work). Defaults to auto in - the default journal namespace, and persistent in all others. + the kernel log buffer, or a syslog socket will still work). Defaults to + &JOURNAL_STORAGE_DEFAULT; in the default journal namespace (this value is + determined at compilation time), and persistent in all others. Note that journald will initially use volatile storage, until a call to journalctl --flush (or sending SIGUSR1 to journald) will cause diff --git a/meson.build b/meson.build index 599d2a3217d..055ee31ee4c 100644 --- a/meson.build +++ b/meson.build @@ -117,6 +117,9 @@ conf.set10('BUMP_PROC_SYS_FS_FILE_MAX', get_option('bump-proc-sys-fs-file-max')) conf.set10('BUMP_PROC_SYS_FS_NR_OPEN', get_option('bump-proc-sys-fs-nr-open')) conf.set('HIGH_RLIMIT_NOFILE', 512*1024) +conf.set('JOURNAL_STORAGE_DEFAULT', get_option('journal-storage-default')) +conf.set('JOURNAL_STORAGE_DEFAULT_VAL', 'STORAGE_' + get_option('journal-storage-default').to_upper()) + # Meson ignores the preceding arguments when joining paths if an absolute # component is encountered, so this should canonicalize various paths when they # are absolute or relative. @@ -3096,6 +3099,7 @@ summary({ 'default locale' : default_locale, 'default nspawn locale' : nspawn_locale, 'default status unit format' : status_unit_format_default, + 'default journal storage mode' : conf.get('JOURNAL_STORAGE_DEFAULT'), 'default user $PATH' : default_user_path != '' ? default_user_path : '(same as system services)', 'systemd service watchdog' : service_watchdog == '' ? 'disabled' : service_watchdog, 'time epoch' : f'@time_epoch@ (@alt_time_epoch@)', diff --git a/meson_options.txt b/meson_options.txt index 1d7c4f4bd27..f8a0fe37123 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -139,6 +139,8 @@ option('timedated', type : 'boolean', description : 'install the systemd-timedated daemon') option('timesyncd', type : 'boolean', description : 'install the systemd-timesyncd daemon') +option('journal-storage-default', type : 'combo', choices : ['auto', 'volatile', 'persistent', 'none'], + description : 'default storage mode for journald (main namespace)') option('remote', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' }, description : 'support for "journal over the network"') option('create-log-dirs', type : 'boolean', diff --git a/src/journal/journald-config.c b/src/journal/journald-config.c index 8cffec880b2..de78a40008f 100644 --- a/src/journal/journald-config.c +++ b/src/journal/journald-config.c @@ -116,7 +116,7 @@ void manager_merge_configs(Manager *m) { journal_config_done(&m->config); - MERGE_NON_NEGATIVE(storage, STORAGE_AUTO); + MERGE_NON_NEGATIVE(storage, JOURNAL_STORAGE_DEFAULT_VAL); manager_merge_journal_compress_options(m); MERGE_NON_NEGATIVE(seal, true); /* By default, /dev/kmsg is read only by the main namespace instance. */ diff --git a/src/journal/journald.conf.in b/src/journal/journald.conf.in index 9a12ca76576..805b79bc8ad 100644 --- a/src/journal/journald.conf.in +++ b/src/journal/journald.conf.in @@ -17,7 +17,7 @@ # See journald.conf(5) for details. [Journal] -#Storage=auto +#Storage={{ JOURNAL_STORAGE_DEFAULT }} #Compress=yes #Seal=yes #SplitMode=uid