#!/usr/bin/perl
use strict;
use warnings;

my $lease_file = "/var/lib/dhcpd/dhcpd.leases";

# last modified time
my $modtime = 0;

# seconds to wait
my $update_freq = 30;

#we create a function because we want to write in log
sub log2messages
   {
        my $message = shift;
        tie *FH, 'esmith::Logger';
        print FH "$message";
        close FH;
   }

###########################################################################
# Main Loop
while (1) {

  # check the file's last updated time, if it's been changed, update
  # the DNS and save the modified time.  This will ALWAYS run once - on
  # startup, since $modtime starts at zero.

  my @stats = stat ($lease_file);
  if ($stats[9] > $modtime) {
  
  	$modtime = $stats[9];
        system ("/usr/bin/sv 1 /service/tinydns") ==0
            or log2messages('Error service dhcp-dns : Unable to restart /service/tinydns');

        system ("/usr/bin/sv 1 /service/dnscache") ==0
            or log2messages('Error service dhcp-dns : Unable to do restart /service/dnscache');
  }

  # wait till next check time
  sleep $update_freq;

} # end main
###########################################################################
