dcdb_init 2.53 KB
Newer Older
Axel Auweter's avatar
Axel Auweter committed
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh

### BEGIN INIT INFO
# Provides:        dcdb
# Required-Start:  $network $remote_fs $syslog
# Required-Stop:   $network $remote_fs $syslog
# Default-Start:   2 3 4 5
# Default-Stop:    1
# Short-Description: Start DCDB stack (Cassandra, CollectAgent)
### END INIT INFO

12
13
14
# Time to wait before giving up on bringing up a service
SERVICE_TIMEOUT=180

Axel Auweter's avatar
Axel Auweter committed
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
DCDB_PREFIX=%DCDB_PREFIX%
PATH=/bin:/usr/bin:${DCDB_PREFIX}/bin:${DCDB_PREFIX}/cassandra/bin

. /lib/lsb/init-functions

LD_LIBRARY_PATH=${DCDB_PREFIX}/lib/

LOCKFILE=${DCDB_PREFIX}/lock
CASSANDRA_PID_FILE=${DCDB_PREFIX}/cassandra.pid

lock_dcdb() {
        if [ -x /usr/bin/lockfile-create ]; then
                lockfile-create $LOCKFILE
                lockfile-touch $LOCKFILE &
                LOCKTOUCHPID="$!"
        fi
}

unlock_dcdb() {
        if [ -x /usr/bin/lockfile-create ] ; then
                kill $LOCKTOUCHPID
                lockfile-remove $LOCKFILE
        fi
}

wait_for_listen_port() {
	echo "Waiting for listening socket on port $1 ..."
	R=0
	E=0
	while [ "$E" -eq "0" ]; do
		R=`expr $R + 1`
46
		if [ "$R" -gt "$SERVICE_TIMEOUT" ]; then
Axel Auweter's avatar
Axel Auweter committed
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
72
73
74
75
76
77
78
79
80
81
82
			echo "Service did not come up in time. Exiting."
			exit 3
		fi
		sleep 1
		netstat -l --numeric --inet | grep $1 > /dev/null
		if [ "$?" -eq "0" ]; then
			E=1
		fi
	done
	echo "Port now open on port $1!"
}

case $1 in
	start)
		# Check if cassandra/collectagent are running
		C=`ps aux | grep cassandra | grep -v grep`
		if [ "$?" = "0" ]; then
			echo "Cassandra already running, please stop the service first."
			exit 3
		fi
		C=`ps aux | grep collectagent | grep -v grep`
		if [ "$?" = "0" ]; then
			echo "CollectAgent already running, please stop the service first."
			exit 3
		fi

		echo "Starting DCDB..."
		lock_dcdb

		# Start Cassandra
		cassandra -p $CASSANDRA_PID_FILE

		# Wait till cassandra is up
		wait_for_listen_port 9160

		# Start CollectAgent (TTL for the data is 100 days)
83
84
85
86
		#env LD_LIBRARY_PATH=$LD_LIBRARY_PATH collectagent -D -l 0.0.0.0 -h 127.0.0.1 -t 8640000
		
		# Start CollectAgent (no TTL)
		env LD_LIBRARY_PATH=$LD_LIBRARY_PATH collectagent -D -l 0.0.0.0 -h 127.0.0.1
Axel Auweter's avatar
Axel Auweter committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116

		# Wait till CollectAgent is up
		wait_for_listen_port 1883

		unlock_dcdb
  		;;
	stop)
		echo "Stopping DCDB Service"
		killall -s SIGINT collectagent
		sleep 2
		if [ -e $CASSANDRA_PID_FILE ]; then
			kill `cat $CASSANDRA_PID_FILE`
		fi
  		;;
	restart|force-reload)
		$0 stop && sleep 5 && $0 start
  		;;
	reload)
		exit 3
		;;
	status)
		echo "Status not implemented."
		exit 3
		;;
	*)
		echo "Usage: $0 {start|stop|restart|status}"
		exit 2
		;;
esac