NTP / time settings


13 posts
by colt_cc » Thu Aug 30, 2012 8:01 pm
Hi all. First post. I'm using wheezy. My pi lives in a rural location that is subject to frequent short power outages. When the the pi powers back up, it does so quicker than my router can re-acquire its internet connection. So when it tries to update its time from an NTP server it fails because it has no internet access. I believe that's what is causing some mysterious time inaccuracies on my pi. (It's not off by an integral number of hours so the time zone isn't the problem.)

Can anyone point me towards a way to have the pi keep trying a bit harder for a bit longer to get a proper time? (Yes, I know I should just get a decent UPS or something...)

Or is there a place where detailed NTP logs are saved so I can try to dig a little deeper?

Many thanks
Posts: 2
Joined: Thu Aug 30, 2012 7:51 pm
by Left_Guard » Sun Sep 02, 2012 8:37 am
I have the same problem.
My Pi is powered from a USB socket on the back of my modem and boots up much faster, if the modem restarts for any reason, and, as a result, my system time is well out from what it should be.
I'll post back, if I find a solution.
Posts: 3
Joined: Sun Sep 02, 2012 8:33 am
by Left_Guard » Sun Sep 02, 2012 2:34 pm
I (think) it's mission accomplished.

Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/questions/266/how-can-i-keep-system-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.

I'm using Raspbian (Wheezy), meaning NTP is already installed, so I used
Code: Select all
sudo nano /etc/rc.conf
to create a file into which I put the line
Code: Select all
DAEMONS=(!hwclock ntpd)
.
After
Code: Select all
sudo reboot
the date was correct, but the time was one hour slow, so I then used
Code: Select all
sudo ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
which, after another dose of
Code: Select all
sudo reboot
, got the time in line with my local UK time.
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.

That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.

If anyone with more experience than myself knows an easier way, of course....
Posts: 3
Joined: Sun Sep 02, 2012 8:33 am
by colt_cc » Sun Sep 02, 2012 2:45 pm
Great, thanks for that, I will experiment. I was on the verge of running (as a cron job on reboot) a script to wait a while (to give the router time to come up) and then try NTP. Your solution looks like much less of a botch! Thanks
Posts: 2
Joined: Thu Aug 30, 2012 7:51 pm
by Oric Tosh » Sun Sep 02, 2012 10:00 pm
Hi,
I'm also using Raspbian (Wheezy)
The way I have setup my NTP time server for the Raspi to keep correct time was to edit this file
/etc/ntp.conf

