How does Google Container Optimized OS handle a scheduled shutdown?

1.5k views Asked by At

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?

2

There are 2 answers

0
datu-puti On BEST ANSWER

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
2
Gabo Licea On

In regard to your question: how do I determine whether a shutdown has been scheduled?

There's no shutdown taks configured by default, you have to configure it (daily, weekly, monthly, etc.), the easier way to do this is by using "crond" (OS Linux task scheduler) please follow this guide to know how to configure jobs in cron(COS usually use Ubuntu OS).

According to this GCP guide: " Container-Optimized OS instances are configured to automatically download weekly updates in the background; only a reboot is necessary to use the latest updates."

So, I suggest you to configure your cron jobs weekly on no peak production days (Saturday or Sunday).

Please let me know if you have further questions.