LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-01-2017, 01:44 PM   #1
MALDATA
Member
 
Registered: Mar 2005
Posts: 150

Rep: Reputation: 19
Sync network time before starting DHCP service


Hi all,

I'm writing an application that runs on a Raspberry Pi (Arch), which has no realtime clock. I'm having an issue using the Pi as a DHCP server. On boot, the Pi always thinks it's February 1, 2017. Shortly thereafter, the systemd-timesyncd daemon starts, and it sets the clock to the last time it knew about before its last shutdown. So, if I had the machine powered down for the weekend, the system clock would be a couple days behind. Not long after that, systemd-timesyncd syncs to an NTP server to actually set the system clock.

The problem is that the Pi's DHCP server can start independently of these things, and if it creates a DHCP lease when the Pi's time is behind by a few days (or all the way back to February) and then the time gets updated, the DHCP leases all expire.

In order to fix this, I've added an override to the DHCP systemd unit such that it starts AFTER time-sync.target. Upon doing this, I found out that systemd-timesyncd considers itself "started" after restoring the time from the last shutdown. In other words, if the Pi boots up after a weekend, it may still start systemd-timesyncd, set the time to two days ago, start DHCP, issue a DHCP lease, do an NTP sync, and then all the leases expire immediately.

What I want is to wait for the sync to an NTP server to actually occur after booting, and then start the DHCP server after that. Is anyone aware of a way to do this, or at the very least, a hacky way to make it work?

Thanks!
 
Old 06-01-2017, 03:15 PM   #2
kentyler
Member
 
Registered: Dec 2008
Location: Newark Ohio
Distribution: Fedora Core
Posts: 270

Rep: Reputation: 37
You could append to the network startup script, just add the command:

ntpdate ip.of.time.server

Then once network starts it runs a time sync
 
Old 06-01-2017, 05:33 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 21,620

Rep: Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187Reputation: 4187
ntpdate is depreceated. Changing to ntp instead of timesyncd might fix your timing problem.

Just to confirm that you configured the Pi with a static IP address and that no DHCP client is running.
 
Old 06-01-2017, 09:53 PM   #4
MALDATA
Member
 
Registered: Mar 2005
Posts: 150

Original Poster
Rep: Reputation: 19
Thanks for your input!

I read up on ntpdate a bit more, and all it really does is call ntpd with an option to sync immediately and then quit. When both ntpd and ntpdate are enabled as services, by default it runs ntpdate (sync immediately and then quit), then ntpd (as a daemon) after that. So, I get the result I wanted by enabling them both and then overriding a few things in the unit files to adjust the time-sync.target to depend on ntpd instead of timesyncd.

Quote:
ntpdate is depreceated. Changing to ntp instead of timesyncd might fix your timing problem.
Yeah, timesyncd doesn't have a lot of configuration options. ntpd is needed. The documentation does indicate that ntpdate is deprecated and due to be replaced by a shell script, but it's good enough for now.

Quote:
Just to confirm that you configured the Pi with a static IP address and that no DHCP client is running.
Our Pi has two ethernet ports, one of which connects to the WAN and may have a static IP or it may get one via DHCP. The other ethernet port is connected to a LAN on which the Pi is the DHCP server.

Thanks, all!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scan network for DHCP server requests in real-time noir911 Linux - Networking 1 03-17-2009 12:16 PM
starting network service. greplinux Linux - Newbie 4 10-07-2008 12:07 AM
fetchmail service not starting at boot time shibu_sp Linux - Newbie 1 07-12-2008 11:13 AM
Network sync my palm as a service Jefficus Linux - Networking 0 01-19-2007 10:53 AM
starting a service at boot time fallen26 General 5 07-31-2004 12:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration