Commit 485353ba authored by Axel Auweter's avatar Axel Auweter
Browse files

Auto-create SysV init.d script.

parent b576f5e4
include config.mk
LIBRARIES = DCDBLib
PROJECTS = FilePusher SysFsPusher CollectAgent ParastationProvider IPMIPusher MontBlancPusher SNMPPusher DCDBTools
PROJECTS = FilePusher SysFsPusher CollectAgent ParastationProvider IPMIPusher MontBlancPusher SNMPPusher DCDBTools scripts
CASSANDRA_VERSION = 2.1.8
MOSQUITTO_VERSION = 1.3.5
......
include ../config.mk
.PHONY : clean install all
all:
install:
# Install SysV init.d script
mkdir -p $(DCDBDEPLOYPATH)/etc/init.d/
sed -e 's|%DCDB_PREFIX%|'$(DCDBDEPLOYPATH)'|g' dcdb_init > $(DCDBDEPLOYPATH)/etc/init.d/dcdb
chmod +x $(DCDBDEPLOYPATH)/etc/init.d/dcdb
#!/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
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`
if [ "$R" -gt "20" ]; then
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)
env LD_LIBRARY_PATH=$LD_LIBRARY_PATH collectagent -D -h 127.0.0.1 -t 8640000
# 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
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment