D-Link Forums

The Graveyard - Products No Longer Supported => D-Link Storage => DNS-323 => Topic started by: jamieburchell on October 01, 2010, 09:42:10 AM

Title: Correct time during DST
Post by: jamieburchell on October 01, 2010, 09:42:10 AM
Is there any way I can get the correct time during BST without entering the start and end dates?

This is the only system I've owned this decade that doesn't do it automatically ;)

If I set the time manually, it reverts to -1 hour after a reboot.

If I select GMT and enable the time server, it's still an hour out.

Also, what needs to be entered in the DST boxes?

    2010    2011    2012
Clocks go forward   28 March   27 March   25 March
Clocks go back   31 October   30 October   28 October
Title: Re: Correct time during BST
Post by: scaramanga on October 01, 2010, 10:26:30 AM
Is there any way I can get the correct time during BST without entering the start and end dates?
I'm afraid not. It's not like a standard linux system where all time-zone settings are in /usr/share/zoneinfo and you just need to choose. In the DNS-323's case, it's all hard-coded in /sys/crfs/web_page/tools/timezone.asp. Seems like bad craftsmanship to me.

This is the only system I've owned this decade that doesn't do it automatically ;)
They all need an update from time to time. It's technically possible that such an update would be available for the DNS-323 with a firmware update. How likely is that is anybody's guess.

If I set the time manually, it reverts to -1 hour after a reboot.
Although it's manual, it works for me.

If I select GMT and enable the time server, it's still an hour out.
Did you set the start/end date accordingly?

Also, what needs to be entered in the DST boxes?

    2010    2011    2012
Clocks go forward   28 March   27 March   25 March
Clocks go back   31 October   30 October   28 October
Instead of thinking in clock goes forward/back, see here when DST starts/ends: http://www.timeanddate.com/worldclock/city.html?n=136 (http://www.timeanddate.com/worldclock/city.html?n=136)
You'll have to update that value once a year.
Title: Re: Correct time during BST
Post by: chriso on October 01, 2010, 02:16:38 PM
I have always found the automatic time setting for the DNS-323 to be off by any hour.  I could set it manually, but not automatically.

What I do is set it using fun_plug (I'm actually using ffp and set it in fun_plug.local), but it would work in any fun_plug script.

   # Fix time zone information.
echo "Fixed /etc/TZ file"
echo "PST8PDT,M3.2.0,M11.1.0" > /etc/TZ

Title: Re: Correct time during BST
Post by: jamieburchell on October 01, 2010, 02:57:49 PM
Thanks for the response guys.

chriso, what does the second line of that command actually do?

And can I use something similar to resolve my issue?

Cheers
Title: Re: Correct time during BST
Post by: jamieburchell on October 01, 2010, 03:12:47 PM
Did you set the start/end date accordingly?

No, I was hoping that it would be smart enough to know we were in BST and set it to the correct time.

So for start/end for 2010 do I put...

03/28
10/31

?
Title: Re: Correct time during BST
Post by: scaramanga on October 01, 2010, 03:31:44 PM
?
Pretty much, yes. That "should" do it. Till 2011's day light saving time kicks in, that is.
Title: Re: Correct time during BST
Post by: scaramanga on October 01, 2010, 03:39:31 PM
chriso, what does the second line of that command actually do?
It overwrites the time zone file with a new value.

And can I use something similar to resolve my issue?
Sure you can. You'll need to learn that time-zone cryptic syntax first. You can read about it here: http://linux.die.net/man/3/tzset (http://linux.die.net/man/3/tzset). chriso's example used the second format.
Title: Re: Correct time during BST
Post by: jamieburchell on October 01, 2010, 03:44:43 PM
I'm confused what the difference is between selecting the timezone from the drop-down in the interface, and setting it with this command?

All I want to achieve is the correct time on my NAS automatically all year round :)

I can use fun_plug commands if it will help.

Suggestions?
Title: Re: Correct time during BST
Post by: lookingforinfo on October 01, 2010, 06:41:31 PM
I experienced the same problem today.  I think I failed to review the time settings after resetting the unit to Factory Default Settings.  Earlier I enabled NTP Server: and told it to use ntp1.dlink.com.  After reading these comments I, rebooted the 323 and the time is being reported correctly.  System is at FW 1.08.
Title: Re: Correct time during BST
Post by: chriso on October 01, 2010, 09:53:37 PM
The reason that time on the DNS-323 is wrong is because it is being handled fundamentally wrong.   Also most anything you image to do wrong with time the DNS-323 does it.

First off the way time settings on a Unix/Linux box are suppose to be done is that what is set in the /etc/TZ file is the name of the timezone, which is then looked up in the /usr/share/timezone database to find the exact rules of when to have daylight saving time or not.  Problem is there is no /usr/share/timezone database on the DNS-323, so they resort to a syntax like: GMT+8.  The problem with this is that it relies on the rule compiled into the OS, but they the rules can change and have just recently (a couple years ago for lots of parts of the world).  So the DNS-323 changes to/from daylight saving time on the wrong dates/time.

The people at D-Link figured they will put in the date boxes for which date you should change on.  There is a few problems with this, but the main problem is that is not what the rules of daylight saving time says.  It isn't a date, it is stated as the first Sunday in X month and ending in the last Sunday of Y month.  So if you set a date that is correct for this year you are guaranteed to be wrong for next year.
The other thing that could be wrong is the time of day to change.  Most use 2 am, but it doesn't have to be.

Some might think that turning on the NTP Server that it would fix the problem.  Not so.  The purpose of the NTP server is to go out to the server and ask it the time and set the system time using it, but this was meant to correct being off by a few seconds (to correct for drifting clocks, which the DNS-323 has).  If your time is off by an hour, the method it uses to sync would take days, but most likely actually it will just give up because it is to far off.  It uses this slow correction because changing the time around quickly can confuse programs that depending on reading the time and doing something.  Another thing to realize is that the NTP servers can be on the other side of the world so they don't know what timezone or if you are suppose to be in daylight time or not.  It is up to the computer to be setup correctly to know these things.  The NTP always just reports GMT with no daylight saving time.

Luckily there is an extended format for the entry in /etc/TZ that allows you to tell the system the correct rules.
In the case of US Pacific time that entry is:
PST8PDT,M3.2.0,M11.1.0

This is read. PST (abbreviation for Pacific Standard Time), 8 the number of hours from GMT, which can be 0 or negative, I know of no syntax for those weird countries that choose to have a 1/2 hour timezone, PDT (abbreviation for Pacific Daylight Time), the "M" entries give the starting/ending month.week.day.
Month is what you expect.  January is 1, February is 2, ... So the first month in mine is March.
Next comes the week.  This is week 1, week 2, ... (up to 5 since you can have a 5th week in a month).  So for my first entry has it changing on the second week in March.  The last is the day.  The days are Sunday which is 0, Monday 1, ...  So my entry is on the Sunday of the second week of March change.  So the ending date reads On the Sunday of the first week November change back.  There is also a format for the time of day to change, the default is 2 am, which the US uses so I didn't include it, but you can see it used below in the BST example.

What is it for BST?  This timezone changes at 1 am, and time would be given with the /1
I grabbed the following rules from this link:
http://wwp.britishsummertime.co.uk/
    *  Starts: Last Sunday in March
    * End: Last Sunday in October
    * Time: 1.00 am (01:00) Greenwich Mean Time (GMT)

BST0BDT,M3.5.0/1,M10.5.0/1

NOTES:
   * I don't live in BST timezone so this example is just going by the rules not my personal experience that it changes when people expect.
    * But the for my timezone listed above (Pacific) I have lived with this setting for about 2 1/2 years and my time is always correct.
    * I notice that the DNS-323 will not allow you to set the "Daylight Savings" flag without filling in the dates.  Well the setting in the /etc/TZ is doing overrides this and even the first setting that picks the timezone, so it doesn't matter what it is set to.  You do want to set the timezone right just so on the DNS-323 GUI is shows it right.
   * If you change the timezone/Daylight/Dates it will override what is in the TZ file until you reboot and the fun_plug script changes it back.
   * This link has a good explanation of the /etc/TZ format: http://www.gnu.org/s/libc/manual/html_node/TZ-Variable.html
    * I have had problems with the built in NTP server not syncing some times, and have switched to running it through the ntpd.sh script in the ffp scripts.  That allows me to tweak it for starting it in "burst" mode, using backup servers, and retrying on errors.  But this is only good information if you are using the ffp fun_plug scripts.
