From 167241912f51fbc0d7d0869b9af34c15b5ecc4b6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 Apr 2020 16:12:00 +0200 Subject: [PATCH 1/5] units: pull in systemd-pstore.service from sysinit.target sysinit.target is the target our early boot services are generally pulled in from, make systemd-pstore.service not an exception of that. Effectively this doesn't mean much, either way our unit is part of the initial transaction. --- units/systemd-pstore.service.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/units/systemd-pstore.service.in b/units/systemd-pstore.service.in index 89f34afe34..37fcf878f0 100644 --- a/units/systemd-pstore.service.in +++ b/units/systemd-pstore.service.in @@ -15,6 +15,7 @@ ConditionVirtualization=!container DefaultDependencies=no Wants=systemd-remount-fs.service After=systemd-remount-fs.service +Before=sysinit.target [Service] Type=oneshot @@ -23,4 +24,4 @@ RemainAfterExit=yes StateDirectory=systemd/pstore [Install] -WantedBy=systemd-remount-fs.service +WantedBy=sysinit.target From f3b7a79b973a28af4f7a592a8b2e199cc194218b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 Apr 2020 16:08:35 +0200 Subject: [PATCH 2/5] core: automatically add dependency on systemd-remount-fs.service if StateDirectory= is used And similar for other settings that require a writable /var/. Rationale: if these options are used for early-boot services (such as systemd-pstore.service) we need /var/ writable. And if /var/ is on the root fs, then systemd-remount-fs.service is the service that ensures that /var/ is writable. This allows us to remove explicit deps in services such as systemd-pstore.service. --- src/core/unit.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/core/unit.c b/src/core/unit.c index 96e1a6c320..17baea3117 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -1047,6 +1047,16 @@ int unit_add_exec_dependencies(Unit *u, ExecContext *c) { if (!MANAGER_IS_SYSTEM(u->manager)) return 0; + /* For the following three directory types we need write access, and /var/ is possibly on the root + * fs. Hence order after systemd-remount-fs.service, to ensure things are writable. */ + if (!strv_isempty(c->directories[EXEC_DIRECTORY_STATE].paths) || + !strv_isempty(c->directories[EXEC_DIRECTORY_CACHE].paths) || + !strv_isempty(c->directories[EXEC_DIRECTORY_LOGS].paths)) { + r = unit_add_dependency_by_name(u, UNIT_AFTER, SPECIAL_REMOUNT_FS_SERVICE, true, UNIT_DEPENDENCY_FILE); + if (r < 0) + return r; + } + if (c->private_tmp) { const char *p; From 0c978faa16fa9ecf92f0bbb5c7cc709dc472d115 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 Apr 2020 16:10:38 +0200 Subject: [PATCH 3/5] units: drop dependency on systemd-remount-fs.service from systemd-pstore.service This dependency is now generated automatically given we use StateDirectory=. Moreover the combination of Wants= and After= was too strong anway, as whether remount-fs is pulled in or not should not be up to systemd-pstore.service, and in fact is part of the initial transaction anyway. --- units/systemd-pstore.service.in | 2 -- 1 file changed, 2 deletions(-) diff --git a/units/systemd-pstore.service.in b/units/systemd-pstore.service.in index 37fcf878f0..f9705b57f6 100644 --- a/units/systemd-pstore.service.in +++ b/units/systemd-pstore.service.in @@ -13,8 +13,6 @@ Documentation=man:systemd-pstore(8) ConditionDirectoryNotEmpty=/sys/fs/pstore ConditionVirtualization=!container DefaultDependencies=no -Wants=systemd-remount-fs.service -After=systemd-remount-fs.service Before=sysinit.target [Service] From e0f968ad96e9a6340edced8e22089c802c2f6497 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 Apr 2020 16:24:23 +0200 Subject: [PATCH 4/5] units: drop systemd-remount-fs.service dependency from more services All services using StateDirectory= don't need the explicit dep anymore, let's hence drop it everywhere. --- units/systemd-backlight@.service.in | 1 - units/systemd-coredump@.service.in | 2 +- units/systemd-rfkill.service.in | 2 +- units/systemd-timesyncd.service.in | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/units/systemd-backlight@.service.in b/units/systemd-backlight@.service.in index d3022856f2..6f7967fd00 100644 --- a/units/systemd-backlight@.service.in +++ b/units/systemd-backlight@.service.in @@ -12,7 +12,6 @@ Description=Load/Save Screen Backlight Brightness of %i Documentation=man:systemd-backlight@.service(8) DefaultDependencies=no Conflicts=shutdown.target -After=systemd-remount-fs.service Before=sysinit.target shutdown.target [Service] diff --git a/units/systemd-coredump@.service.in b/units/systemd-coredump@.service.in index 951faa62a1..d1ece27074 100644 --- a/units/systemd-coredump@.service.in +++ b/units/systemd-coredump@.service.in @@ -12,7 +12,7 @@ Description=Process Core Dump Documentation=man:systemd-coredump(8) DefaultDependencies=no Conflicts=shutdown.target -After=systemd-remount-fs.service systemd-journald.socket +After=systemd-journald.socket Requires=systemd-journald.socket Before=shutdown.target diff --git a/units/systemd-rfkill.service.in b/units/systemd-rfkill.service.in index 3abb958310..af2042f1e5 100644 --- a/units/systemd-rfkill.service.in +++ b/units/systemd-rfkill.service.in @@ -13,7 +13,7 @@ Documentation=man:systemd-rfkill.service(8) DefaultDependencies=no BindsTo=sys-devices-virtual-misc-rfkill.device Conflicts=shutdown.target -After=sys-devices-virtual-misc-rfkill.device systemd-remount-fs.service +After=sys-devices-virtual-misc-rfkill.device Before=shutdown.target [Service] diff --git a/units/systemd-timesyncd.service.in b/units/systemd-timesyncd.service.in index f0486a70ab..92ee94582c 100644 --- a/units/systemd-timesyncd.service.in +++ b/units/systemd-timesyncd.service.in @@ -13,7 +13,7 @@ Documentation=man:systemd-timesyncd.service(8) ConditionCapability=CAP_SYS_TIME ConditionVirtualization=!container DefaultDependencies=no -After=systemd-remount-fs.service systemd-sysusers.service +After=systemd-sysusers.service Before=time-set.target sysinit.target shutdown.target Conflicts=shutdown.target Wants=time-set.target time-sync.target From b0c1a07654c80d3cbbbcc52f860d4206707c0b08 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 8 Apr 2020 16:25:03 +0200 Subject: [PATCH 5/5] units: make sure systemd-pstore stops at shutdown This doesn't matter too much given that the service doesn't do anything on shutdown, but let's still stop it to make things cleaner. --- units/systemd-pstore.service.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/units/systemd-pstore.service.in b/units/systemd-pstore.service.in index f9705b57f6..6e4827f03c 100644 --- a/units/systemd-pstore.service.in +++ b/units/systemd-pstore.service.in @@ -13,7 +13,8 @@ Documentation=man:systemd-pstore(8) ConditionDirectoryNotEmpty=/sys/fs/pstore ConditionVirtualization=!container DefaultDependencies=no -Before=sysinit.target +Conflicts=shutdown.target +Before=sysinit.target shutdown.target [Service] Type=oneshot