Skip to content

Instantly share code, notes, and snippets.

@rosstimson
Created July 3, 2014 10:04
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save rosstimson/81e1f20fbb0d425ac09a to your computer and use it in GitHub Desktop.
Save rosstimson/81e1f20fbb0d425ac09a to your computer and use it in GitHub Desktop.
Init Script (RHEL, CentOS) for ZooKeeper + optional configs (assumes zookeeper tarball extracted to /opt/zookeeper)
# /opt/zookeeper/conf/java.env
ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
ZOO_LOG_DIR="/var/log/zookeeper/"
# /etc/profile.d/java.sh
export JAVA_OPTS="-Xms2048m -Xmx2048m"
# /opt/zookeeper/conf/zoo.cfg
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/var/lib/zookeeper/data
# Transaction log
dataLogDir=/var/lib/zookeeper/data-log
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
# Cluster servers
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
#!/bin/bash
# /etc/init.d/zookeeper
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# ZooKeeper
#
# chkconfig: 2345 89 9
# description: zookeeper
# ZooKeeper install path (where you extracted the tarball)
ZOOKEEPER='/opt/zookeeper'
source /etc/rc.d/init.d/functions
source $ZOOKEEPER/bin/zkEnv.sh
RETVAL=0
PIDFILE="/var/lib/zookeeper/data/zookeeper_server.pid"
desc="ZooKeeper daemon"
start() {
echo -n $"Starting $desc (zookeeper): "
daemon --user zookeeper $ZOOKEEPER/bin/zkServer.sh start
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zookeeper
return $RETVAL
}
stop() {
echo -n $"Stopping $desc (zookeeper): "
daemon --user zookeeper $ZOOKEEPER/bin/zkServer.sh stop
RETVAL=$?
sleep 5
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zookeeper $PIDFILE
}
restart() {
stop
start
}
get_pid() {
cat "$PIDFILE"
}
checkstatus(){
status -p $PIDFILE ${JAVA_HOME}/bin/java
RETVAL=$?
}
condrestart(){
[ -e /var/lock/subsys/zookeeper ] && restart || :
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
checkstatus
;;
restart)
restart
;;
condrestart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
exit 1
esac
exit $RETVAL
@eahydra
Copy link

eahydra commented Apr 15, 2016

Hi, ross. What's the daemon program?

@dkd903
Copy link

dkd903 commented Dec 19, 2016

Daemon is available inside /etc/rc.d/init.d/functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment