0

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?

datu-puti
  • 1,306
  • 14
  • 33

2 Answers2

1

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.

Gabo Licea
  • 198
  • 3
  • 1
    In my earlier dealings with this OS I learned there's no system crond available. I have a container for one of my cron tasks, but I didn't want to run a container just for the purpose of rebooting the host - it's overkill and a security risk. I'm more interested in the different ways that a shutdown is scheduled: there's 3 that I know of now and mentioned in my Q and A - a blocking task (`ps`), systemd, and busctl. – datu-puti Jul 17 '20 at 16:07
  • 2
    You're right, crond is not included in COS images, however; you can use "Cloud Scheduler" and "Cloud Functions" to shedule shutdowns and start ups on instances. In case you rather to use Cloud scheduler I found another stackoverflow questions where explains how to do it, please refer this [link] (https://stackoverflow.com/questions/58830867/gcp-auto-shutdown-and-startup-using-google-cloud-schedulers) Here's another [guide] (https://medium.com/google-cloud/using-cloud-scheduler-and-cloud-functions-to-deploy-a-periodic-compute-engine-vm-worker-2b897ef68dc5) you may find it useful. – Gabo Licea Jul 17 '20 at 18:49
0

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
datu-puti
  • 1,306
  • 14
  • 33