diff --git a/package/gluon-respondd/files/etc/hotplug.d/iface/10-gluon-respondd b/package/gluon-respondd/files/etc/hotplug.d/iface/10-gluon-respondd index c8594a1bc648b2476f0bdeb2d9e136d12822dd77..4f49be52065181a1cbe79323cf3338c82e58f0b0 100644 --- a/package/gluon-respondd/files/etc/hotplug.d/iface/10-gluon-respondd +++ b/package/gluon-respondd/files/etc/hotplug.d/iface/10-gluon-respondd @@ -4,7 +4,6 @@ . /lib/functions/service.sh DEVLIST=/var/run/gluon-respondd.devs -DAEMON=/usr/bin/respondd ifname_to_dev () { json_load "$(ubus call network.interface.$1 status)" @@ -13,20 +12,10 @@ ifname_to_dev () { echo "$dev" } -restart_respondd () { - SERVICE_USE_PID=1 - SERVICE_WRITE_PID=1 - SERVICE_DAEMONIZE=1 - - DEVS=$(cat $DEVLIST | while read dev iface; do echo -n " -i $dev"; done) - - service_stop $DAEMON - service_start $DAEMON -g ff02::2:1001 -p 1001 -d /lib/gluon/respondd $DEVS -} - case "$ACTION" in ifdown) - sed -i "/$INTERFACE/d" $DEVLIST + sed "/ $INTERFACE$/d" $DEVLIST > $DEVLIST.new + mv $DEVLIST.new $DEVLIST ;; ifup) DEVICE="$(ifname_to_dev "$INTERFACE")" @@ -34,11 +23,12 @@ case "$ACTION" in [ "$MESH" = "bat0" -o "$INTERFACE" = "client" ] || exit 0 - DEVS=$(cat $DEVLIST; echo $DEVICE $INTERFACE) + DEVS=$(cat $DEVLIST 2>/dev/null; echo $DEVICE $INTERFACE) - echo "$DEVS" | sort -u > $DEVLIST + echo "$DEVS" | sort -u > $DEVLIST.new + mv $DEVLIST.new $DEVLIST - restart_respondd + /etc/init.d/gluon-respondd restart_if_running & ;; esac diff --git a/package/gluon-respondd/files/etc/init.d/gluon-respondd b/package/gluon-respondd/files/etc/init.d/gluon-respondd new file mode 100755 index 0000000000000000000000000000000000000000..a1bf979f088495b99c73f26d6560956483c84f21 --- /dev/null +++ b/package/gluon-respondd/files/etc/init.d/gluon-respondd @@ -0,0 +1,45 @@ +#!/bin/sh /etc/rc.common + +EXTRA_COMMANDS='restart_if_running' + +START=50 + +SERVICE_WRITE_PID=1 +SERVICE_DAEMONIZE=1 + +DEVLIST=/var/run/gluon-respondd.devs +DAEMON=/usr/bin/respondd +LOCK=/var/run/gluon-respondd.lock + + +do_start() { + DEVS=$(cat $DEVLIST 2>/dev/null | while read dev iface; do echo -n " -i $dev"; done) + service_start $DAEMON -g ff02::2:1001 -p 1001 -d /lib/gluon/respondd $DEVS +} + +do_stop() { + service_stop $DAEMON +} + +start() { + lock $LOCK + do_start + lock -u $LOCK +} + +stop() { + lock $LOCK + do_stop + lock -u $LOCK +} + +restart_if_running() { + lock $LOCK + + if service_check $DAEMON; then + do_stop + do_start + fi + + lock -u $LOCK +}