Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add systemd ScheduledShutdown (and reboot) wakeup check #253

Open
Flowdalic opened this issue Sep 27, 2022 · 8 comments
Open

Add systemd ScheduledShutdown (and reboot) wakeup check #253

Flowdalic opened this issue Sep 27, 2022 · 8 comments

Comments

@Flowdalic
Copy link

Please consider adding a new wakeup check for systemd scheduled reboots. In case there is a scheduled shutdown or reboot pending, the wakeup check should schedule a wakeup briefly, say 3-5 minutes, before the scheduled shutdown or reboot. One can retrieve information about scheduled shutdowns or reboots via e.g.,

$ busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown
@languitar
Copy link
Owner

Interesting, I didn't even know such a feature exists. What is your use case for this?

@Flowdalic
Copy link
Author

We schedule automatic reboots based reboot-required.pkgs and needrestart information. If the systems suspend while a scheduled reboot is pending, and awakes after the time of the scheduled reboot, the scheduled reboot fails. Waking the system up, briefly before the scheduled reboot, causes the system to reboot.

@languitar
Copy link
Owner

I just wanted to look at this issue again. What command do you actually use to schedule a reboot?

@languitar
Copy link
Owner

Btw, looking at this StackExchnage question, it seems that for the moment you should be able to create a simple script for the Comannd wakeup check to workaround the lack of the feature right now.

@Flowdalic
Copy link
Author

What command do you actually use to schedule a reboot?
For example

$ shutdown --reboot +02:00 "Scheduled reboot for maintenance"

@Flowdalic
Copy link
Author

Flowdalic commented Nov 2, 2022

Btw, looking at this StackExchnage question, it seems that for the moment you should be able to create a simple script for the Comannd wakeup check to workaround the lack of the feature right now.

Yes we have something like that in place

#!/usr/bin/env bash
set -eou pipefail

# Although this file is called wakeup-before-scheduled-reboot we
# actually check for the next scheduled reboot *or* shutdown. But this
# does not really matter, as we want to wakeup in both cases and we
# only schedule reboots.
SCHEDULED_SHUTDOWN_INFO=$(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown)

declare -i SCHEDULED_SHUTDOWN_SECS
SCHEDULED_SHUTDOWN_SECS=$(echo "${SCHEDULED_SHUTDOWN_INFO}" | cut -d ' ' -f 3)

if [[ ${SCHEDULED_SHUTDOWN_SECS} -eq 0 ]]; then
    # Output the empty string to make autosuspend happy.
    echo ""
    exit
fi

BEFORE_SCHEDULED_SHUTDOWN_SECS=$(( SCHEDULED_SHUTDOWN_SECS - 180 ))

echo "${BEFORE_SCHEDULED_SHUTDOWN_SECS}"

which is added as script to autosuspend's configuration

[wakeup.BeforeScheduledReboot]
enabled = true
class = Command
command = /etc/autosuspend/wakeup-before-scheduled-reboot

@languitar
Copy link
Owner

Fun thing about the shutdown command: that is provided by the systemd compatibility layer for sysv. However, I couldn't find any way to achieve the same behavior without this compatibility command.

@Flowdalic
Copy link
Author

Fun thing about the shutdown command: that is provided by the systemd compatibility layer for sysv. However, I couldn't find any way to achieve the same behavior without this compatibility command.

Probably because the functionality already exists in that said program. I assume it is meant as drop-in replacement, not as something that will ever disappear. That said, I wouldn't be surprised if this where possible using some dbus API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants