NTP service allways changes to inactive

That is what I am using. I have it write the downloaded zip file, but something is wrong. It doesn’t look like a boot disk

Not sure if you have downloaded the correct file. Reading “downloaded zip file” either you downloaded the wrong file or just used the wrong term in your statement.
The image is not a zip ( .zip ) file but xz-compressed ( .xz ).

That is probably the problem, but I can’t figure out where to get that file on GitHub GitHub - BigGeorgeTx/openhabian: openHABian - empowering the smart home, for Raspberry Pi and Debian systems

Would you like to use the prebuild image ? Then you need to download it from Releases · openhab/openhabian · GitHub .
In case you would like to apply some fixes then you most probably do not want to download the prebuild image but would like to create your own image ?

I appreciate the suggestion. I’m trying to follow @mstormi 's guidance to troubleshoot the issue I and others have with NTP service, and I’m stuck at this point. It is a bit beyond my current knowledge, but I’m happy to learn.

It’s a .xz file (although sometimes shown as .zip) that in turn has another .xz pack of the image inside.
So open the download with WinRAR or whatever and unpack it.
That .xz the Raspi imager should be able to read.
Guess I should modify the openhabian build process to eliminate that inner compression.

Thanks, but I’m not sure I understand. Or perhaps I’m working with the wrong file.

On the mail GitHub page GitHub - BigGeorgeTx/openhabian: openHABian - empowering the smart home, for Raspberry Pi and Debian systems
I click on Code, then Download ZIP


This doesn’t appear to be a .xy file, so I’m probably in the wrong place.

The right one is under Actions - Build - Artifacts.

Thanks for the hint. On the Actions page, under the Build Tab, I clicked on the successful build and it listed the Artifacts. I will download, unzip, and decompress and give it a try. Thanks for your patience as I work way above my knowledge level.

Update: the image booted successfully and is running on my test Pi.

OK. I was finally able to create an image on GitHub, download it to my Windows laptop, unzip it, load in on an SD card with the Raspberry Pi Imager, and boot it up. My first attempt failed in the build stage, but when I followed its suggest to use pgrep instead of grep, it was successful.

Without the setup_ntp, I still end up with NTP running:

openhabian@openhabian-test:~ $ timedatectl
               Local time: Sat 2023-05-06 11:45:33 CDT
           Universal time: Sat 2023-05-06 16:45:33 UTC
                 RTC time: n/a
                Time zone: America/Chicago (CDT, -0500)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
openhabian@openhabian-test:~ $ systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-05-06 11:12:45 CDT; 33min ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 287 (systemd-timesyn)
     Status: "Initial synchronization to time server [2600:1f13:2c1:2e00::be00:5]:123 (2.debian.pool.ntp.org)."
      Tasks: 2 (limit: 4531)
        CPU: 331ms
     CGroup: /system.slice/systemd-timesyncd.service
             └─287 /lib/systemd/systemd-timesyncd

May 06 11:12:45 openhabian-test systemd[1]: Starting Network Time Synchronization...
May 06 11:12:45 openhabian-test systemd[1]: Started Network Time Synchronization.

I tried using sudo -u systemd-timesync strace /lib/systemd/systemd-timesyncd | grep -i clock:

openhabian@openhab:/lib/systemd $ sudo -u systemd-timesync strace /lib/systemd/systemd-timesyncd
execve("/lib/systemd/systemd-timesyncd", ["/lib/systemd/systemd-timesyncd"], 0xbeca0750 /* 17 vars */) = 0
brk(NULL)                               = 0x861000
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb6fcf000
access("/etc/ld.so.preload", R_OK)      = 0
openat(AT_FDCWD, "/etc/ld.so.preload", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=54, ...}) = 0
mmap2(NULL, 54, PROT_READ|PROT_WRITE, MAP_PRIVATE, 3, 0) = 0xb6fce000
close(3)                                = 0
readlink("/proc/self/exe", "/lib/systemd/systemd-timesyncd", 4096) = 30
openat(AT_FDCWD, "/usr/lib/arm-linux-gnueabihf/libarmmem-v7l.so", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\254\3\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=17708, ...}) = 0
mmap2(NULL, 81964, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb6f8c000
mprotect(0xb6f90000, 61440, PROT_NONE)  = 0
mmap2(0xb6f9f000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0xb6f9f000
close(3)                                = 0
munmap(0xb6fce000, 54)                  = 0
openat(AT_FDCWD, "/lib/systemd/tls/v7l/neon/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l/neon/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/v7l/neon/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l/neon", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/v7l/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/v7l/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/v7l", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/neon/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/neon/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/neon/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/neon", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/tls/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/tls", 0xbe8fab68)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/v7l/neon/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l/neon/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/v7l/neon/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l/neon", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/v7l/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/v7l/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/v7l", 0xbe8fab68)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/neon/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/neon/vfp", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/neon/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/neon", 0xbe8fab68) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/vfp/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd/vfp", 0xbe8fab68)  = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/systemd/libc.so.6", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat64("/lib/systemd", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=44086, ...}) = 0
mmap2(NULL, 44086, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb6fc4000
close(3)                                = 0

I don’t know if it is relevant, but near the beginning of the above it makes an effort to open various files in /lib/systemd/tls. There is no such directory on my Pi. A few minutes on the interest informed me that these would be used if the system were securing the systemd DNS actions using TLS.
This next code was filtered by “clock” using grep, and seems to show the same OPERATION NOT PERMITTED that I was getting on the original system.

clock_gettime(CLOCK_REALTIME, {tv_sec=1683404074, tv_nsec=424397666}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=152535, tv_nsec=527010697}) = 0
clock_gettime(CLOCK_BOOTTIME, {tv_sec=152535, tv_nsec=527217396}) = 0
recvmsg(13, {msg_name={sa_family=AF_INET, sin_port=htons(123), sin_addr=inet_addr("50.205.57.38")}, msg_namelen=128->16, msg_iov=[{iov_base="$\1\6\347\0\0\0\0\0\0\0\0GPS\0\350\0013\253\0\0\0\0\350\0013\252\26\200\327\231"..., iov_len=48}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMPNS, cmsg_data={tv_sec=1683404074, tv_nsec=424015897}}], msg_controllen=20, msg_flags=0}, MSG_DONTWAIT) = 48
epoll_ctl(3, EPOLL_CTL_DEL, 13, NULL)   = 0
close(13)                               = 0
clock_adjtime(CLOCK_REALTIME, 0xbeba12a0) = -1 EPERM (Operation not permitted)
writev(2, [{iov_base="Failed to call clock_adjtime(): "..., iov_len=55}, {iov_base="\n", iov_len=1}], 2Failed to call clock_adjtime(): Operation not permitted
) = 56
sendmsg(10, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1\304\0\0\0\4\0\0\0~\0\0\0\1\1o\0\32\0\0\0/org/fre"..., iov_len=144}, {iov_base="!\0\0\0org.freedesktop.timesync1.Ma"..., iov_len=196}], msg_iovlen=2, msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 340
clock_gettime(CLOCK_BOOTTIME, {tv_sec=152535, tv_nsec=529261869}) = 0
epoll_wait(3, [{EPOLLIN, {u32=34477456, u64=34477456}}], 9, -1) = 1
clock_gettime(CLOCK_REALTIME, {tv_sec=1683404106, tv_nsec=625081849}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=152567, tv_nsec=727732175}) = 0
clock_gettime(CLOCK_BOOTTIME, {tv_sec=152567, tv_nsec=727983484}) = 0
read(14, "\1\0\0\0\0\0\0\0", 8)         = 8
socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_IP) = 13
bind(13, {sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
setsockopt(13, SOL_SOCKET, SO_TIMESTAMPNS, [1], 4) = 0
setsockopt(13, SOL_IP, IP_TOS, [16], 4) = 0
epoll_ctl(3, EPOLL_CTL_ADD, 13, {EPOLLIN, {u32=34498816, u64=34498816}}) = 0
clock_gettime(CLOCK_BOOTTIME, {tv_sec=152567, tv_nsec=729749242}) = 0
clock_gettime(CLOCK_REALTIME, {tv_sec=1683404106, tv_nsec=627564572}) = 0
sendto(13, "#\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 48, MSG_DONTWAIT, {sa_family=AF_INET, sin_port=htons(123), sin_addr=inet_addr("50.205.57.38")}, 16) = 48
clock_gettime(CLOCK_BOOTTIME, {tv_sec=152567, tv_nsec=730783071}) = 0
timerfd_settime(14, TFD_TIMER_ABSTIME, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=152599, tv_nsec=977117000}}, NULL) = 0
epoll_wait(3, [{EPOLLIN, {u32=34498816, u64=34498816}}], 10, -1) = 1
clock_gettime(CLOCK_REALTIME, {tv_sec=1683404106, tv_nsec=674596330}) = 0
clock_gettime(CLOCK_MONOTONIC, {tv_sec=152567, tv_nsec=777232748}) = 0
clock_gettime(CLOCK_BOOTTIME, {tv_sec=152567, tv_nsec=777456669}) = 0
recvmsg(13, {msg_name={sa_family=AF_INET, sin_port=htons(123), sin_addr=inet_addr("50.205.57.38")}, msg_namelen=128->16, msg_iov=[{iov_base="$\1\6\347\0\0\0\0\0\0\0\0GPS\0\350\0013\313\0\0\0\0\350\0013\312%g\340\34"..., iov_len=48}], msg_iovlen=1, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_TIMESTAMPNS, cmsg_data={tv_sec=1683404106, tv_nsec=674212579}}], msg_controllen=20, msg_flags=0}, MSG_DONTWAIT) = 48
epoll_ctl(3, EPOLL_CTL_DEL, 13, NULL)   = 0
close(13)                               = 0
clock_adjtime(CLOCK_REALTIME, 0xbeba12a0) = -1 EPERM (Operation not permitted)
writev(2, [{iov_base="Failed to call clock_adjtime(): "..., iov_len=55}, {iov_base="\n", iov_len=1}], 2Failed to call clock_adjtime(): Operation not permitted
) = 56
sendmsg(10, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\4\1\1\304\0\0\0\5\0\0\0~\0\0\0\1\1o\0\32\0\0\0/org/fre"..., iov_len=144}, {iov_base="!\0\0\0org.freedesktop.timesync1.Ma"..., iov_len=196}], msg_iovlen=2, msg_controllen=0, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = 340

I will let it run for a while and see what happens.

I set the first boot log to maximum. If there is anything I should check that might be helpful in troubleshooting the original problem, please let me know.

I guess that’s “ok” as a Pi does not have any real time clock.

Good point.

I see a big difference between the test machine and the operational one with journalctl -u systemd-timesyncd. First the operational one, that eventually exceeds the start limit and fails:

openhabian@openhab:/lib/systemd $ journalctl -u systemd-timesyncd
-- Logs begin at Sat 2023-05-06 06:50:32 CDT, end at Sat 2023-05-06 16:39:42 CDT. --
May 06 16:26:43 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:26:43 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:26:44 openhab systemd-timesyncd[26064]: Synchronized to time server for the first time 147.182.158.78:123 (0.debian.pool.ntp.org).
May 06 16:28:20 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:28:20 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:28:20 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:28:20 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:28:20 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:28:20 openhab systemd-timesyncd[26172]: Synchronized to time server for the first time 147.182.158.78:123 (0.debian.pool.ntp.org).
May 06 16:28:21 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:28:21 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:28:21 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:28:21 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:28:21 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:28:21 openhab systemd-timesyncd[26191]: Synchronized to time server for the first time 162.159.200.1:123 (0.debian.pool.ntp.org).
May 06 16:28:21 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:28:21 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:28:21 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:28:21 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:28:21 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:28:21 openhab systemd-timesyncd[26210]: Synchronized to time server for the first time 184.105.182.16:123 (0.debian.pool.ntp.org).
May 06 16:28:21 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:28:21 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:28:21 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:28:21 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:28:21 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:28:21 openhab systemd-timesyncd[26229]: Synchronized to time server for the first time 184.105.182.16:123 (0.debian.pool.ntp.org).
May 06 16:28:58 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:28:58 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:28:58 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:28:58 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:28:58 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:28:58 openhab systemd-timesyncd[26296]: Synchronized to time server for the first time 147.182.158.78:123 (0.debian.pool.ntp.org).
May 06 16:32:14 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:32:14 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:32:14 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:32:14 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:32:14 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:32:14 openhab systemd-timesyncd[26488]: Synchronized to time server for the first time 171.66.97.126:123 (0.debian.pool.ntp.org).
May 06 16:33:09 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:33:09 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:33:09 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:33:09 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:33:10 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:33:10 openhab systemd-timesyncd[26555]: Synchronized to time server for the first time 171.66.97.126:123 (0.debian.pool.ntp.org).
May 06 16:33:29 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:33:29 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:33:29 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:33:29 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:33:29 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:33:29 openhab systemd-timesyncd[26603]: Synchronized to time server for the first time 171.66.97.126:123 (0.debian.pool.ntp.org).
May 06 16:35:03 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:35:03 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:35:03 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:35:03 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:35:03 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:35:03 openhab systemd-timesyncd[26689]: Synchronized to time server for the first time 205.233.73.201:123 (0.debian.pool.ntp.org).
May 06 16:35:35 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:35:35 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:35:35 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:35:35 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:35:35 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:35:35 openhab systemd-timesyncd[26755]: Synchronized to time server for the first time 205.233.73.201:123 (0.debian.pool.ntp.org).
May 06 16:37:08 openhab systemd[1]: Stopping Network Time Synchronization...
May 06 16:37:08 openhab systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 16:37:08 openhab systemd[1]: Stopped Network Time Synchronization.
May 06 16:37:08 openhab systemd[1]: Starting Network Time Synchronization...
May 06 16:37:08 openhab systemd[1]: Started Network Time Synchronization.
May 06 16:37:08 openhab systemd-timesyncd[26844]: Synchronized to time server for the first time 129.250.35.250:123 (0.debian.pool.ntp.org).

And from the test unit using the custom build:

openhabian@openhabian-test:~ $ journalctl -u systemd-timesyncd
-- Journal begins at Tue 2023-05-02 19:25:51 CDT, ends at Sat 2023-05-06 16:35:01 CDT. --
May 02 19:25:54 openhabian systemd[1]: Starting Network Time Synchronization...
May 02 19:25:55 openhabian systemd[1]: Started Network Time Synchronization.
May 06 11:04:20 openhabian systemd-timesyncd[348]: Initial synchronization to time server [2606:4700:f1::1]:123 (2.debian.pool.ntp.org).
May 06 11:12:43 openhabian-test systemd[1]: Stopping Network Time Synchronization...
May 06 11:12:43 openhabian-test systemd[1]: systemd-timesyncd.service: Succeeded.
May 06 11:12:43 openhabian-test systemd[1]: Stopped Network Time Synchronization.
-- Boot ad6033a07b6e4472896e127850be3bfb --
May 06 11:12:45 openhabian-test systemd[1]: Starting Network Time Synchronization...
May 06 11:12:45 openhabian-test systemd[1]: Started Network Time Synchronization.
openhabian@openhabian-test:~ $ 

The custom build (w/o the setup NTP code), starts and keeps running.
I don’t pretend to understand why they are different, but hopefully this helps.

Not sure what is next in troubleshooting.

I looked at the /lib/dhcpcd/dhcpcd-hooks/ folder that the BASH ntp-setup copies into.
On the production Pi (with the problem), it looks like this:

openhabian@openhab:/lib/dhcpcd/dhcpcd-hooks $ ls
01-test  02-dump  10-wpa_supplicant  20-resolv.conf  30-hostname  50-ntp.conf  50-timesyncd.conf

The test Pi with the new build looks like this:

openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ls
01-test  02-dump  10-wpa_supplicant  20-resolv.conf  30-hostname  60-ntp-common.conf  62-chrony.conf  64-timesyncd.conf  66-ntp.conf  68-openntpd.conf

The conf files, first from the production Pi:

openhabian@openhab:/lib/dhcpcd/dhcpcd-hooks $ cat 50-ntp.conf
# Sample dhcpcd hook script for NTP
# It will configure either one of NTP, OpenNTP or Chrony (in that order)
# and will default to NTP if no default config is found.

# Like our resolv.conf hook script, we store a database of ntp.conf files
# and merge into /etc/ntp.conf

# You can set the env var NTP_CONF to override the derived default on
# systems with >1 NTP client installed.
# Here is an example for OpenNTP
#   dhcpcd -e NTP_CONF=/usr/pkg/etc/ntpd.conf
# or by adding this to /etc/dhcpcd.conf
#   env NTP_CONF=/usr/pkg/etc/ntpd.conf
# or by adding this to /etc/dhcpcd.enter-hook
#   NTP_CONF=/usr/pkg/etc/ntpd.conf
# To use Chrony instead, simply change ntpd.conf to chrony.conf in the
# above examples.

: ${ntp_confs:=ntp.conf ntpd.conf chrony.conf}
: ${ntp_conf_dirs=/etc /usr/pkg/etc /usr/local/etc}
ntp_conf_dir="$state_dir/ntp.conf"

# If NTP_CONF is not set, work out a good default
if [ -z "$NTP_CONF" ]; then
        for d in ${ntp_conf_dirs}; do
                for f in ${ntp_confs}; do
                        if [ -e "$d/$f" ]; then
                                NTP_CONF="$d/$f"
                                break 2
                        fi
                done
        done
        [ -e "$NTP_CONF" ] || NTP_CONF=/etc/ntp.conf
fi

# Derive service name from configuration
if [ -z "$ntp_service" ]; then
        case "$NTP_CONF" in
        *chrony.conf)           ntp_service=chronyd;;
        *)                      ntp_service=ntp;;
        esac
fi

# Debian has a seperate file for DHCP config to avoid stamping on
# the master.
if [ "$ntp_service" = ntp ] && type invoke-rc.d >/dev/null 2>&1; then
        [ -e /var/lib/ntp ] || mkdir /var/lib/ntp
        : ${ntp_service:=ntp}
        : ${NTP_DHCP_CONF:=/run/ntp.conf.dhcp}
fi

: ${ntp_restart_cmd:=service_condcommand $ntp_service restart}

ntp_conf=${NTP_CONF}
NL="
"

build_ntp_conf()
{
        cf="$state_dir/ntp.conf.$ifname"

        # Build a list of interfaces
        interfaces=$(list_interfaces "$ntp_conf_dir")

        header=
        servers=
        if [ -n "$interfaces" ]; then
                # Build the header
                for x in ${interfaces}; do
                        header="$header${header:+, }$x"
                done

                # Build a server list
                srvs=$(cd "$ntp_conf_dir";
                        key_get_value "server " $interfaces)
                if [ -n "$srvs" ]; then
                        for x in $(uniqify $srvs); do
                                servers="${servers}server $x$NL"
                        done
                fi
        fi

        # Merge our config into ntp.conf
        [ -e "$cf" ] && rm -f "$cf"
        [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"

        if [ -n "$NTP_DHCP_CONF" ]; then
                [ -e "$ntp_conf" ] && cp "$ntp_conf" "$cf"
                ntp_conf="$NTP_DHCP_CONF"
        elif [ -e "$ntp_conf" ]; then
                remove_markers "$signature_base" "$signature_base_end" \
                        "$ntp_conf" > "$cf"
        fi

        if [ -n "$servers" ]; then
                echo "$signature_base${header:+ $from }$header" >> "$cf"
                printf %s "$servers" >> "$cf"
                echo "$signature_base_end${header:+ $from }$header" >> "$cf"
        else
                [ -e "$ntp_conf" ] && [ -e "$cf" ] || return
        fi

        # If we changed anything, restart ntpd
        if change_file "$ntp_conf" "$cf"; then
                [ -n "$ntp_restart_cmd" ] && eval $ntp_restart_cmd
        fi
}

add_ntp_conf()
{
        cf="$ntp_conf_dir/$ifname"

        [ -e "$cf" ] && rm "$cf"
        [ -d "$ntp_conf_dir" ] || mkdir -p "$ntp_conf_dir"
        if [ -n "$new_ntp_servers" ]; then
                for x in $new_ntp_servers; do
                        echo "server $x" >> "$cf"
                done
        fi
        build_ntp_conf
}

remove_ntp_conf()
{
        if [ -e "$ntp_conf_dir/$ifname" ]; then
                rm "$ntp_conf_dir/$ifname"
        fi
        build_ntp_conf
}

# For ease of use, map DHCP6 names onto our DHCP4 names
case "$reason" in
BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
        new_ntp_servers="$new_dhcp6_sntp_servers"
;;
esac

if $if_up; then
        add_ntp_conf
elif $if_down; then
        remove_ntp_conf
fi
openhabian@openhab:/lib/dhcpcd/dhcpcd-hooks $ cat 50-timesyncd.conf
# Set NTP servers for systemd-timesyncd

confd=/run/systemd/timesyncd.conf.d

set_servers() {
    mkdir -p "$confd"
    (
        echo "# Created by dhcpcd hook"
        echo "[Time]"
        echo "NTP=$new_ntp_servers"
    ) > "$confd/dhcp-ntp.conf"

    # Tell timesyncd it has an updated configuration
    systemctl try-reload-or-restart systemd-timesyncd
}

if $if_up; then
    set_servers
fi

And from the test Pi:

openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 60-ntp-common.conf
# common functions for separate server config

add_servers() {
        # exit early if there's nothing to do
        if [ "$new_ntp_servers" = "$old_ntp_servers" ]; then
                return
        fi

        rm -f "$SERVERFILE"

        if [ -n "$new_ntp_servers" ]; then
                rebuild_config
        fi

        reload_config
}

remove_servers() {
        local update_required
        if [ -f "$SERVERFILE_IPV4" ]; then
                rm -f "$SERVERFILE_IPV4"
                update_required=1
        fi
        if [ -f "$SERVERFILE_IPV6" ]; then
                rm -f "$SERVERFILE_IPV6"
                update_required=1
        fi
        if [ -n "$update_required" ]; then
                reload_config
        fi
}

handle_reason() {
        case "$reason" in
                BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
                        SERVERFILE="$SERVERFILE_IPV6"
                        new_ntp_servers="$new_dhcp6_sntp_servers"
                        old_ntp_servers="$old_dhcp6_sntp_servers"
                        add_servers
                        ;;
                BOUND|RENEW|REBIND|REBOOT)
                        SERVERFILE="$SERVERFILE_IPV4"
                        add_servers
                        ;;
                EXPIRE|FAIL|RELEASE|STOP)
                        remove_servers
                        ;;
        esac
}

# common functions for combined server config

start_mark="# dhcpcd $interface start"
end_mark="# dhcpcd $interface end"

# inserts a server configuration into the SERVERFILE
# takes an optional argument to indicate server options
insert_servers() {
        local tmpfile
        tmpfile=$(mktemp)
        local protocol='IPv4'
        if echo "$reason" | grep -q 6$; then
                protocol='IPv6'
        fi
        # update section for this interface and protocol
        if [ -f "$SERVERFILE" ]; then
                sed "/^$start_mark $protocol/,/^$end_mark $protocol/d" "$SERVERFILE" > "$tmpfile"
        fi
        # clean up and bail early if there's nothing else to do
        if [ -z "$new_ntp_servers" ] && [ ! -s "$tmpfile" ]; then
                rm -f "$SERVERFILE" "$tmpfile"
                return
        fi
        # otherwise update SERVERFILE
        if [ -n "$new_ntp_servers" ]; then
                echo "$start_mark $protocol" >> "$tmpfile"
                for server in $new_ntp_servers; do
                        echo "server $server${1:+ $1}" >> "$tmpfile"
                done
                echo "$end_mark $protocol" >> "$tmpfile"
        fi
        # preserve permissions if possible
        if [ -f "$SERVERFILE" ]; then
                chown --reference="$SERVERFILE" "$tmpfile"
                chmod --reference="$SERVERFILE" "$tmpfile"
        fi
        mv "$tmpfile" "$SERVERFILE"
}

