Skip to main content
Topic: missing RTC; use/create timestamp on start / stop (Read 474 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

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

Code: [Select]
#!/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
Code: [Select]
/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.

 

Re: missing RTC; use/create timestamp on start / stop

Reply #1
congratulation!  ;D  ;D  it was lauched in 1970

1970 is the lowest possible year in IT, sometimes documents with a date of 1.1.1970 appeared to me earlier (in Windows)