diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 39 | ||||
-rw-r--r-- | ready-for-shutdown.target | 5 | ||||
-rw-r--r-- | ready-for-shutdown.target.8.in | 18 | ||||
-rwxr-xr-x | shutdown-if-no-sessions | 4 | ||||
-rw-r--r-- | shutdown-if-no-sessions.service.8 | 1 | ||||
-rw-r--r-- | shutdown-if-no-sessions.service.in | 7 |
7 files changed, 76 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..92389d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.service +*.target.8 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9984122 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +DESTDIR= +PREFIX=/usr/local +LIBEXECDIR=$(PREFIX)/libexec +LIBDIR=$(PREFIX)/lib +SYSDDIR=$(LIBDIR)/systemd/system +DATADIR=$(PREFIX)/share +MANDIR=$(DATADIR)/man +MAN8DIR=$(MANDIR)/man8 + + +%: %.in + sed "s|@LIBEXECDIR@|$(LIBEXECDIR)|g" $< >$@ + sed -i "s|@SYSDDIR@|$(SYSDDIR)|g" $@ + + +all: shutdown-if-no-sessions.service ready-for-shutdown.target.8 + + +install: all + install -m644 -Dt $(DESTDIR)$(SYSDDIR) ready-for-shutdown.target + install -m644 -Dt $(DESTDIR)$(MAN8DIR) ready-for-shutdown.target.8 + install -m644 -Dt $(DESTDIR)$(SYSDDIR) shutdown-if-no-sessions.service + install -m644 -Dt $(DESTDIR)$(MAN8DIR) shutdown-if-no-sessions.service.8 + install -m755 -Dt $(DESTDIR)$(LIBEXECDIR) shutdown-if-no-sessions + + +uninstall: + rm -f $(DESTDIR)$(SYSDDIR)/ready-for-shutdown.target + rm -f $(DESTDIR)$(MAN8DIR)/ready-for-shutdown.target.8 + rm -f $(DESTDIR)$(SYSDDIR)/shutdown-if-no-sessions.service + rm -f $(DESTDIR)$(MAN8DIR)/shutdown-if-no-sessions.service.8 + rm -f $(DESTDIR)$(BINDIR)/shutdown-if-no-sessions + + +clean: + rm -f *.service *.target.8 + + +.PHONY: all install uninstall clean diff --git a/ready-for-shutdown.target b/ready-for-shutdown.target new file mode 100644 index 0000000..10e8191 --- /dev/null +++ b/ready-for-shutdown.target @@ -0,0 +1,5 @@ +[Unit] +Description=All scheduled timers and builds are done +Documentation=man:ready-for-shutdown.target(8) +Before=shutdown-if-no-sessions.service +Wants=shutdown-if-no-sessions.service diff --git a/ready-for-shutdown.target.8.in b/ready-for-shutdown.target.8.in new file mode 100644 index 0000000..babba56 --- /dev/null +++ b/ready-for-shutdown.target.8.in @@ -0,0 +1,18 @@ +.TH ready-for-shutdown.target 8 "2024-01-25" +.SH NAME +ready-for-shutdown.target, shutdown-if-no-sessions.service - systemd target that marks completion of routine boot tasks +.SH SYNOPSIS +.B ready-for-shutdown.target +.br +.B shutdown-if-no-sessions.service +.SH DESCRIPTION +Target is intended to mark the completion of all scheduled tasks and readiness for shutdown that is triggered +immediately after. Before enabling this target add +.B [Install] +section listing all units that are intended to be run before shutting down. +.SH FILES +.I @SYSDDIR@/ready-for-shutdown.target +.br +.I @SYSDDIR@/shutdown-if-no-sessions.service +.br +.I @LIBEXECDIR@/shutdown-if-no-sessions diff --git a/shutdown-if-no-sessions b/shutdown-if-no-sessions new file mode 100755 index 0000000..285eb70 --- /dev/null +++ b/shutdown-if-no-sessions @@ -0,0 +1,4 @@ +#!/bin/sh +if ! who | grep -e tty -e pts; then + systemctl poweroff +fi diff --git a/shutdown-if-no-sessions.service.8 b/shutdown-if-no-sessions.service.8 new file mode 100644 index 0000000..54b70c1 --- /dev/null +++ b/shutdown-if-no-sessions.service.8 @@ -0,0 +1 @@ +.so ready-for-shutdown.target.8 diff --git a/shutdown-if-no-sessions.service.in b/shutdown-if-no-sessions.service.in new file mode 100644 index 0000000..f8d6748 --- /dev/null +++ b/shutdown-if-no-sessions.service.in @@ -0,0 +1,7 @@ +[Unit] +Description=Shutdown if nobody is logged in +Documentation=man:shutdown-if-no-sessions.service(8) + +[Service] +Type=oneshot +ExecStart=@LIBEXECDIR@/shutdown-if-no-sessions |