Title: Re: Correct time during BST
Post by: jamieburchell on October 02, 2010, 02:08:50 AM
Wow. Thank you for taking the time to explain that so well. I've definitely learned from your post and am happy to say the command is working!
Title: Re: Correct time during BST
Post by: affinity on October 05, 2010, 10:14:01 AM
The reason that time on the DNS-323 is wrong is because it is being handled fundamentally wrong.   Also most anything you image to do wrong with time the DNS-323 does it.
Fantastic explanation, thank you very much.

Now here in Melbourne, we have "early" daylight savings and that is causing me havoc with jobs scheduled with "at" -- the web gui time is an hour out, but with my new /etc/TZ file, date in a putty session now gives the right time!  I've scripted getting current time via "ssh $server /bin/date" previously as a work around.

Anyway, with this new TZ file [shown below if anyone else in Melbourne, AU needs it] ... am I going to be past the problems of the at scheduler?  Or will it still cause more hassle?

Thanks again.
AndrewM

Melbourne, VIC, AU /etc/TZ file:
Code: [Select]
EST-10EST,M10.1.0,M4.1.0/3
btw I actually got that string from a Debian box using the following:
Code: [Select]
tail -1 /etc/localtime
Title: Re: Correct time during BST
Post by: barryware on October 05, 2010, 10:23:34 AM
Just chiming in to say that the DST setup having to specify the dates is silly.

In the US.. dst starts the 2nd sunday of march and ends the 1st sunday of november. Sunday dates change from year to year.

