From b4aaf8a1f804af5bab9c16bd43112606cc8620b3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer <mschiffer@universe-factory.net> Date: Tue, 2 Feb 2016 06:38:03 +0100 Subject: [PATCH] gluon-respondd: add init script Instead of starting gluon-respondd from a hotplug handler, add a proper init script. The new init script has a restart_if_running argument which is now used by the hotplug handler. --- .../etc/hotplug.d/iface/10-gluon-respondd | 22 +++------ .../files/etc/init.d/gluon-respondd | 45 +++++++++++++++++++ 2 files changed, 51 insertions(+), 16 deletions(-) create mode 100755 package/gluon-respondd/files/etc/init.d/gluon-respondd 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 c8594a1bc..4f49be520 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 000000000..a1bf979f0 --- /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 +} -- GitLab