From owner-freebsd-stable@FreeBSD.ORG Wed Nov 30 18:55:54 2005 Return-Path: X-Original-To: freebsd-stable@freebsd.org Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9CC0D16A41F for ; Wed, 30 Nov 2005 18:55:54 +0000 (GMT) (envelope-from LukeD@pobox.com) Received: from thorn.pobox.com (thorn.pobox.com [208.210.124.75]) by mx1.FreeBSD.org (Postfix) with ESMTP id 248CA43D64 for ; Wed, 30 Nov 2005 18:55:54 +0000 (GMT) (envelope-from LukeD@pobox.com) Received: from thorn (localhost [127.0.0.1]) by thorn.pobox.com (Postfix) with ESMTP id 41802AD; Wed, 30 Nov 2005 13:56:15 -0500 (EST) Received: from pool-71-112-205-160.sttlwa.dsl-w.verizon.net (pool-71-112-205-160.sttlwa.dsl-w.verizon.net [71.112.205.160]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by thorn.sasl.smtp.pobox.com (Postfix) with ESMTP id 6B9888E0; Wed, 30 Nov 2005 13:56:13 -0500 (EST) Date: Wed, 30 Nov 2005 10:55:47 -0800 (PST) From: Luke Dean X-X-Sender: lukas@border.crystalsphere.multiverse To: "Ian D. Leroux" In-Reply-To: <1133316076.522.28.camel@localhost> Message-ID: <20051130105535.M796@border.crystalsphere.multiverse> References: <1133316076.522.28.camel@localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-stable@freebsd.org Subject: Re: Restarting ntpd on address change X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Luke Dean List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2005 18:55:54 -0000 On Tue, 29 Nov 2005, Ian D. Leroux wrote: > Greetings, > > My machine's ip address is assigned by DHCP, and whenever it changes > ntpd stops functioning and must be restarted. I gather this behavior > will be changed in some future ntpd version, but in the meantime I had > added a line to my /etc/dhclient-exit-hooks to restart ntpd every time a > new address was obtained: > > # [...] setup variables for ipcheck > > if [ -n "$new_ip_address" ]; then > # [...] run ipcheck to update my dyndns > /etc/rc.d/ntpd restart > fi > > This seemed work fine on 5.4, but on 6.0 it gives problems at boot. > Specifically, I get repeated "bad file descriptor" errors after my > network address is assigned, and running ps after the boot completes > shows that there are two ntpd processes running. Killing one of them > stops the file descriptor errors. My interpretation of this (for what > it's worth) is that an ntpd process gets started before dhclient gets a > chance to configure the address (perhaps when the interface initially > comes up) and then when the address is assigned the /etc/rc.d/ntpd > restart starts a second process, but somehow fails to stop the first > one. For now I've removed that line from dhclient-exit-hooks, which > avoids the problems at boot time. > > I have the feeling that I'm not doing the Right Thing here. So is there > an accepted (or at least known-good) way of automatically managing the > restart of ntpd on address change? Have I found a bug in rc.d worth > investigating? Or should I just stick to manual restarts until ntpd > stops needing them? > > Thanks, > > Ian D. Leroux I needed to solve that same problem and came up with the same solution you did. I saw it work under 5.4 several times when my ISP did maintenance on my upstream router. I've kept the same setup under 6 and haven't noticed any problems yet. I've been fortunate enough to keep my IP address leased since my upgrade to 6, so I haven't truly tested this under 6. Eventually my ISP will do something to make me lose my lease, and if I have any problems then, I'll post. I run pf on this system too. If I don't reset the firewall when I get a new IP address, I lose connectivity. That makes ntpd very upset. Here's what I'm doing in dhclient-exit-hooks to solve both problems: if [ "$old_ip_address" != "$new_ip_address" ]; then case "$new_ip_address" in 10.*) ;; 172.1[6-9].* | 172.2[0-9].* | 172.3[0-1].*) ;; 192.168.*) ;; *) logger -t dhclient IP address changed from $old_ip_address to $new_ip_address resetting pf pfctl -Fa -f /etc/pf.conf logger -t restarting ntpd /etc/rc.d/ntpd restart ;; esac fi