]> rtime.felk.cvut.cz Git - novaboot.git/commitdiff
server: Add missing files for delayed power-off
authorMichal Sojka <michal.sojka@cvut.cz>
Sun, 1 Mar 2020 14:42:39 +0000 (15:42 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Thu, 17 Dec 2020 08:49:22 +0000 (09:49 +0100)
These should have been a part of commit 9dffa51 ("Simplify systemd
logic for automated delayed power off", 2019-11-21).

debian/novaboot-server.install
server/Makefile
server/systemd/novaboot-power [new file with mode: 0755]
server/systemd/novaboot-power-off.service [new file with mode: 0644]
server/systemd/novaboot-power-off@.service [new file with mode: 0644]
server/systemd/novaboot-power-off@.timer [new file with mode: 0644]
server/systemd/novaboot-power@.service [new file with mode: 0644]
server/systemd/sudoers.novaboot-server [new file with mode: 0644]

index 43001b2fa6d8e70e72db3947cada44ea91e689d3..1659f1d66babdce6a88f47a61d987ede20648a00 100644 (file)
@@ -1,8 +1,8 @@
 /etc/sudoers.d/novaboot-server
-/lib/systemd/system/novaboot-power-off@.target
+/lib/systemd/system/novaboot-power-off@.service
 /lib/systemd/system/novaboot-power-off@.timer
 /lib/systemd/system/novaboot-power@.service
-/usr/bin/novaboot-power
+/usr/sbin/novaboot-power
 /usr/bin/novaboot-shell
 /usr/lib/systemd/user/novaboot-power-off.service
 /usr/lib/sysusers.d/novaboot-server.conf
index 9d0413fe7240651b032b1687434d036eda71a1a0..812071ac37f34611531303f75c8b04befbe2ea00 100644 (file)
@@ -14,9 +14,9 @@ install: all
        install -D -m 755 -t $(DESTDIR)$(PREFIX)/sbin adduser-novaboot
        install -D -m 644 -t $(DESTDIR)$(PREFIX)/share/man/man8 adduser-novaboot.8
        install -D -m 644 -t $(DESTDIR)$(PREFIX)/lib/sysusers.d sysusers.d/novaboot-server.conf
-       install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-power-off@.target
+       install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-power-off@.service
        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-power-off.service
        install -D -m 440 systemd/sudoers.novaboot-server $(DESTDIR)/etc/sudoers.d/novaboot-server
-       install -D -m 755 -t $(DESTDIR)$(PREFIX)/bin systemd/novaboot-power
+       install -D -m 755 -t $(DESTDIR)$(PREFIX)/sbin systemd/novaboot-power
diff --git a/server/systemd/novaboot-power b/server/systemd/novaboot-power
new file mode 100755 (executable)
index 0000000..8b1663e
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+if [ -z "$SUDO_USER" ]; then
+    echo >&2 "$0 must be invoked via sudo"
+    exit 1
+fi
+
+case "$1" in
+    on)
+       exec systemctl start "novaboot-power@${SUDO_USER}.service";;
+    off)
+       exec systemctl stop "novaboot-power@${SUDO_USER}.service";;
+    delayed-off)
+       systemctl start "novaboot-power-off@${SUDO_USER}.timer"
+       # || systemd-run --on-active="$2" --unit="novaboot-power-off@${SUDO_USER}.target"
+       ;;
+    *)
+       echo >&2 "Invalid argument"
+       exit 1;;
+esac
diff --git a/server/systemd/novaboot-power-off.service b/server/systemd/novaboot-power-off.service
new file mode 100644 (file)
index 0000000..97d3efd
--- /dev/null
@@ -0,0 +1,13 @@
+[Unit]
+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
diff --git a/server/systemd/novaboot-power-off@.service b/server/systemd/novaboot-power-off@.service
new file mode 100644 (file)
index 0000000..7f73547
--- /dev/null
@@ -0,0 +1,12 @@
+[Unit]
+Description=Power off novaboot target %i
+Conflicts=novaboot-power@%i.service
+After=novaboot-power@%i.service
+
+[Service]
+Type=oneshot
+# We don't need to execute anything. It's sufficient to Conflict
+# novaboot-power. But units without Exec* are invalid. And we don't
+# want tu use target unit (that don't need Exec*), because these don't
+# have RemainAfterExit=no.
+ExecStart=true
diff --git a/server/systemd/novaboot-power-off@.timer b/server/systemd/novaboot-power-off@.timer
new file mode 100644 (file)
index 0000000..b0596d4
--- /dev/null
@@ -0,0 +1,4 @@
+[Timer]
+OnActiveSec=10min
+Unit=novaboot-power-off@%i.service
+RemainAfterElapse=no
diff --git a/server/systemd/novaboot-power@.service b/server/systemd/novaboot-power@.service
new file mode 100644 (file)
index 0000000..b5702b4
--- /dev/null
@@ -0,0 +1,10 @@
+[Unit]
+Description=Power on/off novaboot target %i
+
+[Service]
+Type=oneshot
+RemainAfterExit=true
+ExecStartPre=systemctl stop novaboot-power-off@%i.timer
+ExecStart=/usr/bin/novaboot-shell on
+ExecStop=/usr/bin/novaboot-shell off
+User=%i
diff --git a/server/systemd/sudoers.novaboot-server b/server/systemd/sudoers.novaboot-server
new file mode 100644 (file)
index 0000000..96a257e
--- /dev/null
@@ -0,0 +1,3 @@
+# sudoers file for novaboot-server
+
+%novaboot ALL = NOPASSWD: /usr/sbin/novaboot-power