missing RTC; use/create timestamp on start / stop
The RPI4 lacks a real time clock; and I got fed up seeing that the runit services were marked as having started 51 years ago
I made this start/stop script "timestamp" which I put in /lib/rc/sv.d
#!/bin/bash
# sourcing our current rc.conf requires this to be a bash script
. /usr/lib/rc/functions
TSF=/var/lib/ntp/timestamp
case "$1" in
start)
if [ -f "$TSF" ]; then
if TS="$(/usr/bin/date -u $(/usr/bin/cat ${TSF}))"; then
echo "+++++ timestamp read from ${TSF} as ${TS}"
else
echo "!!!!! failed to read timestamp from ${TSF}"
fi
fi
;;
stop)
if TS="$(date -u +%m%d%H%M%Y.%S)" &&echo "${TS}" > ${TSF}; then
echo "+++++ timestamp ${TS} written to ${TSF}"
else
echo "!!!!! failed to write timestamp ${TS} to ${TSF}"
fi
;;
*)
echo "usage: $0 {start|stop}"
exit 1
;;
esac
this is started and stopped by links in /etc/rc/sysinit/ and /etc/rc/shutdown these are /etc/rc/shutdown/59-timestamp -> /usr/lib/rc/sv.d/timestamp
/etc/rc/sysinit/09-timestamp -> /usr/lib/rc/sv.d/timestamp
My services are now only a minute old after a reboot. That is not true for longer shut downs, but at least created files are in relatively correct order etc etc.