From 945b93d256ba7d090570b0b9b4f557d1f30132c2 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 17 Dec 2021 10:35:03 +0100 Subject: [PATCH] server: Fix enabling of delayed power off 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 | 1 + server/Makefile | 1 + server/adduser-novaboot.pod | 23 ++---------- server/novaboot-shell.pod | 36 ++++++++++++++++++- .../novaboot-delayed-power-off.service | 3 ++ .../systemd/novaboot-delayed-power-off.target | 6 ++++ server/systemd/novaboot-power-off@.timer | 7 ++++ 7 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 server/systemd/novaboot-delayed-power-off.target diff --git a/debian/novaboot-server.install b/debian/novaboot-server.install index 6f35d49..c13ab8b 100644 --- a/debian/novaboot-server.install +++ b/debian/novaboot-server.install @@ -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 diff --git a/server/Makefile b/server/Makefile index e8e5955..d5c6070 100644 --- a/server/Makefile +++ b/server/Makefile @@ -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 diff --git a/server/adduser-novaboot.pod b/server/adduser-novaboot.pod index 01380de..58e070b 100644 --- a/server/adduser-novaboot.pod +++ b/server/adduser-novaboot.pod @@ -20,27 +20,8 @@ and symlinks that for integration with TFTP server. =head2 Automatic power-off When your system uses L, 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 -unit. To override the timeout, run C for your B and insert the -following to the spawned editor: - - [Timer] - OnActiveSec=30min +service to automatically power-off the target after a timeout. See +C in L. =head1 OPTIONS diff --git a/server/novaboot-shell.pod b/server/novaboot-shell.pod index fa83135..aad4664 100644 --- a/server/novaboot-shell.pod +++ b/server/novaboot-shell.pod @@ -132,7 +132,11 @@ Command to C that powers the target on. =item off_cmd -Command to C that powers the target off. +Command to C that powers the target off. This command is +executed either explicitly, when novaboot-shell C command is +invoked or automatically, after the last novaboot-shell session +finishes and the C 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 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 is enabled, the I and I +commands are executed via systemd rather than by C +directly. The delay between the end of the session and power off is +hardcoded in the B unit. To override the +timeout for individual targets, run: + + systemctl edit novaboot-power-off@TARGET.timer + +for your B (the user running C) and insert the +following to the spawned editor: + + [Timer] + OnActiveSec=30min + =head1 AUTHORS Michal Sojka diff --git a/server/systemd/novaboot-delayed-power-off.service b/server/systemd/novaboot-delayed-power-off.service index fe79613..cf750c3 100644 --- a/server/systemd/novaboot-delayed-power-off.service +++ b/server/systemd/novaboot-delayed-power-off.service @@ -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 index 0000000..eed1e29 --- /dev/null +++ b/server/systemd/novaboot-delayed-power-off.target @@ -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) diff --git a/server/systemd/novaboot-power-off@.timer b/server/systemd/novaboot-power-off@.timer index b0596d4..fd53565 100644 --- a/server/systemd/novaboot-power-off@.timer +++ b/server/systemd/novaboot-power-off@.timer @@ -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 -- 2.39.2