13

I like to use shutdown -h TIME/+DELAY sometimes. However, since the switch to systemd (on Ubuntu), things seem to have changed quite a bit.

Apart from the fact that a previous shutdown command no longer prevents running a new one, I can't figure out how to check for the planned shutdown time of a current shutdown process.

I used to just run ps aux | grep shutdown to see the planned shutdown time.

Now with systemd it just shows something like this:

root      5863  0.0  0.0  13300  1988 ?        Ss   09:04   0:00 /lib/systemd/systemd-shutdownd

How can I check the scheduled shutdown time of such a process?

I tried shutdown -k, but instead of only writing a wall message, it seems to also change the scheduled shutdown time to now+1 minute.

12

man shutdown(8) says:

The first argument may be a time string (which is usually "now").

The time string may either be in the format "hh:mm" for hour/minutes specifying the time to execute the shutdown at, specified in 24h clock format. Alternatively it may be in the syntax "+m" referring to the specified number of minutes m from now. "now" is an alias for "+0", i.e. for triggering an immediate shutdown. If no time argument is specified, "+1" is implied.

Try:

# shutdown +5
# systemctl status systemd-shutdownd.service

You should see something like this:

● systemd-shutdownd.service - Delayed Shutdown Service
Loaded: loaded (/lib/systemd/system/systemd-shutdownd.service; static; vendor preset: enabled)
Active: active (running) since Tue 2015-09-15 09:13:11 UTC; 12s ago
Docs: man:systemd-shutdownd.service(8)
Main PID: 965 (systemd-shutdow)
Status: "Shutting down at Tue 2015-09-15 09:18:11 UTC (poweroff)..."
CGroup: /system.slice/systemd-shutdownd.service
       └─965 /lib/systemd/systemd-shutdownd

Status is Shutting down at Tue 2015-09-15 09:18:11 UTC (poweroff)...

  • Thanks. That was easy. I tried "service status" without success before. I guess I'm not used to systemd enough yet. – KIAaze Sep 15 '15 at 9:46
  • 1
    systemd-shutdownd was removed from systemd in May 2015. – JdeBP Aug 28 '18 at 15:16
  • That's correct. Thank you for pointing it out. If a newer version of systemd is used, then something like the following should suffice: USECS=$(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown | cut -d ' ' -f 3); SECS=$((USECS / 1000000)); date --date=@$SECS. – Evgeny Vereshchagin Aug 29 '18 at 9:02
8
# cat /run/systemd/shutdown/scheduled
USEC=1537242600000000
WARN_WALL=1
MODE=poweroff

The USEC is a unix epoch timestamp with microsecond precision, so:

if [ -f /run/systemd/shutdown/scheduled ]; then
  perl -wne 'm/^USEC=(\d+)\d{6}$/ and printf("Shutting down at: %s\n", scalar localtime $1)' < /run/systemd/shutdown/scheduled
fi

will display something like:

Shutting down at: Tue Sep 18 03:50:00 2018

Systemd version is 232-25+deb9u4 running on Debian Stretch .

4

For newer linux distributions versions you might need to do:

busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown

The method of how shutdown works has changed

Tried on: - Debian Stretch 9.6 - Ubuntu 18.04.1 LTS

References

  • 2
    The output specifies the shutdown time as microseconds since the Unix epoch. To get a human-readable time: date -d @$(( $(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown | cut -d' ' -f3) / 1000000 )) – 200_success Jan 31 at 20:30
4

I encountered the same question and found another way to check the shutdown plan.

When you set a shutdown plan, wall will send a message to everybody logged in with their mesg permission set to yes. For every invocation of wall a notification will be written to syslog. To search the syslog, you could run the command journalctl -u systemd-shutdownd, the -u option could filter the log by unit.

When you run journalctl -u systemd-shutdownd, it will show the shutdown details like below:

[root@dev log]# journalctl -u systemd-shutdownd
-- Logs begin at Mon 2017-06-12 09:39:34 CST, end at Mon 2017-06-12 14:05:04 CST. --
Jun 12 09:39:50 dev.local systemd[1]: Started Delayed Shutdown Service.
Jun 12 09:39:50 dev.local systemd[1]: Starting Delayed Shutdown Service...
Jun 12 09:39:50 dev.local systemd-shutdownd[1249]: Shutting down at Mon 2017-06-12 21:00:00 CST (poweroff)...
Jun 12 09:55:59 dev.local systemd-shutdownd[1249]: Shutdown canceled.
Jun 12 09:56:07 dev.local systemd[1]: Started Delayed Shutdown Service.
Jun 12 09:56:07 dev.local systemd[1]: Starting Delayed Shutdown Service...
Jun 12 09:56:07 dev.local systemd-shutdownd[2885]: Shutdown canceled.
Jun 12 11:54:15 dev.local systemd[1]: Started Delayed Shutdown Service.
Jun 12 11:54:15 dev.local systemd[1]: Starting Delayed Shutdown Service...
Jun 12 11:54:15 dev.local systemd-shutdownd[3178]: Shutting down at Mon 2017-06-12 20:00:00 CST (poweroff)...
0

On an Ubuntu 18.04 machine shutdown is managed by systemd. On my machine I have enabled automatic reboots via unattended upgrades:

$ grep Automatic-Reboot /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

The scheduled automatic reboot time is stored in /run/systemd/shutdown/scheduled.

$ cat /run/systemd/shutdown/scheduled
USEC=1563976800000000 
WARN_WALL=1
MODE=reboot

You can convert this to a human readable time using the following command:

$ date -d "@$( awk -F '=' '/USEC/{ $2=substr($2,1,10); print $2 }' /run/systemd/shutdown/scheduled )"
Thu Jul 25 02:00:00 NZST 2019

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.