diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-11 10:13:19 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-11 10:13:19 +0100 |
| commit | 8ba4e93dbfc4f0499f8a34beadeffb638d3e7e48 (patch) | |
| tree | 85bed0dd8c196d62313dd61720c6234f843e4309 /deckit/sleep.py | |
| parent | ed5ff682efbefd3e90d21ea618473af2844b774d (diff) | |
| download | deck-it-8ba4e93dbfc4f0499f8a34beadeffb638d3e7e48.tar.gz deck-it-8ba4e93dbfc4f0499f8a34beadeffb638d3e7e48.zip | |
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 <noreply@anthropic.com>
Diffstat (limited to 'deckit/sleep.py')
| -rw-r--r-- | deckit/sleep.py | 16 |
1 files changed, 16 insertions, 0 deletions
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 <why>" +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 = "" |
