From 8ba4e93dbfc4f0499f8a34beadeffb638d3e7e48 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 11 Nov 2026 10:13:19 +0100 Subject: feat(sleep): run deck-it stop on a confirmed shutdown After the tablet has been told, a PrepareForShutdown runs `deck-it stop` in its own session (it kills the server) so the tunnels, wayvnc and the headless output go cleanly before the inhibitor lets the shutdown on. Login brings everything back on the next boot. Co-Authored-By: Claude Opus 5.5 --- deckit/sleep.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'deckit/sleep.py') diff --git a/deckit/sleep.py b/deckit/sleep.py index 06cb481..c607cda 100644 --- a/deckit/sleep.py +++ b/deckit/sleep.py @@ -22,6 +22,8 @@ someone holds a delay inhibitor (at most InhibitDelayMaxSec, 5 s by default). deck-it holds one; on the announcement the server marks every answer for SHOW seconds, so the tablet's next poll sees it, then lets the inhibitor go. On resume, or a shutdown called off, it takes it again. +A shutdown also runs `deck-it stop` first, so the tunnels, wayvnc and the +headless output go cleanly; the next boot's login brings it all back. """ import ctypes @@ -29,10 +31,12 @@ import os import signal import subprocess import time +from pathlib import Path SHOW = 2.0 # the tablet polls every second (0.5 s on the assistant tab) WHY = {"PrepareForSleep": "asleep", "PrepareForShutdown": "shutting down"} why = "" # the server sends it to the tablet while set: "The PC is " +STOP = [str(Path(__file__).resolve().parent.parent / "deck-it"), "stop"] def _die_with_parent(): @@ -60,6 +64,16 @@ def _release(p): p.wait() +def _stop(): + # Its own session: the stop kills this server, and must outlive it. The + # wait is bounded, the inhibitor only holds the shutdown for 5 s. + try: + subprocess.Popen(STOP, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, + start_new_session=True).wait(timeout=2.5) + except (OSError, subprocess.TimeoutExpired): + pass + + def watch(): """Runs for the server's life; without elogind or dbus-monitor it does nothing.""" global why @@ -80,6 +94,8 @@ def watch(): elif line == "boolean true" and member: why = WHY[member] time.sleep(SHOW) + if member == "PrepareForShutdown": + _stop() _release(lock) elif line == "boolean false" and member: why = "" -- cgit v1.2.3