-/lib/systemd/system/novaboot-target-off@.target
-/lib/systemd/system/novaboot-target-off@.timer
-/lib/systemd/system/novaboot-target-on@.service
-/lib/systemd/system/novaboot-server-session@.service
+/etc/sudoers.d/novaboot-server
+/lib/systemd/system/novaboot-power-off@.target
+/lib/systemd/system/novaboot-power-off@.timer
+/lib/systemd/system/novaboot-power@.service
+/usr/bin/novaboot-power
/usr/bin/novaboot-shell
+/usr/lib/systemd/user/novaboot-power-off.service
/usr/lib/sysusers.d/novaboot-server.conf
/usr/sbin/adduser-novaboot
/usr/share/man/man1/novaboot-shell.1
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-target-off@.target
- install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-target-off@.timer
- install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-target-on@.service
- install -D -m 644 -t $(DESTDIR)/lib/systemd/system systemd/novaboot-server-session@.service
+ 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@.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
echo "NOT creating /srv/tftp/$user and symlink to it from $home/tftproot."
fi
-if [ -d /run/systemd/system ]; then
- echo "Installing systemd services and timers in /etc/systemd/system/user@$uid.service.d"
- mkdir -p /etc/systemd/system/user@$uid.service.d
- cat <<EOF > /etc/systemd/system/user@$uid.service.d/novaboot-server.conf
-[Unit]
-Requires=novaboot-server-session@$user.service
-After=novaboot-server-session@$user.service
-EOF
- systemctl daemon-reload
-fi
-
echo "Creating configuration template in $home/.novaboot-shell"
cat <<'CONFIG_EOF' > $home/.novaboot-shell
#!/bin/sh
CONFIG_EOF
chown $user: $home/.novaboot-shell
+if [ -d /run/systemd/system ]; then
+ cat <<EOF
+To enable automatic delayed power-off run 'systemctl --user enable novaboot-power-off'
+as the created user (e.g. via shell subcommand)
+EOF
+ # TODO: Add a way to run in automatically from here (allow shell
+ #subcommand to accept command lines)
+ #systemctl --user enable novaboot-power-off
+fi
+
+
+
echo "Done"
exit 0
. "${NOVABOOT_SHELL_CONFIG:-$HOME/.novaboot-shell}"
}
+power() {
+ local cmd
+ case "$1" in
+ "on") cmd="${on_cmd:?}";;
+ "off") cmd="${off_cmd:?}";;
+ *) die "Unexpected power parameter";;
+ esac
+
+ if [ "$PPID" -ne 1 ] && systemctl --user is-enabled novaboot-power-off.service; then
+ sudo novaboot-power "$1"
+ else
+ eval "$cmd"
+ fi
+}
+
# run_subcommand should be called only after permission checks and/or locking
run_subcommand() {
read_config
echo $NOVABOOT_PPID > $RUN_DIR/ppid
echo 'novaboot-shell: Connected'
# TODO: $reset_begin_cmd
+ [ -n "${on_cmd}" ] && power on
eval exec "${console_cmd:?}";;
"reset")
eval exec "${reset_cmd:?}";;
cd "$HOME/tftproot"
exec "$@";;
"on")
- eval exec "${on_cmd:?}";;
+ power on
+ exit;;
"off")
- eval exec "${off_cmd:?}";;
+ power off
+ exit;;
+ *)
+ die "Unknown command: $*";;
esac
}
mkdir -p "$RUN_DIR"
fi
-if [ -z "$NOVABOOT_ID" ]; then
+if [ -z "$NOVABOOT_ID" ] && [ "$PPID" -ne 1 ]; then
main "$@"
else
run_subcommand "$@"
+++ /dev/null
-[Unit]
-Description=Novaboot target on/off manager for %i
-StopWhenUnneeded=true
-
-Conflicts=novaboot-target-off@%i.timer
-
-[Service]
-Type=oneshot
-RemainAfterExit=yes
-ExecStart=/bin/systemctl start novaboot-target-on@%i.service
-ExecStop=/bin/systemctl start novaboot-target-off@%i.timer
+++ /dev/null
-[Unit]
-Description=Power off a novaboot target %i
-Conflicts=novaboot-target-on@%i.service
-Conflicts=novaboot-target-off@%i.timer
-After=novaboot-target-on@%i.service
+++ /dev/null
-[Timer]
-OnActiveSec=10min
-Unit=novaboot-target-off@%i.target
+++ /dev/null
-[Unit]
-Description=Power on novaboot target %i
-
-[Service]
-Type=oneshot
-RemainAfterExit=true
-ExecStart=/usr/bin/novaboot-shell -c on
-ExecStop=/usr/bin/novaboot-shell -c off
-User=%i
+++ /dev/null
-[Unit]
-Requires=novaboot-server-session@tx1.service
-After=novaboot-server-session@tx1.service