]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Fix delayed power off
authorMichal Sojka <michal.sojka@cvut.cz>
Thu, 18 Nov 2021 17:58:42 +0000 (18:58 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 18 Nov 2021 18:11:08 +0000 (19:11 +0100)
Th novaboot-delayed-power-off.service was meant to activate
system-level systemd timer at uses session shutdown. However, this
never worked, because an user service cannot be activated as a part of
session shutdown, because each service depends on app.slice and this
slice is being stopped in the shutdown sequence, which results in
removing the service start request from the shutdown transaction. This
behavior is demonstrated by the systemd debug log below:

    Pulling in novaboot-delayed-power-off.service/start from shutdown.target/start
    Added job novaboot-delayed-power-off.service/start to transaction.
    Pulling in app.slice/start from novaboot-delayed-power-off.service/start
    Pulling in novaboot-delayed-power-off.service/stop from app.slice/stop
    Added job novaboot-delayed-power-off.service/stop to transaction.
    Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
    novaboot-delayed-power-off.service: Deleting job novaboot-delayed-power-off.service/start as dependency of job app.slice/start
    Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
    Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
    Keeping job novaboot-delayed-power-off.service/stop because of app.slice/stop
    Found redundant job novaboot-delayed-power-off.service/stop, dropping from transaction.

Therefore, we don't use a service with ExecStart, but use ExecStop to
start the shutdown timer and start the service by novaboot-shell
whenever the board is powered on.

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

index 846ea1b659e8c8ad2e16019fcc0c939544271158..6c7225048ab7316531f0d01fd5a4ac34daa86c75 100755 (executable)
@@ -99,6 +99,7 @@ power() {
 
     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
     else
        eval "$cmd"
     fi
index 97d3efd4b69932a42335f65481169e6ab4e9b4e5..fe79613490da33e56a874c2c9353964f00d8eef5 100644 (file)
@@ -2,12 +2,8 @@
 Description=Delayed power-off of the novaboot target
 ConditionGroup=novaboot
 ConditionFileNotEmpty=%h/.novaboot-shell
-Before=shutdown.target
-DefaultDependencies=no
 
 [Service]
 Type=oneshot
-ExecStart=/usr/bin/sudo novaboot-power delayed-off
-
-[Install]
-WantedBy=shutdown.target
+ExecStop=/usr/bin/sudo novaboot-power delayed-off
+RemainAfterExit=true