Editing dhcpd.conf without corrupting leases

John Hascall john at iastate.edu
Mon Apr 13 18:29:59 UTC 2009


> You've misread the original post yet again. The web app doesn't touch  
> the .conf file, the cron job does. And then, when it's finished, it  
> might restart dhcpd. This part is working fine.
> 
> The problem is the lease database. The OP thinks that perhaps dhcpd  
> gets interrupted while writing out the lease database, thereby  
> corrupting it. But since dhcpd doesn't lock the file in any way,  
> there's no way to test for this.
> 
> Adding a test step (dhcpd -T -t) will probably help, but it still  
> leaves a small window between that test and the subsequent SIGTERM.

I have been rebuilding our dhcpd.conf this way for several years
without incident.

Essentially, my cronjob (which runs every minute)
looks something like this:

    [ -f ${FLAGFILE} ] || exit 0                   # nothing to do?
    rm -f ${CONFFILE}.old ${CONFFILE}.new

    build-conf > ${CONFFILE}.new
    [ $? -eq 0 ] || exit 1

    /usr/sbin/dhcpd -q -t -cf ${CONFFILE}.new
    [ $? -ne 0 ] && exit 1

    ln ${CONFFILE} ${CONFFILE}.old
    /etc/rc.d/dhcpd stop
    sleep 1                                           # jsut in case
    /etc/rc.d/dhcpd status
    [ $? -eq 0 ] && exit 1

    mv ${CONFFILE}.new ${CONFFILE}
    /etc/rc.d/dhcpd start


John



More information about the dhcp-users mailing list