Artix Linux Forum

Artix Linux => Applications & Software => Topic started by: pluto on 27 August 2022, 04:40:50

Title: No way to sync/set correct time [OpenRC]
Post by: pluto on 27 August 2022, 04:40:50
Hey,

i just build a new pc of used parts just for fun.

Installed artix openrc base with kde totaly barebone.

I woundered, why this is my Time:

Code: [Select]
[user@mediapc ~]$ date
Sa 27. Aug 05:42:08 CEST 2022
[user@mediapc ~]$

its totaly wrong.

Timezone is:

Code: [Select]
[user@mediapc ~]$ ls -l /etc/localtime 
lrwxrwxrwx 1 root root 33 27. Aug 05:21 /etc/localtime -> /usr/share/zoneinfo/Europe/Berlin
[user@mediapc ~]$

So i wanted to fix that and followed https://wiki.archlinux.org/title/System_time#Time_synchronization

I choosed https://wiki.archlinux.org/title/OpenNTPD because that package is in the artix repos.

But this dont work:

Code: [Select]
[mediapc user]# ntpd -d
/var/db/ntpd.drift is empty
ntp engine ready
peer 194.36.144.87 now valid
peer 185.232.69.65 now valid
peer 45.9.61.155 now valid
peer 79.133.44.139 now valid
adjusting local clock by -4061.675931s
adjusting local clock by -4061.645494s
adjusting local clock by -4061.517764s
adjusting local clock by -4061.487612s

Code: [Select]
[user@mediapc ~]$ date
Sa 27. Aug 05:44:42 CEST 2022
[user@mediapc ~]$

it should be:
Code: [Select]
[user@polis ~]$ sudo ntpd -d
/var/db/ntpd.drift is empty
ntp engine ready
peer 178.63.9.212 now valid
peer 79.133.44.140 now valid
peer 185.104.163.42 now valid
peer 5.145.135.89 now valid
adjusting local clock by 5.236196s
adjusting local clock by 5.207103s
adjusting local clock by 5.210619s

Code: [Select]
[user@polis ~]$ date
Sa 27. Aug 04:40:35 CEST 2022
[user@polis ~]$



Edit:

/etc/ntpd.conf on both machines:

Code: [Select]
# $OpenBSD: ntpd.conf,v 1.16 2019/11/06 19:04:12 deraadt Exp $
#
# See ntpd.conf(5) and /etc/examples/ntpd.conf
#
#servers 2.arch.pool.ntp.org
#server time.cloudflare.com
#sensor *

#constraint from "9.9.9.9"              # quad9 v4 without DNS
#constraint from "2620:fe::fe"          # quad9 v6 without DNS
#constraints from "www.google.com"      # intentionally not 8.8.8.8
#server 0.fr.pool.ntp.org iburst
#server 1.fr.pool.ntp.org iburst
#server 2.fr.pool.ntp.org iburst
#server 3.fr.pool.ntp.org iburst
server 0.de.pool.ntp.org
server 1.de.pool.ntp.org
server 2.de.pool.ntp.org
server 3.de.pool.ntp.org

"Fun Fact" if i change time manualy (like 12:49, what is totaly wrong), and then run ntpd -d, it shows me thousands of secounds wich he adjusted, but date shows still the wrong time. On both Machines.

Edit2:

Example:

Code: [Select]
[user@polis ~]$ date
Sa 27. Aug 21:47:54 CEST 2022
[user@polis ~]$

Code: [Select]
[user@polis ~]$ sudo ntpd -d
doas (user@polis) password:
/var/db/ntpd.drift is empty
ntp engine ready
peer 131.188.3.222 now valid
peer 162.159.200.1 now valid
peer 185.197.135.21 now valid
peer 185.183.159.238 now valid
adjusting local clock by -61191.020144s

Code: [Select]
[user@polis ~]$ date
Sa 27. Aug 21:48:53 CEST 2022
[user@polis ~]$

Edit3:

Installed Artix on a VM for testing.

This time i  followed https://wiki.archlinux.org/title/Network_Time_Protocol_daemon#Synchronize_time_once_per_boot

Its says it adjust, but didnt work/still wrong time is used/set.

Edit4:

Cloned my VM few times, and tried other Methods. No method mentioned on the wiki works.

Tried the same with a Arch install. There it works without any problem. Even if i set a HUGE (23 hours +) difference. After a reboot, or ntpd restart, time gets synced to correct value.

Dont know if openrc is the problem? cant imagine...
Title: Re: No way to sync/set correct time [OpenRC]
Post by: tintin on 27 August 2022, 06:37:41
Is the time set correctly in the bios?
Title: Re: No way to sync/set correct time [OpenRC]
Post by: pluto on 27 August 2022, 14:14:57
Quote
Is the time set correctly in the bios?

No.

OpenRC seems not to be the problem.

Tried with my Gentoo install. There ntp works like it should.

Edit:

For now i created a workaround for my 3 Artix machines:

Code: [Select]
#!/bin/bash
#get current timestamp from a source outside this machine
timestamp=$(curl -s https://current-timestamp.com/ | grep "<tr><td>Timestamp</td><td>" | sed 's/[^0-9]*//g')

#set the timestamp
sudo date -s @$(echo $timestamp)
Title: Re: No way to sync/set correct time [OpenRC]
Post by: tintin on 27 August 2022, 16:21:31
Great if your solution works.

However, although you probably know:
If the time offset is too high NTP will not change it.
https://forum.artixlinux.org/index.php/topic,647.0.html
Title: Re: No way to sync/set correct time [OpenRC]
Post by: pluto on 27 August 2022, 16:51:40
Quote
However, although you probably know:
If the time offset is too high NTP will not change it.

Interesting. ntpd -gq indeed force a update to correct time.

Never saw this kind of problem. Maybe systemd have a routine or something to make this work without first need to be adjusted by user?

Last time i changed date/time in bios is decades ago lol




Title: Re: No way to sync/set correct time [OpenRC]
Post by: tintin on 27 August 2022, 17:10:43
Last time i changed date/time in bios is decades ago lol
:)

Quote
"to protect against broken hardware, such as when the CMOS battery fails or the clock counter becomes defective, once the clock has been set, an error greater than 1000s will cause ntpd to exit anyway."
https://linux.die.net/man/8/ntpd