Root/ibrdtnd/files/ibrdtn.init

1#!/bin/sh /etc/rc.common
2# Copyright (C) 2007 OpenWrt.org
3
4START=90
5
6start() {
7    # check if the daemon is disabled
8    if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
9        /bin/echo "dtnd is disabled"
10        return
11    fi
12    
13    /bin/echo -n "running dtnd ..."
14    
15    # startup the safety-wrapper for the daemon
16    /usr/sbin/dtnd-safety-wrapper.sh &
17    
18    # store the pid of the process in uci states
19    /sbin/uci -P/var/state -q set ibrdtn.safetypid=`echo $!`
20    
21    /bin/echo " done"
22}
23
24stop() {
25    # check if the daemon is disabled
26    if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
27        /bin/echo "dtnd is disabled"
28        return
29    fi
30    
31    /bin/echo -n "stopping dtnd ..."
32    
33    # set state to None, this indicates a clear shutdown to the safety-wrapper.
34    /sbin/uci -P/var/state -q set ibrdtn.state=None
35    
36    # stop the safety-wrapper
37    if [ -n "`/sbin/uci -P/var/state -q get ibrdtn.safetypid`" ]; then
38        /usr/bin/kill `/sbin/uci -P/var/state -q get ibrdtn.safetypid` 2> /dev/null >/dev/null
39    fi
40    
41    # finally kill really all safety-wrapper!
42    /bin/sleep 2
43    /usr/bin/killall -9 dtnd-safety-wrapper.sh
44    
45    # send a kill signal to the daemon
46    /usr/bin/killall dtnd 2> /dev/null >/dev/null
47    
48    # wait for some time
49    TIMEOUT=0;
50    
51    # check if the daemon is running
52    while [ -n "`ps ax | grep dtnd | grep -v grep`" ]; do
53        # check if the daemon is still running
54        if [ $TIMEOUT -ge 10 ]; then
55            /bin/echo " killing"
56            # kill all processes of dtnd
57            /usr/bin/killall -9 dtnd 2> /dev/null >/dev/null
58            return
59        fi
60        
61        # increment timeout
62        TIMEOUT=`expr $TIMEOUT + 1`
63        
64        echo -n "."
65        
66        # wait some time
67        /bin/sleep 1
68    done
69    
70    echo " done"
71}
72

Archive Download this file



interactive