osbuild/systemd-unit-create: fix DefaultDependencies option#668
osbuild/systemd-unit-create: fix DefaultDependencies option#668achilleas-k merged 10 commits intoosbuild:mainfrom
Conversation
|
This needs more work. The systemd service needs fixing both in the things it runs and its ordering. |
|
The systemd unit in its current form doesn't do what we want. We need to be very specific about unit ordering for the There's a simple (ish) way to experiment with the problem this service is trying to solve.
{
"name": "ostree-filesystem-customizations-42000",
"blueprint": {
"customizations": {
"user": [
{
"name": "root",
"key": "<SSHKEY>",
"password": "<PASSWORD>"
}
],
"filesystem": [
{
"mountpoint": "/data",
"minsize": 2147483648
},
{
"mountpoint": "/data/secondary",
"minsize": 2147483648
},
{
"mountpoint": "/stuff",
"minsize": 2147483648
},
{
"mountpoint": "/var/mydata",
"minsize": 1073741824
}
]
}
},
"options": {
"ostree": {
"ref": "rhel/9/x86_64/edge",
"url": "http://127.0.0.1:42000/repo"
}
}
}
With the service disabled, the mount should fail on boot. If the service looks like this though, everything should work (you can just plop it down in |
c0692e7 to
f40111c
Compare
8046905 to
3d3399f
Compare
mvo5
left a comment
There was a problem hiding this comment.
Thank you! This is very nice! Some quick drive-by feedback, I wanted to go full-review but only managed the first few lines and then got distracted. Feel free to ignore, it's mostly rambling.
The default value of DefaultDependencies in systemd is 'true' so we need to make it a pointer with 'omitempty' to be able to represent the 'unset' state. Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
Update the options of the org.osbuild.systemd.unit.create stage with the new Before option.
Adding more paths that are denied for mountpoint creation for ostree-based images. In a booted ostree system, these paths are symlinks, so it makes no sense (and will cause problems) to create mountpoints at those locations. The list has been sorted to make it simpler to modify consistently going forward.
- The [ -z ... ] is redundant. We can condition on the exit code of grep itself and don't need a subshell. - Double quoting was wrong.
With RemainAfterExit enabled, the service is not considered "stopped" when the execution ends, so the ExecStopPost is never executed. Disabling RemainAfterExit ensures that ExecStopPost is run always, even when the execution of the unit fails.
The mountpoint creation should happen after the ostree-remount.service is run so that the ostree mounts are all set up and directories are created in the correct location for the *live* system.
A new helper function that shells out to systemd-escape to determine the mount unit name for a mountpoint. See systemd-escape(1) for details.
- Add comment explaining why we disable DefaultDependencies. - Drop the unnecessary [:] from the mountpoints slice.
3d3399f to
49d8e81
Compare
The original purpose of this PR was to make the DefaultDependencies option an optional property that defaults to 'true'. The original PR also had a small fix for the mountpoint creation service. While working on updating the previous PR, I found that the mountpoint creation service for ostree-based images needed more work, including additions to the osbuild stage that creates it.
Replaces #608.
Changes to the systemd unit:
chattr +i /command inExecStartPostisn't run becauseRemainAfterExitis enabled, so the service doesn't "stop".RemainAfterExitshould be disabled.Instead of checking forcomposefsby grepping a binary, perhaps it's more reliable to check for the symptom, the thing we want to toggle, withlsattr -ld / | grep -q Immutable.The last item was abandoned because we don't have a clean way of toggling the immutable flag back on without communicating info from the Pre command to the Post command.
This PR also updates the mountpoint policy for ostree-based systems to disallow paths that are top-level symlinks on a booted system.
Requires osbuild/osbuild#1782