withdraw_servers() {
        if [ ! -f "$SERVERFILE" ]; then
                return
        fi
        local tmpfile
        tmpfile=$(mktemp)
        sed "/^$start_mark/,/^$end_mark/d" "$SERVERFILE" > "$tmpfile"
        # remove the SERVERFILE if there's nothing to put in it
        if [ ! -s "$tmpfile" ]; then
                rm -f "$SERVERFILE" "$tmpfile"
        else
                # otherwise update SERVERFILE
                chown --reference="$SERVERFILE" "$tmpfile"
                chmod --reference="$SERVERFILE" "$tmpfile"
                mv "$tmpfile" "$SERVERFILE"
        fi
}
# vi: ft=sh

and

openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 62-chrony.conf
# vi: ft=sh

SERVERFILE_IPV4="/var/lib/dhcp/chrony.servers.ipv4.$interface"
SERVERFILE_IPV6="/var/lib/dhcp/chrony.servers.ipv6.$interface"

reload_config() {
        /usr/lib/chrony/chrony-helper update-daemon || :
}

rebuild_config() {
        for server in $new_ntp_servers; do
                echo "$server iburst" >> "$SERVERFILE"
        done
}

if [ -e /usr/lib/chrony/chrony-helper ]; then
        handle_reason
fi

and

openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 64-timesyncd.conf
# vi: ft=sh

SERVERFILE_IPV4="/run/systemd/timesyncd.conf.d/01-dhcpcd.ipv4.$interface.conf"
SERVERFILE_IPV6="/run/systemd/timesyncd.conf.d/01-dhcpcd.ipv6.$interface.conf"

reload_config() {
        systemctl try-restart systemd-timesyncd.service || :
}

rebuild_config() {
        mkdir -p "$(dirname "$SERVERFILE")"
        cat <<EOF > "$SERVERFILE"
# NTP server entries received from DHCP server
[Time]
NTP=$new_ntp_servers
EOF
}

if [ -d /run/systemd/system ]; then
        handle_reason
fi

and

openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 60-ntp-common.conf
# common functions for separate server config

add_servers() {
        # exit early if there's nothing to do
        if [ "$new_ntp_servers" = "$old_ntp_servers" ]; then
                return
        fi

        rm -f "$SERVERFILE"

        if [ -n "$new_ntp_servers" ]; then
                rebuild_config
        fi

        reload_config
}

remove_servers() {
        local update_required
        if [ -f "$SERVERFILE_IPV4" ]; then
                rm -f "$SERVERFILE_IPV4"
                update_required=1
        fi
        if [ -f "$SERVERFILE_IPV6" ]; then
                rm -f "$SERVERFILE_IPV6"
                update_required=1
        fi
        if [ -n "$update_required" ]; then
                reload_config
        fi
}

