Bug#779890: udhcpd: Support for multiple interfaces/udhcpd processes
Grr, final bit of confirmation has a shell quirk show up. I suspect there likely should be more backslashes on the sed command, but the attached is what is confirmed to work. -- (\___(\___(\__ --=> 8-) EHM <=-- __/)___/)___/) \BS (| ehem+sig...@m5p.com PGP 87145445 |) / \_CS\ | _ -O #include O- _ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445 #! /bin/sh # # Written by Miquel van Smoorenburg . # Modified for Debian GNU/Linux by Ian Murdock # and Axel Beckert . # Adjusted for use as an ifupdown hook script by Elliott Mitchell # . # ### BEGIN INIT INFO # Provides: udhcpd # Required-Start:$remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start busybox udhcpd at boot time ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/udhcpd NAME=udhcpd DESC="very small Busybox based DHCP server" DHCPD_OPTS="-S" # Additional options given to the server test -x $DAEMON || exit 0 case "${IF_DHCPD_ENABLE}" in udhcpd) # *we* and not some other DHCP server are enabled ;; true|yes|1) # the DHCP server is enabled ;; *) exit 0 ;; esac # Include defaults if available [ -e /etc/default/udhcpd ] && . /etc/default/udhcpd set -e # Base location of configuration if relative path is given [ -z "${DHCPD_CONFIG_DIR}" ] && DHCPD_CONFIG_DIR=/etc # Has a configuration file been explicitly specified? Optionally add directory if [ -n "${IF_DHCPD_CONFIG}" ] thenif [ "${IF_DHCPD_CONFIG}" = "${IF_DHCPD_CONFIG#/}" ] thenIF_DHCPD_CONFIG=${DHCPD_CONFIG_DIR}/${IF_DHCPD_CONFIG} fi # Probe the location, first try ifupdown's logical name, then physical name elif [ -e "${DHCPD_CONFIG_DIR}/udhcpd.${LOGICAL}.conf" ] thenIF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.${LOGICAL}.conf" elif [ -e "${DHCPD_CONFIG_DIR}/udhcpd.${IFACE}.conf" ] thenIF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.${IFACE}.conf" elseIF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.conf" fi # Has the .pid file been specified? Is it relative? if [ -n "${IF_DHCPD_PIDFILE}" ] thenif [ "${IF_DHCPD_PIDFILE}" = "${IF_DHCPD_PIDFILE#/}" ] thenIF_DHCPD_PIDFILE=/run/${IF_DHCPD_PIDFILE} fi # Look for the .pid file in the configuration file elseif grep -q -E -e^\[\[:space:]]\*pidfile\[\[:space:]] ${IF_DHCPD_CONFIG} thenIF_DHCPD_PIDFILE=`grep -E -e^\[\\\[:space:]]\*pidfile\[\\\[:space:]] ${IF_DHCPD_CONFIG} | sed -es/^\[\\\[:space:]]\*pidfile\[\\\[:space:]]+//` elseIF_DHCPD_PIDFILE=/run/udhcpd.pid fi fi # This works better for us [ "${VERBOSITY}" = 0 ] && VERBOSITY="" case "$MODE" in start) [ -n "${VERBOSITY}" ] && echo -n "Starting $DESC: " start-stop-daemon --start ${VERBOSITY:+--verbose} \ --pidfile ${IF_DHCPD_PIDFILE} --oknodo --exec $DAEMON \ -- ${IF_DHCPD_OPTS:-${DHCPD_OPTS}} ${IF_DHCPD_CONFIG} [ -n "${VERBOSITY}" ] && echo "$NAME." ;; stop) [ -n "${VERBOSITY}" ] && echo -n "Stopping $DESC: " start-stop-daemon --stop ${VERBOSITY:+--verbose} \ --pidfile ${IF_DHCPD_PIDFILE} --oknodo --exec $DAEMON [ -n "${VERBOSITY}" ] && echo "$NAME." ;; *) echo "Usage: $0 {start|stop}" >&2 exit 1 ;; esac exit 0
Bug#779890: udhcpd: Support for multiple interfaces/udhcpd processes
On Fri, Mar 06, 2015 at 09:02:39AM +0300, Michael Tokarev wrote: > 06.03.2015 02:57, Elliott Mitchell wrote: > > The documentation seems to suggest udhcpd can only handle binding to one > > interface and using one IP address range per udhcpd process. Due to > > this, it would be handy if Debian's init scripts had support for > > starting/stopping multiple udhcpd processes (this would mean require > > multiple .conf and .pid files). > > I suggest using some more advanced dhcp servers for this, for > example there's an excellent piece of software named dnsmasq > which is small and has other useful functionality. Udhcpd > scripts can be extended to support multiple interfaces, but > I think at this time, it is better to use, say, systemd > service files for that, which should be trivial to write > and drop to the right location (and no, I don't know off > my head how to do that ;). I'm undecided on systemd right now, but the controversy has me rather concerned right now. dnsmasq may well be used in the future, but right now I still suspect udhcpd can readily take care of my current needs. > > When reading the man page I was wondering, could multiple configuration > > files be specified on udhcpd's command-line and would this have the > > effect of starting multiple udhcpd processes? (I rather doubt it, but > > the man page could be read that way) > > One invocation handles one interface, I think. But you can try :) I doubt it would work, just the man page could be interpreted to suggest this. I'm unsure whether it is good or bad news, but with some adjustments the /etc/init.d/udhcpd script can be rewritten as an ifupdown hook script. I'm attaching the script, place it in /etc/network/if-up.d/udhcpd, stick a symbolic link in /etc/network/if-down.d/ and the attached script will start/stop udhcpd when a given interface is brought up or down. This adds 3 settings to /etc/network/interfaces. "dhcpd-enable", "dhcpd-config" and "dhcpd-pidfile". Setting "dhcpd-enable" to "true", "yes", "1", or "udhcpd" will make udhcpd to be started when a given interface is brought up. If set, "dhcpd-config" will specify the configuration filename, DHCPD_CONFIG_DIR (set in /etc/default/udhcpd) will be added as a prefix if this is not an absolute path; otherwise it will look for /etc/udhcpd..conf then /etc/udhcpd..conf and finally fall back to /etc/udhcpd.conf. The "dhcpd-pidfile" can tell it where the .pid file is, though it will try to find it in the configuration file. Hopefully this works for others as a way to start udhcpd. -- (\___(\___(\__ --=> 8-) EHM <=-- __/)___/)___/) \BS (| ehem+sig...@m5p.com PGP 87145445 |) / \_CS\ | _ -O #include O- _ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445 #! /bin/sh # # Written by Miquel van Smoorenburg . # Modified for Debian GNU/Linux by Ian Murdock # and Axel Beckert . # Adjusted for use as an ifupdown hook script by Elliott Mitchell # . # ### BEGIN INIT INFO # Provides: udhcpd # Required-Start:$remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start busybox udhcpd at boot time ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/sbin/udhcpd NAME=udhcpd DESC="very small Busybox based DHCP server" DHCPD_OPTS="-S" # Additional options given to the server test -x $DAEMON || exit 0 case "${IF_DHCPD_ENABLE}" in udhcpd) # *we* and not some other DHCP server are enabled ;; true|yes|1) # the DHCP server is enabled ;; *) exit 0 ;; esac # Include defaults if available [ -e /etc/default/udhcpd ] && . /etc/default/udhcpd set -e # Base location of configuration if relative path is given [ -z "${DHCPD_CONFIG_DIR}" ] && DHCPD_CONFIG_DIR=/etc # Has a configuration file been explicitly specified? Optionally add directory if [ -n "${IF_DHCPD_CONFIG}" ] thenif [ "${IF_DHCPD_CONFIG}" = "${IF_DHCPD_CONFIG#/}" ] thenIF_DHCPD_CONFIG=${DHCPD_CONFIG_DIR}/${IF_DHCPD_CONFIG} fi # Probe the location, first try ifupdown's logical name, then physical name elif [ -e "${DHCPD_CONFIG_DIR}/udhcpd.${LOGICAL}.conf" ] thenIF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.${LOGICAL}.conf" elif [ -e "${DHCPD_CONFIG_DIR}/udhcpd.${IFACE}.conf" ] thenIF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.${IFACE}.conf" elseIF_DHCPD_CONFIG="${DHCPD_CONFIG_DIR}/udhcpd.conf" fi # Has the .pid file been specified? Is it relative? if [ -n "${IF_DHCPD_PIDFILE}" ] thenif [ "${IF_DHCPD_PIDFILE}" = "${IF_DHCPD_PIDFILE#/}" ] thenIF_DHCPD_PIDFILE=/run/${IF_DHCPD_PIDFILE} fi # Look for the .pid file in the configuration file elseif grep -q -E -e^\[\[:space:]]\*pidfile\[\[:space:]] ${IF_DHCPD_CONFIG} thenIF_DHCPD_P
Bug#779890: udhcpd: Support for multiple interfaces/udhcpd processes
06.03.2015 02:57, Elliott Mitchell wrote: > Package: udhcpd > Version: 1:1.20.0-7 > Severity: wishlist > > The documentation seems to suggest udhcpd can only handle binding to one > interface and using one IP address range per udhcpd process. Due to > this, it would be handy if Debian's init scripts had support for > starting/stopping multiple udhcpd processes (this would mean require > multiple .conf and .pid files). I suggest using some more advanced dhcp servers for this, for example there's an excellent piece of software named dnsmasq which is small and has other useful functionality. Udhcpd scripts can be extended to support multiple interfaces, but I think at this time, it is better to use, say, systemd service files for that, which should be trivial to write and drop to the right location (and no, I don't know off my head how to do that ;). > When reading the man page I was wondering, could multiple configuration > files be specified on udhcpd's command-line and would this have the > effect of starting multiple udhcpd processes? (I rather doubt it, but > the man page could be read that way) One invocation handles one interface, I think. But you can try :) Thanks, /mjt -- To UNSUBSCRIBE, email to debian-boot-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/54f942ff.40...@msgid.tls.msk.ru
Bug#779890: udhcpd: Support for multiple interfaces/udhcpd processes
Upon a bit more thinking about the situation, I must suggest the overlapping feature of adding a hook script to allow udhcpd to be started/stopped by `ifupdown` instead of only by init script. This ends up dovetailing into support for multiple interfaces. -- (\___(\___(\__ --=> 8-) EHM <=-- __/)___/)___/) \BS (| ehem+sig...@m5p.com PGP 87145445 |) / \_CS\ | _ -O #include O- _ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445 -- To UNSUBSCRIBE, email to debian-boot-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150306032746.ga52...@scollay.m5p.com
Bug#779890: udhcpd: Support for multiple interfaces/udhcpd processes
Package: udhcpd Version: 1:1.20.0-7 Severity: wishlist The documentation seems to suggest udhcpd can only handle binding to one interface and using one IP address range per udhcpd process. Due to this, it would be handy if Debian's init scripts had support for starting/stopping multiple udhcpd processes (this would mean require multiple .conf and .pid files). When reading the man page I was wondering, could multiple configuration files be specified on udhcpd's command-line and would this have the effect of starting multiple udhcpd processes? (I rather doubt it, but the man page could be read that way) -- (\___(\___(\__ --=> 8-) EHM <=-- __/)___/)___/) \BS (| ehem+sig...@m5p.com PGP 87145445 |) / \_CS\ | _ -O #include O- _ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445 -- To UNSUBSCRIBE, email to debian-boot-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150305235736.ga51...@scollay.m5p.com