dd-wrt (open source linux router firmware).. that is how you select dst.. days of the week & months.. not dates.
Title: Re: Correct time during BST
Post by: gunrunnerjohn on October 05, 2010, 11:12:59 AM
Most other Linux based products have no problem with DST calculations.  This is just one of a number of oddities and poor design decisions in the D-Link NAS boxes.
Title: Re: Correct time during BST
Post by: affinity on October 05, 2010, 05:34:20 PM
:(

Still got "at" scheduler issues, jobs re-spawning ... it's driving me nuts atm.
Title: Re: Correct time during BST
Post by: chriso on October 06, 2010, 12:14:25 AM
I would point out that there is no substitute for actual support.  It doesn't matter if you are talking about compiled in rules in the OS or the timezone database or the TZ file (Or the Java database for time for that matter).  Countries change their timezones all the time, and the only way for them to be correct is that whatever time data/rules are being used is updated.  With an OS like Unix/Linux/Windows you are getting a constant set of updates.  And so these daylight saving times rules are just part of that.  If you kept your Windows/Linux/Unix box off the Internet or didn't allow any updates they would be wrong when your country changed its rules they would be wrong too.

No magic here.
Title: Re: Correct time during BST
Post by: jamieburchell on November 16, 2010, 02:12:10 PM
Code: [Select]
echo "BST0BDT,M3.5.0/1,M10.5.0/1" > /etc/TZ
Although the above has correctly set my time, I've noticed the NAS is still reporting the zone to be BST and not GMT now we are out of BST. Not critical, but how can this be fixed?
Title: Re: Correct time during BST
Post by: dosborne on November 16, 2010, 05:15:51 PM
My understanding is that string should produce a TZ of BST or BDT depending on the date.
Title: Re: Correct time during BST
Post by: chriso on November 17, 2010, 01:04:01 AM
I found out that along with the problem of /etc/TZ needing to be set there are a few of programs that run from cron that mess up the correct time too.

Here is my corrections, if you use it make sure you use the right setting for your location for /etc/TZ
   # Fix time zone information.
crontab -l | grep -vi rtc | grep -vi stime | grep -vi daylight > /tmp/cron.tmp
crontab /tmp/cron.tmp
echo "PST8PDT,M3.2.0,M11.1.0" > /etc/TZ
echo "Fixed /etc/TZ file"
Title: Re: Correct time during BST
Post by: lookingforinfo on November 17, 2010, 12:37:37 PM
I am sorry if this question is too basic, but it is related to having the 323 use the correct time.

As I said previously, I have enabled NTP server but have not advanced to using ffp.  Initially this seemed to work.  It now appears that the unit only checks the NTP server when I select "Save Settings" on the TOOLS page.  Having super accurate time is not essential, however I would like to confirm what must be done to keep the time generally correct.  I had previously thought the time check might occur after a sleep period.
Title: Re: Correct time during BST
Post by: chriso on November 17, 2010, 04:02:55 PM
Code: [Select]
echo "BST0BDT,M3.5.0/1,M10.5.0/1" > /etc/TZ
Although the above has correctly set my time, I've noticed the NAS is still reporting the zone to be BST and not GMT now we are out of BST. Not critical, but how can this be fixed?

You are in BST, which happens to be GMT, what you came out of was BDT (daylight savings time ended).  If you don't like it saying BST then use:
Code: [Select]
echo "GMT0BDT,M3.5.0/1,M10.5.0/1" > /etc/TZ
Title: Re: Correct time during BST
Post by: chriso on November 17, 2010, 04:15:05 PM
I am sorry if this question is too basic, but it is related to having the 323 use the correct time.

As I said previously, I have enabled NTP server but have not advanced to using ffp.  Initially this seemed to work.  It now appears that the unit only checks the NTP server when I select "Save Settings" on the TOOLS page.  Having super accurate time is not essential, however I would like to confirm what must be done to keep the time generally correct.  I had previously thought the time check might occur after a sleep period.

What you are seeing is basically what I have seen too.  I dumped the built in for the one in ffp, and even tweaked it a bit.  Where is my ffp/start/ntpd.sh
Code: [Select]
#!/ffp/bin/sh

# PROVIDE: ntpd
# REQUIRE: SERVERS
# BEFORE: LOGIN

. /ffp/etc/ffp.subr

name="ntpd"
command="/ffp/bin/ntpd"
ntpd_flags="-g -f /ffp/etc/ntp.drift"
required_files="/ffp/etc/ntp.conf"
start_cmd="ntpd_start"

ntpd_start()
{
# fix /etc/services
if ! grep -w ntp /etc/services >/dev/null; then
echo "ntp 123/udp" >>/etc/services
fi

# remove rtc and daylight cron jobs
crontab -l | grep -vw '/usr/sbin/daylight' | grep -vw '/usr/sbin/rtc' | crontab -

# Make sure the system clock is correct at start up.
ntpdate -b -u 0.us.pool.ntp.org
if [ $? -ne 0 ] ; then
echo "Sleeping 10 seconds"
sleep 10
ntpdate -b -u 0.us.pool.ntp.org
fi

proc_start $command           
}

run_rc_command "$1"

And my ffp/etc/ntp.conf (This will be different if you are not in the US).
Code: [Select]
# US time servers, iburst to speed up synchronization on startup
#server us.pool.ntp.org iburst
server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server 3.us.pool.ntp.org

# drift file path is passed on command line in ntpd.sh (-f)
# driftfile /etc/ntp.drift

# add local clock with stratum 10 as last resort
server 127.127.1.0
fudge  127.127.1.0 stratum 10

# detailed logging
#logconfig =all
Title: Re: Correct time during BST
Post by: lookingforinfo on November 17, 2010, 07:34:44 PM
Thank you for the additional information and confirmation.  At the current point in time I am trying to make my life more simple and would like to not utilize ffp, if at all possible.

I doubt that this will be fixed by D-Link, but do hope others will recognize the limitations when they enable NTP server.
Title: Re: Correct time during BST
Post by: jamieburchell on November 18, 2010, 03:33:51 AM
You are in BST, which happens to be GMT, what you came out of was BDT (daylight savings time ended).  If you don't like it saying BST then use:
Code: [Select]
echo "GMT0BDT,M3.5.0/1,M10.5.0/1" > /etc/TZ

My understanding is that BST = British Summer Time. It's clear to see from looking out of the window it's not summer anymore :)

Never heard of "BDT" before.

GMT = Greenwich Mean Time. Greenwich is in the UK.
Title: Re: Correct time during BST
Post by: chriso on November 18, 2010, 04:52:31 PM
BST if it follows the rest of the world is British Standard Time, and BDT is British Daylight Time.
For instance my time Pacific Standard Time (PST), and Pacific Daylight Time (PDT).

But like I said if you want some other three letter abbreviations feel free to use them.
Title: Re: Correct time during BST
Post by: dosborne on November 18, 2010, 05:57:29 PM
BST if it follows the rest of the world is British Standard Time, and BDT is British Daylight Time.
It does not. BST is British Summer Time. The compliment is GMT, Greenwich Mean Time. BST = GMT+1