handle_reason() {
        case "$reason" in
                BOUND6|RENEW6|REBIND6|REBOOT6|INFORM6)
                        SERVERFILE="$SERVERFILE_IPV6"
                        new_ntp_servers="$new_dhcp6_sntp_servers"
                        old_ntp_servers="$old_dhcp6_sntp_servers"
                        add_servers
                        ;;
                BOUND|RENEW|REBIND|REBOOT)
                        SERVERFILE="$SERVERFILE_IPV4"
                        add_servers
                        ;;
                EXPIRE|FAIL|RELEASE|STOP)
                        remove_servers
                        ;;
        esac
}

# common functions for combined server config

start_mark="# dhcpcd $interface start"
end_mark="# dhcpcd $interface end"

# inserts a server configuration into the SERVERFILE
# takes an optional argument to indicate server options
insert_servers() {
        local tmpfile
        tmpfile=$(mktemp)
        local protocol='IPv4'
        if echo "$reason" | grep -q 6$; then
                protocol='IPv6'
        fi
        # update section for this interface and protocol
        if [ -f "$SERVERFILE" ]; then
                sed "/^$start_mark $protocol/,/^$end_mark $protocol/d" "$SERVERFILE" > "$tmpfile"
        fi
        # clean up and bail early if there's nothing else to do
        if [ -z "$new_ntp_servers" ] && [ ! -s "$tmpfile" ]; then
                rm -f "$SERVERFILE" "$tmpfile"
                return
        fi
        # otherwise update SERVERFILE
        if [ -n "$new_ntp_servers" ]; then
                echo "$start_mark $protocol" >> "$tmpfile"
                for server in $new_ntp_servers; do
                        echo "server $server${1:+ $1}" >> "$tmpfile"
                done
                echo "$end_mark $protocol" >> "$tmpfile"
        fi
        # preserve permissions if possible
        if [ -f "$SERVERFILE" ]; then
                chown --reference="$SERVERFILE" "$tmpfile"
                chmod --reference="$SERVERFILE" "$tmpfile"
        fi
        mv "$tmpfile" "$SERVERFILE"
}

withdraw_servers() {
        if [ ! -f "$SERVERFILE" ]; then
                return
        fi
        local tmpfile
        tmpfile=$(mktemp)
        sed "/^$start_mark/,/^$end_mark/d" "$SERVERFILE" > "$tmpfile"
        # remove the SERVERFILE if there's nothing to put in it
        if [ ! -s "$tmpfile" ]; then
                rm -f "$SERVERFILE" "$tmpfile"
        else
                # otherwise update SERVERFILE
                chown --reference="$SERVERFILE" "$tmpfile"
                chmod --reference="$SERVERFILE" "$tmpfile"
                mv "$tmpfile" "$SERVERFILE"
        fi
}
# vi: ft=sh
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ^C
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ls
01-test  02-dump  10-wpa_supplicant  20-resolv.conf  30-hostname  60-ntp-common.conf  62-chrony.conf  64-timesyncd.conf  66-ntp.conf  68-openntpd.conf
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 62-chrony.conf
# vi: ft=sh

SERVERFILE_IPV4="/var/lib/dhcp/chrony.servers.ipv4.$interface"
SERVERFILE_IPV6="/var/lib/dhcp/chrony.servers.ipv6.$interface"

reload_config() {
        /usr/lib/chrony/chrony-helper update-daemon || :
}

rebuild_config() {
        for server in $new_ntp_servers; do
                echo "$server iburst" >> "$SERVERFILE"
        done
}

if [ -e /usr/lib/chrony/chrony-helper ]; then
        handle_reason
fi
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ^C
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ls
01-test  02-dump  10-wpa_supplicant  20-resolv.conf  30-hostname  60-ntp-common.conf  62-chrony.conf  64-timesyncd.conf  66-ntp.conf  68-openntpd.conf
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 64-timesyncd.conf
# vi: ft=sh

SERVERFILE_IPV4="/run/systemd/timesyncd.conf.d/01-dhcpcd.ipv4.$interface.conf"
SERVERFILE_IPV6="/run/systemd/timesyncd.conf.d/01-dhcpcd.ipv6.$interface.conf"

reload_config() {
        systemctl try-restart systemd-timesyncd.service || :
}

