]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Fix enabling of delayed power off
authorMichal Sojka <michal.sojka@cvut.cz>
Fri, 17 Dec 2021 09:35:03 +0000 (10:35 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Fri, 17 Dec 2021 12:10:30 +0000 (13:10 +0100)
The documented procedure stopped working after the last commit because
the [Install] section was removed from
novaboot-delayed-power-off.service.

In addition to adding the [Install] section, we also reshuffle
documentation and update systemd unit dependencies to make
power-on/off operations more reliable. The latter should (hopefully)
fix some race conditions that were possible in the past.

debian/novaboot-server.install
server/Makefile
server/adduser-novaboot.pod
server/novaboot-shell.pod
server/systemd/novaboot-delayed-power-off.service
server/systemd/novaboot-delayed-power-off.target [new file with mode: 0644]
server/systemd/novaboot-power-off@.timer

index 6f35d49f2e1f79e00e399636a15fce9c5cc7604a..c13ab8b07e08d4c91299df5fd3d37178e02d080b 100644 (file)
@@ -5,6 +5,7 @@
 /usr/sbin/novaboot-power
 /usr/bin/novaboot-shell
 /usr/lib/systemd/user/novaboot-delayed-power-off.service
+/usr/lib/systemd/user/novaboot-delayed-power-off.target
 /usr/lib/sysusers.d/novaboot-server.conf
 /usr/sbin/adduser-novaboot
 /usr/share/man/man1/novaboot-shell.1
index e8e595598a7281e54e0b2f315199c575981b8492..d5c6070ecd47272035de08520b4c624ebf993a30 100644 (file)
@@ -18,5 +18,6 @@ install: all
        install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-power-off@.timer
        install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-power@.service
        install -D -m 644 -t $(DESTDIR)/usr/lib/systemd/user systemd/novaboot-delayed-power-off.service
+       install -D -m 644 -t $(DESTDIR)/usr/lib/systemd/user systemd/novaboot-delayed-power-off.target
        install -D -m 440 systemd/sudoers.novaboot-server $(DESTDIR)/etc/sudoers.d/novaboot-server
        install -D -m 755 -t $(DESTDIR)$(PREFIX)/sbin systemd/novaboot-power
index 01380def3805e653dbc8067e42f0880ca0b73771..58e070bee2390e34a56097889b33e46320a72161 100644 (file)
@@ -20,27 +20,8 @@ and symlinks that for integration with TFTP server.
 =head2 Automatic power-off
 
 When your system uses L<systemd(1)>, you can configure a systemd
-service to automatically power-off the target after timeout. To enable
-this run:
-
-    systemctl --user enable novaboot-delayed-power-off
-
-as the created user (e.g. via shell subcommand). To enable delayed
-power-off for all novaboot-shell account, run the follwing as root:
-
-    systemctl --global enable novaboot-delayed-power-off
-
-Individual accounts may disable this global configuration by running:
-
-    systemctl --user mask novaboot-delayed-power-off
-
-The power-off timeout is hardcoded in the B<novaboot-power-off@.timer>
-unit. To override the timeout, run C<systemctl edit
-novaboot-power-off@TARGET.timer> for your B<TARGET> and insert the
-following to the spawned editor:
-
-    [Timer]
-    OnActiveSec=30min
+service to automatically power-off the target after a timeout. See
+C<novaboot-delayed-power-off> in L<novaboot-shell(1)>.
 
 =head1 OPTIONS
 
index fa831353c8feac4ea0c372ceb1f79eab37c733c4..aad46648319b796231b513e3155fe40d3681dfe3 100644 (file)
@@ -132,7 +132,11 @@ Command to C<exec> that powers the target on.
 
 =item off_cmd
 
-Command to C<exec> that powers the target off.
+Command to C<exec> that powers the target off. This command is
+executed either explicitly, when novaboot-shell C<off> command is
+invoked or automatically, after the last novaboot-shell session
+finishes and the C<novaboot-delayed-power-off> systemd user service is
+enabled (see below).
 
 =item target_config
 
@@ -192,6 +196,36 @@ is perhaps this command:
 
 =back
 
+=head1 AUTOMATIC POWER OFF
+
+The target can be automatically powered off when the last session
+finishes. This can be enabled by running:
+
+    systemctl --user enable novaboot-delayed-power-off
+
+perhaps via the C<shell> subcommand. To enable delayed power-off for
+all novaboot-shell accounts, run the follwing as root:
+
+    systemctl --global enable novaboot-delayed-power-off
+
+Individual accounts may disable this global configuration by running:
+
+    systemctl --user mask novaboot-delayed-power-off
+
+When C<novaboot-delayed-power-off> is enabled, the I<on> and I<off>
+commands are executed via systemd rather than by C<novaboot-shell>
+directly. The delay between the end of the session and power off is
+hardcoded in the B<novaboot-power-off@.timer> unit. To override the
+timeout for individual targets, run:
+
+    systemctl edit novaboot-power-off@TARGET.timer
+
+for your B<TARGET> (the user running C<novaboot-shell>) and insert the
+following to the spawned editor:
+
+    [Timer]
+    OnActiveSec=30min
+
 =head1 AUTHORS
 
 Michal Sojka <sojkam1@fel.cvut.cz>
index fe79613490da33e56a874c2c9353964f00d8eef5..cf750c3cd65b48f000c8446f87e64895bbebd461 100644 (file)
@@ -7,3 +7,6 @@ ConditionFileNotEmpty=%h/.novaboot-shell
 Type=oneshot
 ExecStop=/usr/bin/sudo novaboot-power delayed-off
 RemainAfterExit=true
+
+[Install]
+WantedBy=novaboot-delayed-power-off.target
diff --git a/server/systemd/novaboot-delayed-power-off.target b/server/systemd/novaboot-delayed-power-off.target
new file mode 100644 (file)
index 0000000..eed1e29
--- /dev/null
@@ -0,0 +1,6 @@
+# This unit serves only as a placeholde that allows enabling and
+# disabling novaboot-delayed-power-off.service. We don't use this
+# targer for anything.
+[Unit]
+Description=Novaboot power on target
+Documentation=man:novaboot-shell(1)
index b0596d4b315f687f5510ce199d8c87acec061817..fd53565bb91d347a89508f828f0c6c2d1f390130 100644 (file)
@@ -1,3 +1,10 @@
+[Unit]
+# Don't allow starting the timer if the target is already powered off
+Requisite=novaboot-power@%i.service
+After=novaboot-power@%i.service
+# If somebody powers off the target explicitly stop the timer (if running) too
+PartOf=novaboot-power@%i.service
+
 [Timer]
 OnActiveSec=10min
 Unit=novaboot-power-off@%i.service