Pi, no RTC, correct syncthing time at auto-start

For a long time I’ve struggled to get syncthing to start on Raspberry Pis after the correct time is set.

I think I’ve found a solution.

Anyone familiar with the pi will know that it doesn’t have a real-time clock (rtc addons available) and it solves this by saving the time at shutdown and carrying on from this value at next boot. Eventually it connects to a timeserver and sets the time correctly.

Until yesterday, I had syncthing@user.service disabled and used Cron to start the service after a sleep (60 later increased to 600 seconds).

This was, mostly, good enough.

I got a hint from Start systemd service after internet clock (superuser)

Now I use the following dropin, created via sudo systemctl edit syncthing@.service)

    [Unit]
    #Wants=network-online.target
    #After=network-online.target
    #After=systemd-timesyncd.service
    #After=time-sync.target
    Wants=systemd-time-wait-sync.service
    After=systemd-time-wait-sync.service

The commented out bits don’t do any harm, but are not necessary.

Journal

Mar 10 12:06:48 pi4b NetworkManager[415]: <info>  [1583842008.8226] device (wlan0): supplicant in
Mar 10 12:07:07 pi4b systemd-time-wait-sync[119]: adjtime state 0 status 2000 time Tue 2020-03-10
Mar 10 12:07:07 pi4b systemd-timesyncd[362]: Synchronized to time server for the first time [2a01
Mar 10 12:07:07 pi4b systemd[1]: Started Wait Until Kernel Time Synchronized.
Mar 10 12:07:07 pi4b systemd[1]: Started Syncthing - Open Source Continuous File Synchronization 
Mar 10 12:07:07 pi4b systemd[1]: Reached target System Time Synchronized.
Mar 10 12:07:07 pi4b systemd[1]: Started Daily rotation of log files.
Mar 10 12:07:07 pi4b systemd[1]: Started Daily apt download activities.
Mar 10 12:07:07 pi4b systemd[1]: Started Daily man-db regeneration.
Mar 10 12:07:07 pi4b systemd[1]: Started Daily apt upgrade and clean activities.
Mar 10 12:07:07 pi4b systemd[1]: Reached target Timers.
Mar 10 12:07:07 pi4b systemd[1]: Starting LSB: exim Mail Transport Agent...
Mar 10 12:07:07 pi4b systemd[1]: Starting Daily apt download activities...
Mar 10 12:07:07 pi4b syncthing[944]: [start] INFO: syncthing v1.3.4 "Fermium Flea" (go1.13.7 linu

~

2 Likes

Apologies to those who tried to read this before I fixed the formatting.

I should mention that with this dropin, st won’t start until there is an internet connection, preventing syncing on the local network.

It’s only useful for devices without an rtc.

dinosore,

So you’re having trouble getting Syncthing going on a Pi? I simply use a cron entry with a run condition of @reboot.

I’ve never had trouble with the Pi being off time upon boot. It even reset to daylight savings time this past weekend.

@increa, no, no difficulty getting st running: I’ve been using it successfully for several years.

I don’t think you understood the point of my post.

Yes, the pi will sync with a timeserver, so you will usually see the correct time - but it depends when you look.

At the start of the boot process, the clock time is out by at least a few seconds. If you look at the journal you will see the message Synchronized to time server for the first time. Look at the timestamps just before and you will see a discontinuity - in the example above, 19 seconds.

Try powering off the pi and leaving it powered off for an hour, a day or a week. The discontinuity will reflect the time you left it powered off.

And you wonder why I hate systemd? I’ve been playing around with ‘devuan’, a fork of Debian without systemd (https://devuan.org/os/debian-fork) and it has promise. It resolves back to the KISS principle…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.