Package: ddclient
Version: 3.8.1-1
Severity: wishlist
Tags: patch

Running ddclient as a daemon consumes memory, which in routers and
embedded systems is not abundant. It would be useful to run ddclient only
when the IP potentially changes, which for most home networks is after
DHCP client updates.

Attached is a patch which adds an exit hook to dhclient (the DHCP client
from isc-dhcp-client) and a debconf configuration option which controls
whether it is used or not, similar to the existing 'run_ipup' for ppp
connections.

Best,
Teemu
>From 93010be3d7e2c93f6e59da68414d7fae24b08f3b Mon Sep 17 00:00:00 2001
From: Teemu Ikonen <tpiko...@gmail.com>
Date: Sun, 31 Mar 2013 15:38:12 +0200
Subject: [PATCH] Add dhclient exit hook and debconf configuration.

---
 debian/config                      |    1 +
 debian/ddclient.dhclient-exit-hook |   16 ++++++++++++++++
 debian/ddclient.templates          |    8 ++++++++
 debian/dirs                        |    1 +
 debian/postinst                    |    7 ++++++-
 debian/rules                       |    4 +++-
 6 files changed, 35 insertions(+), 2 deletions(-)
 create mode 100644 debian/ddclient.dhclient-exit-hook

diff --git a/debian/config b/debian/config
index f91cb9d..f561cf9 100644
--- a/debian/config
+++ b/debian/config
@@ -39,6 +39,7 @@ read_old_config()
 
   db_set ddclient/run_daemon false
   db_set ddclient/run_ipup false
+  db_set ddclient/run_dhclient false
 }
 
 
diff --git a/debian/ddclient.dhclient-exit-hook b/debian/ddclient.dhclient-exit-hook
new file mode 100644
index 0000000..88ddb2a
--- /dev/null
+++ b/debian/ddclient.dhclient-exit-hook
@@ -0,0 +1,16 @@
+#!/bin/sh
+# /etc/dhcp/dhclient-exit-hooks.d/ddclient - exit hook for dhclient
+
+[ -x /usr/sbin/ddclient ] || exit 0
+[ -f /etc/default/ddclient ] || exit 0
+. /etc/default/ddclient
+[ $run_dhclient = "true" ] || exit 0
+
+case $reason in
+    BOUND | RENEW | REBIND)
+        /usr/bin/logger -t dhclient $reason, updating IP address with ddclient
+        /usr/sbin/ddclient -daemon=0 -syslog > /dev/null 2>&1
+        ;;
+    *)
+        ;;
+esac
diff --git a/debian/ddclient.templates b/debian/ddclient.templates
index 07f407f..3e322cb 100644
--- a/debian/ddclient.templates
+++ b/debian/ddclient.templates
@@ -62,6 +62,14 @@ _Description: Network interface used for dynamic DNS service:
  Please enter the name of the network interface (eth0/wlan0/ppp0/...)
  to use for dynamic DNS service.
 
+Template: ddclient/run_dhclient
+Type: boolean
+Default: false
+_Description: Run ddclient on DHCP update?
+ You should enable this option if ddclient should be run every time the
+ IP address is changed by the DHCP client (dhclient).
+ Note: This mode is not compatible with daemon mode.
+
 Template: ddclient/run_ipup
 Type: boolean
 Default: false
diff --git a/debian/dirs b/debian/dirs
index 92b2a37..bd557c8 100644
--- a/debian/dirs
+++ b/debian/dirs
@@ -1,3 +1,4 @@
 usr/sbin
 var/cache/ddclient
 etc/ppp/ip-up.d
+etc/dhcp/dhclient-exit-hooks.d
diff --git a/debian/postinst b/debian/postinst
index 472ca8d..8277dfa 100644
--- a/debian/postinst
+++ b/debian/postinst
@@ -51,6 +51,7 @@ EOF
       db_get ddclient/run_daemon			&& run_daemon="$RET"
       db_get ddclient/daemon_interval		&& daemon_interval="$RET"
       db_get ddclient/run_ipup				&& run_ipup="$RET"
+      db_get ddclient/run_dhclient			&& run_dhclient="$RET"
       temp=`mktemp /etc/default/ddclient.XXXXXX`
       trap "rm -f $temp; exit 1" HUP INT QUIT TERM
       cat <<EOF >"$temp"
@@ -59,12 +60,16 @@ EOF
 #
 # /etc/default/ddclient
 
+# Set to "true" if ddclient should be run every time DHCP client ('dhclient'
+# from package isc-dhcp-client) updates the systems IP address.
+run_dhclient="$run_dhclient"
+
 # Set to "true" if ddclient should be run every time a new ppp connection is 
 # established. This might be useful, if you are using dial-on-demand.
 run_ipup="$run_ipup"
 
 # Set to "true" if ddclient should run in daemon mode
-# If this is changed to true, run_ipup must be set to false.
+# If this is changed to true, run_ipup and run_dhclient must be set to false.
 run_daemon="$run_daemon"
 
 # Set the time interval between the updates of the dynamic DNS name in seconds.
diff --git a/debian/rules b/debian/rules
index 694f22b..b91b64a 100755
--- a/debian/rules
+++ b/debian/rules
@@ -32,7 +32,9 @@ install: build
 
 	install -m 755 ddclient \
 	  $(DESTDIR)/usr/sbin/ddclient
-	
+	install -m 755 debian/ddclient.dhclient-exit-hook \
+	  $(DESTDIR)/etc/dhcp/dhclient-exit-hooks.d/ddclient
+
 %.8 : %.xml
 	xmlto -o $(@D) man $<
 
-- 
1.7.10.4

Reply via email to