Remove the hash(#) from the line below *You need to talk to an NTP server or two (or three)*
type the URL of the time server in front of server. such as ntp.timeserver.com

I also setup a rc.conf file the same as you have but found some more information on how to make it run faster, add ntpdate so your file looks this:
DAEMONS=(!hwclock ntpd ntpdate)

Source: http://raspberrypi.stackexchange.com/qu ... ystem-time

Hope that's useful
Posts: 3
Joined: Fri Aug 31, 2012 6:46 pm
by Left_Guard » Mon Sep 03, 2012 10:41 am
Okay.
Watch this space. More to come, because....

Logged into my Pi today, to find the time two hours slow again!
Modem must have rebooted overnight, for some reason, (Note to self: Get a new modem. This one started randomly rebooting two weeks ago and you've no idea why) and the Pi hasn't got the right local time now.
Hey, ho. Back to work on it.
Posts: 3
Joined: Sun Sep 02, 2012 8:33 am
by shaun5 » Tue Oct 16, 2012 6:40 pm
I can not get the system time to update. Do I need to make rc.conf executable? I thought ntpd -gq would update the time, but it doesn't seem to be working either.
Posts: 3
Joined: Wed Oct 03, 2012 6:40 pm
by W. H. Heydt » Tue Oct 16, 2012 7:48 pm
If you have power issues...whether it's sags and surges or outages (brief or otherwise), or even if you think your power is reliable...

Get an Uninteruptable Power Supply (UPS). Put not only your Pi and PC on it, but you networking equipment (modem, router, switches, etc.) on it as well. If you can't get everything on one UPS, get however many you need. If you want to isolate your network gear, get small UPS (<500VA) for the network and a larger one for other equipment.

Doing this will save you much grief in the long run...and not just with the Pi. There will be less wear and tear on your electronics, you won't lose work because your machine dropped, you won't be rebuilding corrupted SD cards, you'll be able to ignore brief power interruptions, and you'll be able to do an orderly shutdown in longer interruptions.

Just to give a concrete example from a few years ago... I was running convention registration when the power went out in the hotel we were using for the con. I had my crew process the registrations they were already working on and then we did a controlled shutdown of 4 PCs, two impact printers, and a Linux server, plus the associated network bits that tied it all together ....all because it was all running on two 1.5KVA UPS'. The power was out for about 3 hours. When we got power back, everything came back up smoothly with no glitches and no file corruption.

You never know when or where you'll have a power outage.
Posts: 1641
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)
by blades » Tue Nov 13, 2012 1:14 pm
Left_Guard wrote:I (think) it's mission accomplished.

Having searched for information and having followed links to
http://raspberrypi.stackexchange.com/questions/266/how-can-i-keep-system-time
and
http://www.wikihow.com/Change-the-Timezone-in-Linux
this is how I did it.

I'm using Raspbian (Wheezy), meaning NTP is already installed, so I used
Code: Select all
sudo nano /etc/rc.conf
to create a file into which I put the line
Code: Select all
DAEMONS=(!hwclock ntpd)
.
After
Code: Select all
sudo reboot
the date was correct, but the time was one hour slow, so I then used
Code: Select all
sudo ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
which, after another dose of
Code: Select all
sudo reboot
, got the time in line with my local UK time.
Anyone not in the UK would have to search through /usr/share/zoneinfo's subdirectories to find the most appropriate location to change to symbolic link target to.

That's what seems to have worked for me.
I hope it works for you and anyone else who tries it.

If anyone with more experience than myself knows an easier way, of course....

I was looking for ages for a workaround about the non real clock Pi and it seems your post gave real time to my Pi.Thanx a lot.
Posts: 8
Joined: Wed Oct 10, 2012 8:21 am
by f0rd0prefect » Fri May 17, 2013 12:09 pm
Hi,
I'm wondering about the successful settings.
AFAIK, Debian has not a rc.conf.
AFAIK you mix up two distros: Debian (SysV style init process) and Arch (BSD style init process). Wikipedia has a brief explanation here: http://en.wikipedia.org/wiki/Init.
Greetings
Herbert
Posts: 1
Joined: Fri May 17, 2013 11:58 am
by really » Mon Nov 11, 2013 4:19 am
So , I guess I'm not the only one who had to tackle this problem...
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?

Thanks
Posts: 2
Joined: Mon Nov 11, 2013 4:09 am
by DougieLawson » Tue Nov 12, 2013 12:55 am
really wrote:So , I guess I'm not the only one who had to tackle this problem...
but I still haven't solved the problem
my PI is always 36 days behind,
I dont know why, I dont want to re-install it , again,
my Timezone is correct,
I want my PI to check the network time at boot, and adjust it's clock accordingly....
can one of you ( with NTP success ) post me the content of ntp.conf, because I can't see where is the problem with my PI
or is there a command to force ntp daemon to adjust time?

Thanks


NTP won't normally reset the clock if it's off by more than 1000s.

If you run 'ntpd -gq' it ignores the clock being way adrift from ntp time and will force it to be correct then close. The old ntpdate program does the same thing.

You need an active Internet connection to run NTP.

My ntp.conf (on my RPi blank lines and comments removed)
Code: Select all
driftfile /var/lib/ntp/ntp.drift
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
server 0.debian.pool.ntp.org iburst
server 1.debian.pool.ntp.org iburst
server 2.debian.pool.ntp.org iburst
server 3.debian.pool.ntp.org iburst
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
Hacker on ZX80, Microtan65, Raspberry Pis and Arduinos
Unemployed mainframe database troubleshooter
RPi owner since 2012.
Twitter: @DougieLawson

Gaffer tape is "The Force", it has a dark side and a light side and it holds the Universe together.
User avatar
Posts: 7101
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by really » Tue Nov 12, 2013 3:28 am
Thanks it really helped,

turns out , the 1000s was the culprit....
Thanks again, I been cranking on this for hours...
Posts: 2
Joined: Mon Nov 11, 2013 4:09 am