]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Refactor delayed power-off logic
authorMichal Sojka <michal.sojka@cvut.cz>
Mon, 25 Apr 2022 20:21:32 +0000 (22:21 +0200)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 25 Apr 2022 20:24:38 +0000 (22:24 +0200)
From time to time, I'm facing problems with delayed power off not
working. I'm not sure what is the exact reason, but a potential reason
could be that the board was powered on but the systemd service
novaboot-delayed-power-off.service, which is responsible for powering
off, was not started. To prevent that, we change the logic so that
powering on happens as a start job of the same service.

server/novaboot-shell
server/novaboot-shell.pod
server/systemd/novaboot-delayed-power-off.service

index 6c7225048ab7316531f0d01fd5a4ac34daa86c75..5e8621adf3b37689b4cdd375c188fa304f7e9134 100755 (executable)
@@ -98,8 +98,10 @@ power() {
     esac
 
     if [ "$PPID" -ne 1 ] && systemctl --user is-enabled --quiet novaboot-delayed-power-off.service; then
-       sudo novaboot-power "$1"
-        if [ "$1" = "on" ]; then systemctl --user start novaboot-delayed-power-off.service; fi
+        case "$1" in
+            "on") systemctl --user start novaboot-delayed-power-off.service;;
+            "off") sudo novaboot-power off;;
+        esac
     else
        eval "$cmd"
     fi
index 5684c6e39a03f187cbd502f8e3a0ff16339ce526..8442ef9dfd51566dc7dd34c5e712cb74c7f6779a 100644 (file)
@@ -225,6 +225,41 @@ following into the spawned editor:
     [Timer]
     OnActiveSec=30min
 
+=head2 Implementation/Debugging
+
+Implementation of delayed power off is a bit tricky because it uses
+C<sudo> in combination with several systemd services and timers. Here
+is a summary of the call chains in various situations. This might be
+useful for debugging.
+
+Powering on (via I<on> or I<console> subcommands):
+
+  novaboot-shell -c on
+    systemctl --user start novaboot-delayed-power-off.service
+      sudo novaboot-power on
+        systemctl stop  "novaboot-power-off@${SUDO_USER}.timer"
+        systemctl start "novaboot-power@${SUDO_USER}.service"
+          novaboot-shell -c on (with $PPID = 1)
+            eval "$on_cmd"
+
+Powering off via explicit I<off> subcommand:
+
+  novaboot-shell -c off
+    sudo novaboot-power off
+      systemctl stop "novaboot-power@${SUDO_USER}.service"
+        novaboot-shell -c off (with $PPID = 1)
+          eval $off_cmd
+
+Delayed off (executed automatically as a stop job of
+novaboot-delayed-power-off.service at session end):
+
+  sudo novaboot-power delayed-off
+    systemctl start "novaboot-power-off@${SUDO_USER}.timer"
+  ...
+  novaboot-power-off@${SUDO_USER}.service conflicts novaboot-power@${SUDO_USER}.service
+    novaboot-shell -c off (with $PPID = 1)
+      eval $off_cmd
+
 =head1 AUTHORS
 
 Michal Sojka <sojkam1@fel.cvut.cz>
index cf750c3cd65b48f000c8446f87e64895bbebd461..c469c12619c2a80e503f2a36ea2165e0284d6482 100644 (file)
@@ -5,6 +5,7 @@ ConditionFileNotEmpty=%h/.novaboot-shell
 
 [Service]
 Type=oneshot
+ExecStart=/usr/bin/sudo novaboot-power on
 ExecStop=/usr/bin/sudo novaboot-power delayed-off
 RemainAfterExit=true