British Standard Time was an expirement in the '60s where the time was advanced an hour all year long and was discontinued after a couple of years.
Title: Re: Correct time during BST
Post by: chriso on November 18, 2010, 10:17:45 PM
Sounds like you want
Code: [Select]
echo "GMT0BST,M3.5.0/1,M10.5.0/1" > /etc/TZ
Title: Re: Correct time during BST
Post by: jamieburchell on November 19, 2010, 02:38:40 PM
Sounds like you want
Code: [Select]
echo "GMT0BST,M3.5.0/1,M10.5.0/1" > /etc/TZ

Thanks chriso, that's perfect.
Title: Re: Correct time during BST
Post by: jamieburchell on March 29, 2011, 01:29:28 AM
Something's still not right here. We've just entered BST as of Sunday, but my NAS's time didn't move an hour forward. So I changed it manually. This morning I've checked and the time has gone back an hour again.

I've got a cron job that runs every few hours, and it spits out the current time, looking at it - something's amiss when you consider the flicking between UTC, GMT and BST:

Checking SMART status on SDA at Sat Mar 26 08:00:01 UTC 2011...
Checking SMART status on SDB at Sat Mar 26 08:00:06 UTC 2011...
Checking SMART status on SDA at Sat Mar 26 14:00:01 GMT 2011...
Checking SMART status on SDB at Sat Mar 26 14:01:03 GMT 2011...
Checking SMART status on SDA at Sat Mar 26 20:00:01 GMT 2011...
Checking SMART status on SDB at Sat Mar 26 20:00:06 GMT 2011...
Checking SMART status on SDA at Sun Mar 27 02:00:00 BST 2011...
Checking SMART status on SDB at Sun Mar 27 02:00:05 BST 2011...
Checking SMART status on SDA at Sun Mar 27 08:00:01 BST 2011...
Checking SMART status on SDB at Sun Mar 27 08:00:06 BST 2011...
Checking SMART status on SDA at Sun Mar 27 14:00:00 BST 2011...
Checking SMART status on SDB at Sun Mar 27 14:00:05 BST 2011...
Checking SMART status on SDA at Sun Mar 27 20:00:01 BST 2011...
Checking SMART status on SDB at Sun Mar 27 20:00:06 BST 2011...
Checking SMART status on SDA at Mon Mar 28 02:00:01 UTC 2011...
Checking SMART status on SDB at Mon Mar 28 02:00:06 UTC 2011...
Checking SMART status on SDA at Mon Mar 28 08:00:01 UTC 2011...
Checking SMART status on SDB at Mon Mar 28 08:00:06 UTC 2011...
Checking SMART status on SDA at Mon Mar 28 14:00:00 GMT 2011...
Checking SMART status on SDB at Mon Mar 28 14:00:05 GMT 2011...
Checking SMART status on SDA at Mon Mar 28 20:00:01 GMT 2011...
Checking SMART status on SDB at Mon Mar 28 20:00:06 GMT 2011...
Checking SMART status on SDA at Tue Mar 29 02:00:01 GMT 2011...
Checking SMART status on SDB at Tue Mar 29 02:00:06 GMT 2011...
Checking SMART status on SDA at Tue Mar 29 08:00:01 GMT 2011...
Checking SMART status on SDB at Tue Mar 29 08:00:06 GMT 2011...
Title: Re: Correct time during BST
Post by: chriso on March 29, 2011, 05:03:11 PM
With your logs and such what is happening is that some thing (or things) are resetting your time.
Do you have the NTP server enabled on the DNS-323?  The first thing is to make sure it is off, but that might not be enough and if you don't have another NTP server on it might drift with time.

As a test I just put echo "GMT0BST,M3.5.0/1,M10.5.0/1" > /etc/TZ
Into my DNS-323 and got the right time for BST.

This should be case for any time zone, you should be able to switch the /etc/TZ entry and it switches to the right time.  The reason is because the real time should be stored and maintained as GMT time in the system clock no matter where you are in the world or whether it is daylight savings time or not.  The /etc/TZ just tells it what to display as the time you want to see.

Since I found the whole time setup to be wrong on the DNS-323 I have done the following:
1) Disable NTP Server on DNS-323
2) At start up from in ffp/etc/fun_plug.local  :
Code: [Select]
   # Fix time zone information.
   # remove rtc and daylight cron jobs
