diff options
author | jim-p <jimp@pfsense.org> | 2012-05-16 10:48:26 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2012-05-16 10:48:26 -0400 |
commit | 0b8e9d38d8bc8a53b4e6bb503f487dae425ca3fd (patch) | |
tree | 876c344332e9ed7c0f970e41f44aafeae455f14c | |
parent | 11e069064b417cacbd56f7f557b131af3c10fb86 (diff) | |
download | pfsense-0b8e9d38d8bc8a53b4e6bb503f487dae425ca3fd.zip pfsense-0b8e9d38d8bc8a53b4e6bb503f487dae425ca3fd.tar.gz |
On its own, ntpd does not sync fast enough at bootup, so bring back the ntpdate sync but improve it so it can't get stuck forever.
-rw-r--r-- | etc/inc/system.inc | 8 | ||||
-rwxr-xr-x | etc/rc.bootup | 11 | ||||
-rwxr-xr-x | etc/rc.newwanip | 3 | ||||
-rwxr-xr-x | etc/rc.newwanipv6 | 3 | ||||
-rwxr-xr-x | usr/local/sbin/ntpdate_sync_once.sh | 27 |
5 files changed, 35 insertions, 17 deletions
diff --git a/etc/inc/system.inc b/etc/inc/system.inc index bb7ed11..b22d170 100644 --- a/etc/inc/system.inc +++ b/etc/inc/system.inc @@ -1249,7 +1249,7 @@ function system_timezone_configure() { echo gettext("done.") . "\n"; } -function system_ntp_configure() { +function system_ntp_configure($start_ntpd=true) { global $config, $g; $driftfile = "/var/db/ntpd.drift"; @@ -1277,6 +1277,10 @@ function system_ntp_configure() { /* slurp! */ fclose($fd); + /* At bootup we just want to write out the config. */ + if (!$start_ntpd) + return; + /* if ntpd is running, kill it */ while(is_process_running("ntpd")) { killbyname("ntpd"); @@ -1294,7 +1298,7 @@ function system_ntp_configure() { // Note that we are starting up log_error("NTPD is starting up."); - + return; } function sync_system_time() { diff --git a/etc/rc.bootup b/etc/rc.bootup index baf39da..721cea6 100755 --- a/etc/rc.bootup +++ b/etc/rc.bootup @@ -305,6 +305,12 @@ system_routing_configure(); /* enable routing */ system_routing_enable(); +/* Do an initial time sync */ +echo "Starting NTP time client..."; +/* At bootup this will just write the config, ntpd will launch from ntpdate_sync_once.sh */ +system_ntp_configure(false); +mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh"); + /* start load balancer daemon */ relayd_configure(); @@ -329,11 +335,6 @@ send_event("service reload dyndnsall"); /* Run a filter configure now that most all services have started */ filter_configure_sync(); -/* start the NTP client */ -echo "Starting OpenNTP time client..."; -system_ntp_configure(); -echo "done.\n"; - /* setup pppoe and pptp */ vpn_setup(); diff --git a/etc/rc.newwanip b/etc/rc.newwanip index fd73901..a33502c 100755 --- a/etc/rc.newwanip +++ b/etc/rc.newwanip @@ -50,7 +50,8 @@ function restart_packages() { global $oldip, $curwanipi, $g; /* restart packages */ - system_ntp_configure(); + system_ntp_configure(false); + mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh"); log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages."); send_event("service reload packages"); } diff --git a/etc/rc.newwanipv6 b/etc/rc.newwanipv6 index 9f02772..3571e40 100755 --- a/etc/rc.newwanipv6 +++ b/etc/rc.newwanipv6 @@ -62,7 +62,8 @@ function restart_packages() { global $oldip, $curwanipv6, $g; /* restart packages */ - system_ntp_configure(); + system_ntp_configure(false); + mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh"); log_error("{$g['product_name']} package system has detected an ip change $oldip -> $curwanip ... Restarting packages."); mwexec_bg("/etc/rc.start_packages"); } diff --git a/usr/local/sbin/ntpdate_sync_once.sh b/usr/local/sbin/ntpdate_sync_once.sh index 7aa20a8..f4a5256 100755 --- a/usr/local/sbin/ntpdate_sync_once.sh +++ b/usr/local/sbin/ntpdate_sync_once.sh @@ -1,19 +1,30 @@ #!/bin/sh NOTSYNCED="true" -SERVER=`cat /cf/conf/config.xml | grep timeservers | cut -d">" -f2 | cut -d"<" -f1` -pkill -f ntpdate_sync_once.sh +MAX_ATTEMPTS=3 +SERVER=`/bin/cat /cf/conf/config.xml | /usr/bin/grep timeservers | /usr/bin/cut -d">" -f2 | /usr/bin/cut -d"<" -f1` +/bin/pkill -f ntpdate_sync_once.sh -while [ "$NOTSYNCED" = "true" ]; do +ATTEMPT=1 +# Loop until we're synchronized, but for a set number of attempts so we don't get stuck here forever. +while [ "$NOTSYNCED" = "true" ] && [ ${ATTEMPT} -le ${MAX_ATTEMPTS} ]; do # Ensure that ntpd and ntpdate are not running so that the socket we want will be free. - killall ntpd 2>/dev/null - killall ntpdate + /usr/bin/killall ntpd 2>/dev/null + /usr/bin/killall ntpdate 2>/dev/null sleep 1 - ntpdate -s -t 5 $SERVER + /usr/sbin/ntpdate -s -t 5 ${SERVER} if [ "$?" = "0" ]; then NOTSYNCED="false" + else + sleep 5 + ATTEMPT=`expr ${ATTEMPT} + 1` fi - sleep 5 done -/usr/local/sbin/ntpd -g -c /var/etc/ntpd.conf
\ No newline at end of file +if [ "$NOTSYNCED" = "true" ]; then + echo "Giving up on time sync after ${MAX_ATTEMPTS} attempts." | /usr/bin/logger -t ntp; +fi + +if [ -f /var/etc/ntpd.conf ]; then + /usr/sbin/ntpd -g -c /var/etc/ntpd.conf +fi
\ No newline at end of file |