Search code examples
google-container-osgoogle-container-optimized-os

How does Google Container Optimized OS handle a scheduled shutdown?


I'm playing around with Container Optimized OS on Google Cloud and found that the 'Auto Update' feature doesn't apply the updates until the system is restarted, and doesn't offer any functionality for scheduling a reboot after an update is applied.

I'm writing a simple startup script that schedules a shutdown when a reboot is needed, essentially:

#!/usr/bin/env sh

update_engine_client --block_until_reboot_is_needed
shutdown -r 02:00

My question is: how do I determine whether a shutdown has been scheduled? I have tried three methods so far that don't work in this OS:

  1. $ ps -ef | grep shutdown - no shutdown process
  2. $ systemctl status systemd-shutdownd.service - Unit systemd-shutdownd.service could not be found.
  3. cat /run/systemd/shutdown/scheduled - no file found

Documentation on this OS, and what it's based on, are slim. What determines how shutdown is scheduled, and how does COS handle it?


Solution

  • In Container-Optimized OS, the following command will display pending shutdown information in epoch time:

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

    I am curious why Google chose to use busctl instead of systemd - I was unfamiliar with busctl and had to do some reading on it to understand what the command is doing - busctl man page

    Example:

    $ sudo shutdown -r 02:00
    Shutdown scheduled for Fri 2020-07-17 02:00:00 UTC, use 'shutdown -c' to cancel.
    $ busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown
    (st) "reboot" 1594951200000000
    $ sudo shutdown -c
    busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown
    (st) "" 0