crontab -l | grep -vi rtc | grep -vi stime | grep -vi daylight | crontab -
echo "PST8PDT,M3.2.0,M11.1.0" > /etc/TZ
echo "Fixed /etc/TZ file"

Basically kill anything that the DNS-323 does to change the time and then set the correct TZ value.

And then I go on to run a good NTP server from ffp, with my own tweak to make sure it sets to the right time on boot (and I notice I  remove the programs above from the crontab here again, most likely not needed in both places).

ffp/start/ntpd.sh
Code: [Select]
#!/ffp/bin/sh

# PROVIDE: ntpd
# REQUIRE: SERVERS
# BEFORE: LOGIN

. /ffp/etc/ffp.subr

name="ntpd"
command="/ffp/bin/ntpd"
ntpd_flags="-g -f /ffp/etc/ntp.drift"
required_files="/ffp/etc/ntp.conf"
start_cmd="ntpd_start"

ntpd_start()
{
# fix /etc/services
if ! grep -w ntp /etc/services >/dev/null; then
echo "ntp 123/udp" >>/etc/services
fi

# remove rtc and daylight cron jobs
crontab -l | grep -vw '/usr/sbin/daylight' | grep -vw '/usr/sbin/rtc' | crontab -

# Make sure the system clock is correct at start up.
ntpdate -b -u 0.us.pool.ntp.org
if [ $? -ne 0 ] ; then
echo "Sleeping 10 seconds"
sleep 10
ntpdate -b -u 0.us.pool.ntp.org
fi

proc_start $command           
}

run_rc_command "$1

ffp/etc/ntp.conf
Code: [Select]
# US time servers, iburst to speed up synchronization on startup
#server us.pool.ntp.org iburst
server 0.us.pool.ntp.org
server 1.us.pool.ntp.org
server 2.us.pool.ntp.org
server 3.us.pool.ntp.org

# drift file path is passed on command line in ntpd.sh (-f)
# driftfile /etc/ntp.drift

# add local clock with stratum 10 as last resort
server 127.127.1.0
fudge  127.127.1.0 stratum 10

# detailed logging
#logconfig =all
Title: Re: Correct time during BST
Post by: jamieburchell on March 30, 2011, 01:24:24 PM
Thanks for the detailed reply. I have the time server and daylight savings disabled in the web configuration. I use that one line TZ fix in fun_plug.local. There's some cron jobs listed in crontab to do with the time- rtc, daylight, stime - I guess that's the problem.... I'll have a play.
Title: Re: Correct time during BST
Post by: chriso on March 30, 2011, 02:55:35 PM
Well you can certainly get rid of the programs causing problems in the crontab from the one script, as shown in my ffp/etc/fun_plug.local script.  The only problems with it is you are now left with no NTP client to compensate for drift, and also with rtc gone I'm not sure what will happen on reboot.  RTC I believe is responsible for writing/reading to the real time clock (maintain time when off), and I saw funny things with the times it set, that is why I killed it and then I set the time using the NTP client.
Title: Re: Correct time during BST
Post by: jamieburchell on March 30, 2011, 03:05:43 PM
In your example is it ntp.conf or ntp.drift, I'm a bit confused. Or are they different things?
If you're removing the rtc commands are you saying there are no adverse effects providing the time is set from a time server?
Also, what servers should I use for the UK!
thanks for your help, who'd have thought having the right date and time would be so difficult to achieve!
Would be nice if proper daylight savings were included in the new firmware. I've never had to specify dates for it each year in any other device.
Title: Re: Correct time during BST
Post by: chriso on March 30, 2011, 03:48:03 PM
It is ntp.conf.  ntp.drift gets created automatically to calculate what it thinks the drift will be so that it doesn't have to constantly contact the ntp server (instead it applies the drift for some time, and then contacts the ntp server).

You should probably not use the servers I'm using (even though they would work, ntp is based on UTC time it doesn't care where you are from).  Actually best might to be use the ones from this page:
http://www.pool.ntp.org/en/use.html (server 0.pool.ntp.org, ...)  Or better yet could also drill down and only use the ones from your region http://www.pool.ntp.org/zone/@  (Use the pool not the individual servers)


