On Thu, 17 Jun 2021, Tomas Pospisek wrote:

With respect to "unattended-upgrades blocking other cron.daily scripts via shutdown -r" I reflected:

Now what would a "correct" or "better" behavior be?

I suggest to trigger an asynchronous shutdown, that is *not*
to wait for `shutdown -r $TIME` to come back so that whatever
daily menial taks are scheduled via /etc/cron.daily are able
to be executed.

What about the idea of using

   echo "shutdown -r now" | at $TIME

instead of directly calling

   shutdown -r now

Pro:

* async execution. unattended-update can finish it's stuff and
 the rest of cron.daily finishes correctly
* consoles won't be flooded with repeat "Systeme will be going
 doing in XX hours"

Con:

* does care have to be taken that unattended-upgrade won't re-run
 while it wants the system to reboot?
* behavior change (this should be triggering a major semver change...)
 * this could be worked around with yet another config option
   (UseAtInstead=True)
* users on the system won't be warned of the system going down in
 XX hours

What do you think?

The idea in code:

--- /usr/bin/unattended-upgrade.orig 2021-06-18 09:46:37.434386824 +0200
+++ /usr/bin/unattended-upgrade 2021-06-18 09:47:03.958639111 +0200
@@ -1353,11 +1353,12 @@
     when = apt_pkg.config.find(
         "Unattended-Upgrade::Automatic-Reboot-Time", "now")
     logging.warning("Found %s, rebooting" % REBOOT_REQUIRED_FILE)
-    cmd = ["/sbin/shutdown", "-r", when]
+    cmd = ["/usr/bin/at", when]
     try:
-        shutdown_msg = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
-        if shutdown_msg.strip():
-            logging.warning("Shutdown msg: %s", shutdown_msg.strip())
+        p = subprocess.Popen(cmd, stdin=subprocess.PIPE, 
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+        p_out = p.communicate(input=b'shutdown -h 
now\n')[0].decode('utf-8').strip()
+        if p_out:
+            logging.warning("Shutdown msg: %s", p_out)
     except Exception as e:
         logging.error("Failed to issue shutdown: %s", e)

Feedback about whether this is a good idea is appreciated.

Thanks & greetings,
*t

Reply via email to