rebuild_config() {
        mkdir -p "$(dirname "$SERVERFILE")"
        cat <<EOF > "$SERVERFILE"
# NTP server entries received from DHCP server
[Time]
NTP=$new_ntp_servers
EOF
}

if [ -d /run/systemd/system ]; then
        handle_reason
fi
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ^C
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ ls
01-test  02-dump  10-wpa_supplicant  20-resolv.conf  30-hostname  60-ntp-common.conf  62-chrony.conf  64-timesyncd.conf  66-ntp.conf  68-openntpd.conf
openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 66-ntp.conf
# vi: ft=sh

SERVERFILE_IPV4="/run/ntp.conf.dhcp"
SERVERFILE_IPV6="$SERVERFILE_IPV4"

add_servers() {
        # exit early if there's nothing to do
        if [ "$new_ntp_servers" = "$old_ntp_servers" ]; then
                return
        fi

        insert_servers iburst
        reload_config
}

remove_servers() {
        SERVERFILE=$SERVERFILE_IPV4

        # exit early if there's nothing to do
        if [ ! -f $SERVERFILE ]; then
                return
        fi

        withdraw_servers
        reload_config
}

reload_config() {
        invoke-rc.d ntp try-restart || :
}

if [ -e /etc/ntp.conf ]; then
        handle_reason
fi

and finally

openhabian@openhabian-test:/lib/dhcpcd/dhcpcd-hooks $ cat 68-openntpd.conf
# vi: ft=sh

SERVERFILE_IPV4="/etc/openntpd/ntpd.conf"
SERVERFILE_IPV6="$SERVERFILE_IPV4"

add_servers() {
        # exit early if there's nothing to do
        if [ "$new_ntp_servers" = "$old_ntp_servers" ]; then
                return
        fi

        insert_servers
        reload_config
}

remove_servers() {
        SERVERFILE=$SERVERFILE_IPV4

        # exit early if there's nothing to do
        if [ ! -f $SERVERFILE ]; then
                return
        fi

        withdraw_servers
        reload_config
}

reload_config() {
        invoke-rc.d openntpd try-restart || :
}

if [ -d /etc/openntpd ]; then
        handle_reason
fi

The different NTP related files may not have anything to do with the problem. I have another installation at another location that has the same problem with systemd-timesyncd failing, and it has the same files as the treat installation, so it probably has to do with the vintage of the install.

I was trying to find some difference to investigate. I’m out of ideas.

@mstormi
I can confirm that after several more days, on the test unit with the revised code, systemd-timesyncd is running, and there are no failed services on the unit.

My productions unit continue to have the problem where systemd-timesyncd fails due to excess start attempts.

What are the next steps in troubleshooting this?

Thanks for all of your help.

George

1 Like

What do you mean by ‘revised’, how does that differ from latest openHABian ?

When a stock openHABian install works you could simply import your OH config there and replace your production unit with it.

Same for me, but no idea for now, sorry.

Now that you are on a test system, did you follow the
instructions above?

Revised is the image I built with your helpful guidance that disables the setup_ntp function in the system.bash file. systemd-timesyncd behaves as expected on this one, unlike the stock openHABian installs where it fails.

I have two stock openHABian installs at differenct locations. Both of them have the problem where systemd-timesyncd fails due to excess starts.

I am trying to do as discussed

1 Like

So you just disabled what setup_ntp() did and that did the trick ?

Is there any sort of ntp daemon running ? Does your test box keep synchronizing to an ntp server ?

If so, sounds like there is a working ntp daemon in place in Raspi OS and setup_ntp() resulted in creation of another one. So omiting that would be the right fix.
It would at least explain what we have been observing.
We would need to validate that, though, before applying it to the the openHABian code base.

Could you put that up as a PR ? Remove calling setup_ntp() from openhabian-setup.sh and functions/menu.bash, too, and remove the routine from system.bash, of course.

Yes. I just commented out the setup_ntp section the system.bash file.

Yes:

openhabian@openhabian-test:~ $ timedatectl
               Local time: Sat 2023-05-13 11:31:28 CDT
           Universal time: Sat 2023-05-13 16:31:28 UTC
                 RTC time: n/a
                Time zone: America/Chicago (CDT, -0500)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
openhabian@openhabian-test:~ $ 

If I can be for further assistance, please let me know.

Hopefully (once verified by people who know what they are doing), this will resolve the issue for future installs. I’m guessing for existing installs that it will be necessary to start over with a clean install of openhabian to which backed up openhab configuration is restored, as we don’t know where the conflict is and it would be more trouble than it is worth to try and fix an existing install.

1 Like