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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#!/bin/sh
#
# zookeeper ZooKeeper Server
#
# chkconfig: - 80 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=<%= scope.lookupvar("zookeeper::service_name") %>
desc="Zookeeper Service"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile="/var/lock/subsys/$prog"
pidfile=<%= scope.lookupvar("zookeeper::pid_path") %>
[ "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 <%= scope.lookupvar("zookeeper::zoo_main") %>"
else
ZOOMAIN=<%= scope.lookupvar("zookeeper::zoo_main") %>
fi
ZOOBINDIR="<%= scope.lookupvar("zookeeper::service::_zoo_dir") %>/bin"
ZOOCFGDIR=<%= scope.lookupvar("zookeeper::cfg_dir") %>
ZOOCFG="$ZOOCFGDIR/zoo.cfg"
ZOO_LOG_DIR=<%= scope.lookupvar("zookeeper::log_dir") %>
[ -e "$ZOOCFGDIR/java.env" ] && . "$ZOOCFGDIR/java.env"
[ -e "$ZOOCFGDIR/<%= scope.lookupvar("zookeeper::environment_file") %>" ] && . "$ZOOCFGDIR/<%= scope.lookupvar("zookeeper::environment_file") %>"
[ "x$ZOO_LOG4J_PROP" = "x" ] && ZOO_LOG4J_PROP="<%= scope.lookupvar("zookeeper::log4j_prop") %>"
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} ${JAVA_OPTS} ${JVMFLAGS} ${ZOOMAIN} ${ZOOCFG} & echo \$! > ${pidfile}"
start() {
echo $pidfile
echo -n "Starting $desc $prog: "
touch $pidfile && chown <%= scope.lookupvar("zookeeper::user") %> $pidfile
daemon --user <%= scope.lookupvar("zookeeper::user") %> --pidfile $pidfile "$cmd"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
restart
}
get_status() {
if [ -f $pidfile ]
then
PID=`cat $pidfile`
if [ -z "`ps -ef | awk '{print $2}' | grep "^$PID$"`" ]
then
echo "$prog stopped but pid file exists"
exit 1
else
echo "$prog running with pid $PID"
exit 0
fi
else
echo "$prog stopped"
exit 1
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
get_status
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
|