-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Description
Submission type
- Bug report
systemd version the issue has been seen with
systemd-233-6.fc26.x86_64
Used distribution
Fedora 26
In case of bug report: Expected behaviour you didn't see
sleep.target can be used correctly by mortal humans. (It's purpose is "to hook units into
the sleep state logic"). E.g. after reading documentation for systemd, they should not have false confidence about how easy it is to get right...
In case of bug report: Unexpected behaviour you saw
The system is left hung. My screen was featureless black except for the flashing text cursor. It does not respond to tapping the power button or pressing ctrl+alt+del again.
When I gave up and forcibly powered off my hardware, systemd had gone for 30 seconds without logging any progress to the system journal. (I have it configured with SyncIntervalSec=1s). At that point, the last log message from systemd was around 30 seconds ago. (Looking at the journal after the forced power off).
Here is a cool log as evidence. Not sure why the difference in behaviour to the above.
Jul 27 22:11:10 alan-laptop sudo[1964]: alan-sysop : TTY=pts/0 ; PWD=/home/alan-sysop ; USER=root ; COMMAND=/bin/sh -c systemctl --no-block start ctrl-alt-del.target; logger "systemctl suspend"; systemctl suspend
...
Jul 27 22:11:10 alan-laptop systemd[1]: Starting Show Plymouth Reboot Screen...
...
Jul 27 22:11:10 alan-laptop alan-sysop[1995]: systemctl suspend
...
Jul 27 22:11:11 alan-laptop kernel: PM: Syncing filesystems ...
...
Jul 27 22:11:23 alan-laptop systemd[1]: Stopped target Basic System.
Jul 27 22:11:23 alan-laptop systemd[1]: Starting Tell Plymouth To Write Out Runtime Data...
Jul 27 22:11:23 alan-laptop systemd[1]: Stopped target Sockets.
...
Jul 27 22:11:23 alan-laptop systemd[1]: Stopped target Slices.
Jul 27 22:11:23 alan-laptop systemd[1]: Removed slice User and Session Slice.
...
Jul 27 22:11:23 alan-laptop systemd[1]: Started Tell Plymouth To Write Out Runtime Data.
Jul 27 22:11:23 alan-laptop systemd[1]: Starting Disable power saving on rotating hard drives...
Jul 27 22:11:24 alan-laptop systemd[1]: Started Disable power saving on rotating hard drives.
Jul 27 22:11:25 alan-laptop systemd[1]: Received SIGRTMIN+20 from PID 1980 (plymouthd).
... press ctrl+alt+del after 40 minutes at the blank screen ...
Jul 27 22:51:31 alan-laptop systemd[1]: Received SIGINT.
...
Jul 27 22:51:31 alan-laptop systemd[1]: home.mount: Mount process exited, code=exited status=32
Jul 27 22:51:31 alan-laptop systemd[1]: Failed unmounting /home.
...
Jul 27 22:51:31 alan-laptop systemd[1]: Failed unmounting Temporary Directory.
...
Jul 27 22:51:31 alan-laptop systemd[1]: Reached target Shutdown.
Jul 27 22:51:31 alan-laptop systemd[1]: Starting Reboot...
Jul 27 22:51:31 alan-laptop systemd[1]: Shutting down.
...
Jul 27 22:51:32 alan-laptop systemd-shutdown[1]: Sending SIGTERM to remaining processes...
Jul 27 22:51:32 alan-laptop systemd-journald[557]: Journal stopped
In case of bug report: Steps to reproduce the problem
ok, so my example was actually a resume hook. I haven't tested sleep hooks, but I have no reason to believe it's any different.
# /etc/systemd/system/hdparm-noapm.service
[Unit]
Description=Disable power saving on rotating hard drives
# Assumption: the relevant devices are available at boot time
# (after local-fs.target, which is an automatic dependency).
After=suspend.target hibernate.target hybrid-sleep.target
[Service]
Type=oneshot
# this should be irrelevant to the issue, feel free to replace with /bin/true
ExecStart=/usr/sbin/hdparm -B 254 /dev/sda
[Install]
WantedBy=suspend.target hibernate.target hybrid-sleep.target
systemctl enable hdparm-noapm
and then to trigger the hang:
- log in
- tmux
- press
ctrl+band thend, to detach - close the shell which launched tmux
tmux attach# connect to a detached tmux - this seems to survive longer during shutdownsudo sh -c 'systemctl start --no-block ctrl-alt-del.target; systemctl suspend'- when the system goes to sleep, wake it back up using the power button
I predicted this defect as an attempt to answer What is the practical difference between systemctl start ctrl-alt-del.target and systemctl reboot?. My hypothesis was that without DefaultDependencies=no, the above hook unit gets Conflicts=shutdown.target. The suspend process would therefore stop the queued shutdown.target, which is a Requires dependency of systemd-reboot.service. As a result, systemd-reboot.service would not be started, but all services and mounts would be still stopped. Note I can't tell from the logs whether that's exactly right, it's only what I predicted.
Adding DefaultDependencies=no to the above unit is sufficient to avoid the issue. The shutdown "wins", and it occurs without any system suspend. Note that the systemd sleep units all have DefaultDependencies=no, but systemd fails to explain why this is important. As a result, many and prominent examples of sleep hook units are written incorrectly.
As my question suggests, using systemctl reboot instead of systemctl start reboot.target or it's aliases (symlinks) was also sufficient to avoid the issue. So I recommend never using systemctl start reboot.target, and fixing ctrl-alt-del.target to run systemctl reboot.