You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LSB service stopped after, not before partition unmounting #9765
LSB service with 'Required-Stop: $local_fs $remote_fs $named $network $syslog $time' stops before partition mounted with fstab tried to get unmounted.
Unexpected behaviour you saw
LSB service stops after unmounting attempt, which results in failure, as the service still uses this partition.
Steps to reproduce the problem
Create separate partition on some /dev/sd* device, mount it in fstab, create an LSB service that depends on $local_fs and $remote_fs and uses this partition (say, stores database there), and then try to shutdown PC.
Thats why I expect that everything will be mounted before my service is started (which is true) and that my service will be stopped at shutdown before unmounting (which is false):
It turned out that the workaround I provided in previous comment fixed this issue, but creates another one: it prevents the sniffer service to start if hdd was formatted at the beginning of boot by other service. If there is no "RequiresMountsFor" option, then the service is started normally after /var/sniffer is mounted.
Normal situation:
[ OK ] Listening on journal audit socket
Starting format and label storage HDD at boot... <- my custom service to format /dev/sda if needed
Mounting Kernel Debug File System...
Starting udev Coldplug all Devices...
[ OK ] Listening on /dev/initctl Compatibility Named Pipe.
...
[ OK ] Reached Local File Systems (Pre).
...
[ OK ] Mounted /var/sniffer.
...
[ OK ] Started LSB: Start sniffer daemon.
Problem situation with workaround is the same except there are no Starting/Started LSB: Start sniffer daemon entries. Sniffer daemon is not started at all, even though /var/sniffer is successfully mounted at boot (it is just mounted a little bit later than usually, but still at boot and still before sniffer daemon is started if there is no workaround).
I fixed it by using "After=var-sniffer.mount" dependency instead of "RequiresMountsFor". It seems that Requires condition is just checked too early. But there is one more caveat: if there is no storage HDD and => no "/var/sniffer" mount, it takes quite long for a service to get started (usually 90s) and it is not clear where this timeout could be changed.
You specified "nofail" for that partition in /etc/fstab. That means that systemd won't wait for the mount to show up at boot, nor for it to go away on shutdown. It also means systemd won't care if mounting it fails.
The ordering logic is a bit underdocumented, I added this now in #9784.
Basically, if you want the mount to show up realiably either drop "nofail" from the fstab entry, or use After=var-sniffer.mount in your unit file.
Anyway, this is kinda intended behaviour (and with #9784 finally documented), hence closing this. I hope this makes sense.
But why systemd can't detect on shutdown that it is actually mounted and act accordingly?
And, for RequiresMountsFor it is also very strange to see a situation where service is not started even though partition was mounted (but probably it is yet another bug) and, moreover, when this option is not used, service still starts after partition get mounted (so ordering is not affected, but just "Requires" condition is wrongly checked).
But why systemd can't detect on shutdown that it is actually mounted and act accordingly?
So, systemd doesn't have a concept for "order only at shutdown but not at startup". The assumption so far is that either some file system is needed for a service or it isn't. Hence there's only one type of ordering, and After= hence means two things: "start B after A when both are starting, but stop A after B when both are stopping".
It has been requested before that systemd should allow separate ordering for startup and shutdown, i.e. allow that when two units are started they can be ordered in some way, but that when they are stopped they aren't ordered in the opposite order. But so far when this came up each time a better solution was found.
I am not sure I grok your usecase. It appears your service needs that mount to be around, no? If so RequiresMountsFor= sounds appropriate, no?
I just want the service to start and work even if separate storage HDD is not installed, but if it is, then wait for it to be mounted and then stop service before it gets unmounted.
I want HDD to be labeled and formatted at boot if it had not been labeled yet. I do it in a separate service that is started before local-fs-pre (actually it has DefaultDependencies=no, Before=systemd-fsck-root.service, Conflicts=shutdown.target). For some reason it affects mount time of /var/sniffer (when it is mounted after formatting) even though the service is started before local-fs-pre, so this mount is shifted towards end of boot sequence, but still happens before start of LSB services. And here I see this strange "RequiresMountsFor" behavior, when /var/sniffer is mounted before the time LSB services are started, but sniffer service is not started by systemd as if there is no /var/sniffer mount (see LSB service stopped after, not before partition unmounting #9765 (comment)).
note that devices can take any time they want to show up at boot with today's hardware. hence a logic of "is the hardware installed then mount it" can never work reliably, since during early boot the device won't have been enumerated, and you never know when it will or whether it will at all...
I am not sure how you format your disk, but have you checked that after formatting is complete the device shows up properly? i.e. "udevadm info" on the device should show the "systemd" tag to be set for it, and SYSTEMD_READY=0 should not be set.
It has been requested before that systemd should allow separate ordering for startup and shutdown, i.e. allow that when two units are started they can be ordered in some way, but that when they are stopped they aren't ordered in the opposite order. But so far when this came up each time a better solution was found.
That's not entirely true, #6102 is still opened...
Activity
mbiebl commentedon Jul 31, 2018
You probably want Required-Start: instead of -Stop
sknaumov commentedon Aug 1, 2018
I already have it:
Thats why I expect that everything will be mounted before my service is started (which is true) and that my service will be stopped at shutdown before unmounting (which is false):
poettering commentedon Aug 1, 2018
What does your fstab entry look like? What does
systemctl show var-sniffer.mountshow?sknaumov commentedon Aug 1, 2018
fstab.txt
var-sniffer.mount.txt
BTW, I've managed to make a workaround (the var-sniffer.mount.txt above is without the workaround applied):
sknaumov commentedon Aug 2, 2018
It turned out that the workaround I provided in previous comment fixed this issue, but creates another one: it prevents the sniffer service to start if hdd was formatted at the beginning of boot by other service. If there is no "RequiresMountsFor" option, then the service is started normally after /var/sniffer is mounted.
Normal situation:
Problem situation with workaround is the same except there are no
Starting/Started LSB: Start sniffer daemonentries. Sniffer daemon is not started at all, even though /var/sniffer is successfully mounted at boot (it is just mounted a little bit later than usually, but still at boot and still before sniffer daemon is started if there is no workaround).I fixed it by using "After=var-sniffer.mount" dependency instead of "RequiresMountsFor". It seems that Requires condition is just checked too early. But there is one more caveat: if there is no storage HDD and => no "/var/sniffer" mount, it takes quite long for a service to get started (usually 90s) and it is not clear where this timeout could be changed.
man: document that 'nofail' also has an effect on ordering
poettering commentedon Aug 2, 2018
You specified "nofail" for that partition in /etc/fstab. That means that systemd won't wait for the mount to show up at boot, nor for it to go away on shutdown. It also means systemd won't care if mounting it fails.
The ordering logic is a bit underdocumented, I added this now in #9784.
Basically, if you want the mount to show up realiably either drop "nofail" from the fstab entry, or use After=var-sniffer.mount in your unit file.
Anyway, this is kinda intended behaviour (and with #9784 finally documented), hence closing this. I hope this makes sense.
man: document that 'nofail' also has an effect on ordering
sknaumov commentedon Aug 3, 2018
But why systemd can't detect on shutdown that it is actually mounted and act accordingly?
And, for RequiresMountsFor it is also very strange to see a situation where service is not started even though partition was mounted (but probably it is yet another bug) and, moreover, when this option is not used, service still starts after partition get mounted (so ordering is not affected, but just "Requires" condition is wrongly checked).
poettering commentedon Aug 3, 2018
So, systemd doesn't have a concept for "order only at shutdown but not at startup". The assumption so far is that either some file system is needed for a service or it isn't. Hence there's only one type of ordering, and After= hence means two things: "start B after A when both are starting, but stop A after B when both are stopping".
It has been requested before that systemd should allow separate ordering for startup and shutdown, i.e. allow that when two units are started they can be ordered in some way, but that when they are stopped they aren't ordered in the opposite order. But so far when this came up each time a better solution was found.
I am not sure I grok your usecase. It appears your service needs that mount to be around, no? If so RequiresMountsFor= sounds appropriate, no?
sknaumov commentedon Aug 3, 2018
I just want the service to start and work even if separate storage HDD is not installed, but if it is, then wait for it to be mounted and then stop service before it gets unmounted.
I want HDD to be labeled and formatted at boot if it had not been labeled yet. I do it in a separate service that is started before local-fs-pre (actually it has DefaultDependencies=no, Before=systemd-fsck-root.service, Conflicts=shutdown.target). For some reason it affects mount time of /var/sniffer (when it is mounted after formatting) even though the service is started before local-fs-pre, so this mount is shifted towards end of boot sequence, but still happens before start of LSB services. And here I see this strange "RequiresMountsFor" behavior, when /var/sniffer is mounted before the time LSB services are started, but sniffer service is not started by systemd as if there is no /var/sniffer mount (see LSB service stopped after, not before partition unmounting #9765 (comment)).
poettering commentedon Aug 3, 2018
note that devices can take any time they want to show up at boot with today's hardware. hence a logic of "is the hardware installed then mount it" can never work reliably, since during early boot the device won't have been enumerated, and you never know when it will or whether it will at all...
I am not sure how you format your disk, but have you checked that after formatting is complete the device shows up properly? i.e. "udevadm info" on the device should show the "systemd" tag to be set for it, and SYSTEMD_READY=0 should not be set.
fbuihuu commentedon Aug 28, 2018
That's not entirely true, #6102 is still opened...
man: document that 'nofail' also has an effect on ordering
man: document that 'nofail' also has an effect on ordering
man: document that 'nofail' also has an effect on ordering