Quote
If you're removing the rtc commands are you saying there are no adverse effects providing the time is set from a time server?

Yes that is true provide the system clock gets set.  Here is what is happening.
Your system (DNS-323) has a "Real Time Clock", which is to say it has hardware that keeps the time of the day and will maintain the time even with the system off (battery backed up).  So when your system boots it will read the time and date from the RTC, but after it does it maintains its idea of the date and time separately from this clock.  For one thing its system clock is much more precise.  The RTC is only good to seconds.  And in some systems the system might even write its concept of time back to the RTC before shutting down.  Why?  Because since the time of the first PC these RTC chip have kept terrible time (they drift a lot more then your cheapest watch).  So basically I don't trust any of it.

If look you at the code in ffp/start/ntpd.sh I added this:
Code: [Select]
# Make sure the system clock is correct at start up.
ntpdate -b -u 0.us.pool.ntp.org
if [ $? -ne 0 ] ; then
echo "Sleeping 10 seconds"
sleep 10
ntpdate -b -u 0.us.pool.ntp.org
fi

What this does is try to set the system clock based on the the NTP server, and if it fails it gives another try in 10 seconds, (after that I just give up, after I want to boot more then to worry about the time).

The reason for ntpdate is because it says set the date plain and simple.  If you just say well I have the NTP client checking time won't it get the time to the right time?  Well the problem is that NTP was setup to compensate for small changes in time.  It is in the protocol that it corrects time very slowly (as in minutes off can take hours or even days to correct).  It is done like this so as not to disturb processes that are based on the time, like things in cron.  And it even won't try to sync if the time is too far off.
Title: Re: Correct time during BST
Post by: jamieburchell on March 31, 2011, 07:18:21 AM
Excellent. Finally got around to looking at this properly. I've enabled the ntpd.sh and made some edits to include your code to set the time initially. I see that this already handles the cron jobs. I've also added the TZ fix before the initial time update in the same file.
I've copied the example conf file and changed to uk time servers.
All seems to be working well. I notice however, that the "stime" cron job isn't removed by the FFP ntpd.sh script, should I remove that one too?
Thanks again for your help
Title: Re: Correct time during BST
Post by: dosborne on March 31, 2011, 08:54:49 AM
Yes, remove stime and rtc from cron.
Title: Re: Correct time during BST
Post by: jamieburchell on March 31, 2011, 10:01:41 AM
Just out of interest, why would the "dns323-rtc" command show the old time, but "date" shows the correct one? I'm guessing the correct date isn't being saved to rtc.
Title: Re: Correct time during BST
Post by: chriso on March 31, 2011, 05:58:36 PM
Yes like dosbrone said remove stime.  I actually have it removed the line in my ffp\etc\fun_plug.local
Code: [Select]
crontab -l | grep -vi rtc | grep -vi stime | grep -vi daylight | crontab -

does it.  As I said I had redundant code, and I just missed stime in the ntpd.sh script.  You will notice they do the same thing, they are just written a bit differently.

Quote
Just out of interest, why would the "dns323-rtc" command show the old time, but "date" shows the correct one? I'm guessing the correct date isn't being saved to rtc.

The ntpdate command sets the system time (date command shows this), it doesn't change the RTC.  You could run the RTC command to set it if you liked, but like I said I don't use it anyway with the ntpdate in place.
Title: Re: Correct time during BST
Post by: chriso on March 31, 2011, 06:33:01 PM
Actually I just looked at it more and dns323-rtc doesn't use the TZ variables, it just reports what time it has.
So if you sync the RTC with the system clock (which is stored internally as UTC):
/usr/sbin/rtc -w

You will find that the time the RTC shows is GMT/UTC time, and if you use "date" you will get the time adjusted for local and daylight time.

I decided to go ahead and add the setting of the RTC in the ntpd.sh just because if it ever fails to set time with ntpdate, then what will be the system time is what was retrieved from the RTC at boot so I might as well set it in the ntpd.sh when I know it is right (a drifting clock is better then one that is say an hour off):
Code: [Select]
     # Fix time zone information.
      # remove rtc, stime and daylight cron jobs
   crontab -l | grep -vi rtc | grep -vi stime | grep -vi daylight | crontab -

      # Make sure the system clock is correct at start up.
   ntpdate -b -u 0.us.pool.ntp.org
   if [ $? -ne 0 ] ; then
      echo "Sleeping 10 seconds"
      sleep 10
      ntpdate -b -u 0.us.pool.ntp.org
      if [ $? -eq 0 ] ; then
         /usr/sbin/rtc -w
      fi
   else
      /usr/sbin/rtc -w
   fi
