aboutsummaryrefslogtreecommitdiff
path: root/net/ibrdtnd/files/ibrdtn.init
blob: 5a00c24115948237e2d58071da894ba28d2999a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/sh /etc/rc.common
# Copyright (C) 2007 OpenWrt.org

START=90

start() {
	# check if the daemon is disabled
	if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
		/bin/echo "dtnd is disabled"
		return
	fi
	
	/bin/echo -n "running dtnd ..."
	
	# startup the safety-wrapper for the daemon
	/usr/sbin/dtnd-safety-wrapper.sh &
	
	# store the pid of the process in uci states
	/sbin/uci -P/var/state -q set ibrdtn.safetypid=`echo $!`
	
	/bin/echo " done"
}

stop() { 
	# check if the daemon is disabled
	if [ "`/sbin/uci -P/var/state -q get ibrdtn.disable`" == "1" ]; then
		/bin/echo "dtnd is disabled"
		return
	fi
	
	/bin/echo -n "stopping dtnd ..."
	
	# set state to None, this indicates a clear shutdown to the safety-wrapper.
	/sbin/uci -P/var/state -q set ibrdtn.state=None
	
	# stop the safety-wrapper
	if [ -n "`/sbin/uci -P/var/state -q get ibrdtn.safetypid`" ]; then
		/usr/bin/kill `/sbin/uci -P/var/state -q get ibrdtn.safetypid` 2> /dev/null >/dev/null
	fi
	
	# finally kill really all safety-wrapper!
	/bin/sleep 2
	/usr/bin/killall -9 dtnd-safety-wrapper.sh
	
	# send a kill signal to the daemon
	/usr/bin/killall dtnd 2> /dev/null >/dev/null
	
	# wait for some time
	TIMEOUT=0;
	
	# check if the daemon is running
	while [ -n "`ps | grep dtnd | grep -v grep`" ]; do
		# check if the daemon is still running
		if [ $TIMEOUT -ge 10 ]; then
			/bin/echo " killing"
			# kill all processes of dtnd
			/usr/bin/killall -9 dtnd 2> /dev/null >/dev/null
			return
		fi
		
		# increment timeout
		TIMEOUT=`expr $TIMEOUT + 1`
		
		echo -n "."
		
		# wait some time
		/bin/sleep 1
	done
	
	echo " done"
}