Servers often have wrong clock on startup. NTP services, like
systemd-timesyncd try to correct clock gradually to avoid weird bugs in software. Therefore, if server has a large clock offset on startup, it works with incorrect clock for several minutes.
In my experience, AWS instances may have clock error up to 5 minutes on startup. Server writing log timestamps 5 minutes in the past or in the future is not always a good idea.
Solution is to force NTP time syncronization once before starting any other services. I prefer to use chrony: it can act both as always runnig NTP client and one-time syncronization tool;
chronyc clearly reports syncronization status, making it easy to monitor; it is recommended by AWS.
All other services in
multi-user.target will start after time is syncronized or failed to syncronize after given timeout.
network-online.target sometimes is not working as expected,
ExecStartPre line is a workaround for that.
Comments are closed