* luci/contrib: add fork of openwrt olsrd
[project/luci.git] / contrib / package / olsrd-luci / files / etc / init.d / olsrd
diff --git a/contrib/package/olsrd-luci/files/etc/init.d/olsrd b/contrib/package/olsrd-luci/files/etc/init.d/olsrd
new file mode 100755 (executable)
index 0000000..04c3a75
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh /etc/rc.common
+START=50
+
+BIN=/usr/sbin/olsrd
+CONF=/var/etc/olsrd.conf
+DEFAULT=/etc/default/olsrd
+PID=/var/run/olsrd.pid
+
+start() {
+       ### load defaults
+       [ -f $DEFAULT ] && . $DEFAULT
+
+       ### generate config
+       mkdir -p ${CONF%/*}
+       lua /lib/config/olsr.lua > $CONF
+
+       ### check for running instance (start-stop-daemon is too stupid to do this)
+       if [ -s $PID ]; then
+               if kill -0 $(cat $PID) 2>&-; then
+                       echo "there is already a running instance ($(cat $PID))"
+                       exit 1
+               fi
+       fi
+
+       ### start olsrd
+       start-stop-daemon -b -m -p $PID -x $BIN -S -- -f $CONF -nofork $OPTIONS
+}
+
+stop() {
+       ### stop olsrd
+       start-stop-daemon -q -p $PID -a ${BIN##*/} -K
+}
+
+restart() {
+       ### override generic restart because we need some time between stop and start
+       stop; sleep 3; start
+}