Time Difference between reboots

whenever a reboot happens there is always a time shift in logs till pppoe is up and ntp server is reachable.

Before:
2020-04-03T10:43:35+00:00 OpenWrt dnsmasq[26737]: exiting on receipt of SIGTERM
2020-04-03T10:43:35+00:00 OpenWrt miniupnpd[2860]: shutting down MiniUPnPd
After:
2020-04-03T10:00:25+00:00 OpenWrt netifd: Network device 'eth0' link is up
2020-04-03T10:00:25+00:00 OpenWrt netifd: Interface 'wan' has link connectivity
2020-04-03T10:00:25+00:00 OpenWrt netifd: Interface 'wan' is setting up now

from what I understand the system date and time are set by /etc/init.d/sysfixtime script by finding the most recent timestamp of any file found in /etc.
if that is the case why not use /var/log instead of /etc ?
log files should have the most recent timestamp so when the system reboots the logs timestamp should continue from where they left off before reboot.
right?

1 Like

Logfiles are kept in /tmp. Which is lost during boot.

yes, my bad. realized that just after I pressed the create topic button. Still trying to find a better way. maybe using an external drive for logs and modify the file to point to that external drive. but again how fast that drive would be accessible at boot time.

Except that support for external drives will be enabled during the boot process after the the first log items have already been logged.

As there is no real-time clock, there is no great alternative for finding the "correct last time".

Your best bet is to "touch /etc/banner" always before a planned reboot.

Thanks.
I created a cron job

*/5 * * * * touch /etc/banner

so worst case scenario the time difference will be 5 minutes for either planned or unplanned reboots.
but will there be any downsides for such cron job?

You burn out your flash sooner or later, as you write a new 64 kB erase block every five minutes. (That it the basic reason why default OpenWrt writes pretty much nothing to the flash after the boot has been completed.)

Depending on your crashines and/or power problems, writing 1-2 times per day should be enough. If you really need exact time right after the boot, you might use some x86 device with a real-time clock.

2 Likes

A workaround for anyone interested, using a local syslog server with the sever time-stamping received messages with the time received rather than router generated timestamp before correcting it's clock.