Title: Re: Correct time during BST
Post by: jamieburchell on April 01, 2011, 01:57:06 PM
My dmesg is showing a lot of errors since doing this.

kernel: TWSI: mvTwsiStartBitSet ERROR
Title: Re: Correct time during BST
Post by: chriso on April 01, 2011, 04:07:14 PM
I don't have the problem, but it is talked about in this thread:
http://forum.dsmg600.info/viewtopic.php?pid=9812 (http://forum.dsmg600.info/viewtopic.php?pid=9812)

The last post seems to be the right one for this problem and he says all you need to do is stick the -x flag in the ntpd_flags line.
Title: Re: Correct time during BST
Post by: jamieburchell on April 02, 2011, 07:07:32 AM
I'll give that a try- I assume it's related to the time changes, since I've not seen those errors before. I was having trouble with a USB enclosure dropping out at the time, I don't know if that error could have related to that. I googled the error and got the post regarding the time stuff, so that swayed my judgment.

Interestingly, after a reboot last night, there isn't any more of those errors shown in dmesg.
Title: Re: Correct time during BST
Post by: chriso on April 02, 2011, 09:01:08 AM
From what I gather about from the thread is that if the time is too far off for ntpd to adjust properly (or drifts to fast) it will do that.  But I suspect once you are properly synced you shouldn't have the problem any more.
Title: Re: Correct time during BST
Post by: jamieburchell on April 06, 2011, 02:30:34 PM
Here's something strange- dmesg has filled up with these errors and I hadn't yet tried your suggestion. I noticed that the NAS was showing a temperature of 0 C 32 F and a fan speed (the fan wasn't running). I tried a restart from the web interface and the NAS got stuck in a startup cycle with the front LED flashing, the network light going on and off- as were the drive lights.

I've never seen that before, had to pull the plug.

For now I've disabled the ntpd stuff. Looks like a known issue:

http://forum.dsmg600.info/viewtopic.php?pid=28017 (http://forum.dsmg600.info/viewtopic.php?pid=28017)
Title: Re: Correct time during BST
Post by: chriso on April 06, 2011, 04:23:33 PM
Nothing is every easy!

Well if I get the gist of this right, the idea is that if ntpd is constantly changing the time to slew (actually stepping it, which causes the problem) it to the time it should be, that interferes with other processes that depend on looking at the time to do whatever they need to do.  The -x will force it to slew not step, which should prevent it from interfering with other time sensitive processes.

The big question I see to that is why does ntpd have to keep changing the time on those machines, must be a lot of drift (either in the DNS-323 or in the time servers).

I killed ntpd on my machine at then after 30 minutes to see what it said for time slew:
root@DLink-NAS:~# /ffp/bin/ntpd -q
ntpd: time slew +0.000644s

As you can see on my DNS-323 there isn't any reason it would be changing the time very often.

Anyway I suppose you could not run ntpd as a demon and just run the following command from cron once an hour or even less.
/ffp/bin/ntpd -q

It just sets the time and quits, it is like ntpdate I read they are going to obsolete, but it will use your ntpd.conf to find the time servers and such.

Also when I look at it I think that when you get out to the .00XX seconds, just which time server gets pulled up from the pool matters.  These machines are not atomic clocks so they do vary.
Title: Re: Correct time during BST
Post by: dosborne on April 06, 2011, 04:36:53 PM
I run it as a cron job once every 12 hours. It changes by a few seconds at most. I don't need precision any better than that so it works for me.
Title: Re: Correct time during BST
Post by: jamieburchell on April 07, 2011, 04:42:19 PM
I played a bit more and discovered that if you ONLY remove the "daylight" cron job and leave the others - providing you have the TZ fix in place, the stime script will get an updated (and correct) time from DLink each night. Without needing to bother with ntpd.

You just need to make sure you don't "save" the settings in the web interface, as this seems to write over the TZ fix.

Quite why the cron jobs still run even if the timeserver and daylight saving changes are disabled in the web admin is anyone's guess.