Help wanted to finalise wtmpdb init integration
Andrew Bower
andrew at bower.uk
Wed Mar 5 17:35:17 GMT 2025
Lorenzo and Mark,
Thank you both for the brilliant discussion!
Lorenzo was right about the runlevels to use, and because we are
supplied with the current and previous runlevel when invoked by init, we
can perform single shot services quite easily without (ironically)
parsing utmp or handling guard files. Perhaps this shouldn't be a
surprise as this isn't exactly the first ever one-shot init script!
How about this? It seems to work flawlessly including over
re-installation and when going down or starting in single user mode. I
guess I can ditch the argument to dh_installinit, too.
---
debian/wtmpdb.wtmpdb-update-boot.init | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/debian/wtmpdb.wtmpdb-update-boot.init b/debian/wtmpdb.wtmpdb-update-boot.init
index 4022d0f..ae68562 100644
--- a/debian/wtmpdb.wtmpdb-update-boot.init
+++ b/debian/wtmpdb.wtmpdb-update-boot.init
@@ -1,8 +1,10 @@
#! /bin/sh
#
-# Provided by Mark Hindley from unit file using utrans generator:
+# Thanks to:
+# Mark Hindley
+# Lorenzo Puliti
#
-# Generated by /home/mark/src/debian/unit-translator/utrans from:
+# Originally generated by /home/mark/src/debian/unit-translator/utrans from:
# 6e6aacdeddf878a01b260abbda787373e176cce440d786d535d6cf7a465c25cd
# +./tmp.iH71YBzenr/usr/lib/systemd/system/wtmpdb-update-boot.service
@@ -17,7 +19,7 @@ fi
# Required-Stop: $remote_fs
# Should-Start:
# Should-Stop:
-# Default-Start: 1 2 3 4 5
+# Default-Start: S
# Default-Stop: 0 6
# Short-Description: Write boot and shutdown times into wtmpdb
# Description: Invokes wtmpdb to write boot and shutdown times
@@ -29,9 +31,15 @@ DAEMON="none"
NAME="wtmpdb-update-boot"
do_start_cmd_override() {
- /usr/bin/wtmpdb boot
+ if [ "$RUNLEVEL" = "S" ] && [ "$PREVLEVEL" = "N" ]
+ then
+ /usr/bin/wtmpdb boot
+ fi
}
do_stop_cmd_override() {
- /usr/bin/wtmpdb shutdown
+ if [ "$RUNLEVEL" = "0" ] || [ "$RUNLEVEL" = "6" ]
+ then
+ /usr/bin/wtmpdb shutdown
+ fi
}
--
2.47.2
More information about the Debian-init-diversity
mailing list