Translate

Friday, February 14, 2014

Zookeeper Init Script

#!/bin/sh
#
# zookeeper ZooKeeper Server
#
# chkconfig: - 18 05
# description: Enable ZooKeeper Server
#
### BEGIN INIT INFO
# Provides: zookeeper
# Default-Start:
# Default-Stop:
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Description: zookeeper Server
# Short-Description: Enable zookeeper Server
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions
prog="zookeeeper"
desc="zookeeper Server"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile="/var/lock/subsys/$prog.pid"
pidfile="/home/zookeeper/zookeeper/data/$prog.pid"
[ "x$JMXLOCALONLY" = "x" ] && JMXLOCALONLY=false
if [ "x$JMXDISABLE" = "x" ]
then
# for some reason these two options are necessary on jdk6 on Ubuntu
# accord to the docs they are not necessary, but otw jconsole cannot
# do a local attach

ZOOMAIN="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY org.apache.zookeeper.server.quorum.QuorumPeerMain"
else
ZOOMAIN="org.apache.zookeeper.server.quorum.QuorumPeerMain"
fi

ZOOBINDIR="/home/zookeeper/zookeeper/bin"
ZOOCFGDIR="/home/zookeeper/zookeeper/conf"
ZOOCFG="zoo.cfg"
ZOOCFG="$ZOOCFGDIR/$ZOOCFG"
ZOO_LOG_DIR="/home/zookeeper/zookeeper/logs"
[ -e "$ZOOCFGDIR/java.env" ] && . "$ZOOCFGDIR/java.env"
[ "x$ZOO_LOG4J_PROP" = "x" ] && ZOO_LOG4J_PROP="INFO,CONSOLE"

for f in ${ZOOBINDIR}/../zookeeper-*.jar
do
CLASSPATH="$CLASSPATH:$f"
done
ZOOLIBDIR=${ZOOLIBDIR:-$ZOOBINDIR/../lib}
for i in "$ZOOLIBDIR"/*.jar
do
CLASSPATH="$CLASSPATH:$i"
done
#add the zoocfg dir to classpath
CLASSPATH=$ZOOCFGDIR:$CLASSPATH
cmd="java \"-Dzookeeper.log.dir=${ZOO_LOG_DIR}\" \"-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}\" -cp ${CLASSPATH} ${JVMFLAGS} ${ZOOMAIN} ${ZOOCFG} & echo \$! > ${pidfile}"
start() {
echo -n quot;Starting $desc ($prog): "
touch $pidfile && sudo chown zookeeper $pidfile
daemon --user zookeeper --pidfile $pidfile "$cmd" > "$ZOO_LOG_DIR/zookeeper.out"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n quot;Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
stop
start
}

reload() {
restart
}

get_status() {
status $prog
RETVAL=$?
STAT=`echo stat | nc localhost $(grep clientPort $ZOOCFG | sed -e 's/.*=//') 2> /dev/null| grep Mode`
if [ "x$STAT" = "x" ]
then
echo "Error contacting service."
else
echo $STAT
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
get_status
;;
*)
echo quot;Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac

exit $RETVAL

2 comments:

  1. I adore your websites way of raising the awareness on your readers.
    web hosting in Nigeria

    ReplyDelete
  2. Keep up the good work andplease tell me when can you publish more articles or where can I read more on the subject?
    Marketing1on1 - Find the best marketing companies

    ReplyDelete

About Me

My photo
Greetings Friend! I am Linux scholar, trying to learn as much I can and share it with you. I am in mid of my Professional Career. Doing Good. :)

Followers