Skip to content

Instantly share code, notes, and snippets.

@gchaix
Forked from logic/java.env
Last active July 20, 2017 23:29
Show Gist options
  • Save gchaix/03261522c400b61fb8fa1ec4982cc4aa to your computer and use it in GitHub Desktop.
Save gchaix/03261522c400b61fb8fa1ec4982cc4aa to your computer and use it in GitHub Desktop.
Zookeeper RPM spec for CentOS and Fedora, including python bindings
ZOO_LOG4J_PROP="INFO,ROLLINGFILE"
ZOO_LOG_DIR="/var/log/zookeeper/"
#
# ZooKeeper Logging Configuration
#
# Format is "<default threshold> (, <appender>)+
# DEFAULT: console appender only
#log4j.rootLogger=INFO, CONSOLE
log4j.rootLogger=INFO, ROLLINGFILE
# Example with rolling log file
#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE
# Example with rolling log file and tracing
#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE
#
# Log INFO level and above messages to the console
#
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
#
# Add ROLLINGFILE to rootLogger to get log file output
# Log DEBUG level and above messages to a log file
log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender
log4j.appender.ROLLINGFILE.Threshold=DEBUG
log4j.appender.ROLLINGFILE.File=/var/log/zookeeper/zookeeper.log
# Max log file size of 10MB
log4j.appender.ROLLINGFILE.MaxFileSize=10MB
# uncomment the next line to limit number of backup files
#log4j.appender.ROLLINGFILE.MaxBackupIndex=10
log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout
log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L] - %m%n
#
# Add TRACEFILE to rootLogger to get log file output
# Log DEBUG level and above messages to a log file
log4j.appender.TRACEFILE=org.apache.log4j.FileAppender
log4j.appender.TRACEFILE.Threshold=TRACE
log4j.appender.TRACEFILE.File=/var/log/zookeeper/zookeeper_trace.log
log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout
### Notice we are including log4j's NDC here (%x)
log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} - %-5p [%t:%C{1}@%L][%x] - %m%n
#!/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="zookeeper"
desc="zookeeper Server"
user="hrsitest"
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
lockfile="/var/lock/subsys/$prog"
pidfile="/var/run/$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="/ngs/app/hrsitest/opt/zookeeper/bin"
ZOOCFGDIR="/ngs/app/hrsitest/opt/zookeeper/conf"
ZOOCFG="zoo.cfg"
ZOOCFG="$ZOOCFGDIR/$ZOOCFG"
ZOO_LOG_DIR="/ngs/app/hrsitest/log/zookeeper"
[ -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 $"Starting $desc ($prog): "
touch $pidfile && chown zookeeper $pidfile
daemon --user $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() {
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 $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
/ngs/app/hrsitest/log/zookeeper/*.log {
weekly
rotate 10
copytruncate
delaycompress
compress
notifempty
missingok
}
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%define _noarch_libdir /usr/lib
%define rel_ver 3.3.5
Summary: High-performance coordination service for distributed applications.
Name: zookeeper
Version: %{rel_ver}
Release: 1
License: Apache License v2.0
Group: Applications/Databases
URL: http://hadoop.apache.org/zookeeper/
Source0: http://www.apache.org/dyn/closer.cgi/hadoop/zookeeper/zookeeper-%{rel_ver}/zookeeper-%{rel_ver}.tar.gz
Source1: zookeeper.init
Source2: zookeeper.logrotate
Source3: zoo.cfg
Source4: log4j.properties
Source5: java.env
BuildRoot: %{_tmppath}/%{name}-%{rel_ver}-%{release}-root
BuildRequires: python-devel,gcc,autoconf,automake,libtool,cppunit-devel
Requires: logrotate, java, cppunit
Requires(post): chkconfig initscripts
Requires(pre): chkconfig initscripts
AutoReqProv: no
%description
ZooKeeper is a distributed, open-source coordination service for distributed
applications. It exposes a simple set of primitives that distributed
applications can build upon to implement higher level services for
synchronization, configuration maintenance, and groups and naming. It is
designed to be easy to program to, and uses a data model styled after the
familiar directory tree structure of file systems. It runs in Java and has
bindings for both Java and C.
Coordination services are notoriously hard to get right. They are especially
prone to errors such as race conditions and deadlock. The motivation behind
ZooKeeper is to relieve distributed applications the responsibility of
implementing coordination services from scratch.
%define _zookeeper_noarch_libdir %{_noarch_libdir}/zookeeper
%define _maindir %{buildroot}%{_zookeeper_noarch_libdir}
%prep
%setup -q -n zookeeper-%{rel_ver}
%build
pushd src/c
rm -rf aclocal.m4 autom4te.cache/ config.guess config.status config.log \
config.sub configure depcomp install-sh ltmain.sh libtool \
Makefile Makefile.in missing stamp-h1 compile
autoheader
libtoolize --force
aclocal
automake -a
autoconf
autoreconf
%configure
%{__make} %{?_smp_mflags}
popd
# Build Python interface
cd src/contrib/zkpython
python src/python/setup.py build_ext -L $PWD/../../c/.libs
%install
rm -rf %{buildroot}
install -p -d %{buildroot}%{_zookeeper_noarch_libdir}
cp -a bin lib %{buildroot}%{_zookeeper_noarch_libdir}
# Copy all necessary lib files etc.
mkdir -p %{buildroot}%{_sysconfdir}/zookeeper
install -p -D -m 644 zookeeper-%{rel_ver}.jar %{buildroot}%{_zookeeper_noarch_libdir}/zookeeper-%{rel_ver}.jar
install -p -D -m 755 %{S:1} %{buildroot}%{_initrddir}/zookeeper
install -p -D -m 644 %{S:2} %{buildroot}%{_sysconfdir}/logrotate.d/zookeeper
install -p -D -m 644 %{S:3} %{buildroot}%{_sysconfdir}/zookeeper/zoo.cfg
install -p -D -m 644 %{S:4} %{buildroot}%{_sysconfdir}/zookeeper/log4j.properties
install -p -D -m 644 %{S:5} %{buildroot}%{_sysconfdir}/zookeeper/java.env
install -p -D -m 644 conf/configuration.xsl %{buildroot}%{_sysconfdir}/zookeeper/configuration.xsl
install -d %{buildroot}%{_sbindir}
install -d %{buildroot}%{_bindir}
ln -sf %{_zookeeper_noarch_libdir}/bin/zkServer.sh %{buildroot}%{_sbindir}/zookeeper-server
ln -sf %{_zookeeper_noarch_libdir}/bin/zkCleanup.sh %{buildroot}%{_sbindir}/zookeeper-cleanup
ln -sf %{_zookeeper_noarch_libdir}/bin/zkCli.sh %{buildroot}%{_bindir}/zookeeper-cli
install -d %{buildroot}%{_localstatedir}/log/zookeeper
install -d %{buildroot}%{_localstatedir}/lib/zookeeper
install -d %{buildroot}%{_localstatedir}/lib/zookeeper/data
install -p -d -D -m 0755 %{buildroot}%{_datadir}/zookeeper
%{makeinstall} -C src/c
# Kludge for ugly default path
mv %{buildroot}%{_includedir}/c-client-src %{buildroot}%{_includedir}/zookeeper
cd src/contrib/zkpython
python src/python/setup.py install --install-lib %{buildroot}%{python_sitearch}
%clean
rm -rf %{buildroot}
%files
%defattr(-,root,root,-)
%doc CHANGES.txt LICENSE.txt NOTICE.txt README.txt
%doc docs recipes
%dir %attr(0750, zookeeper, zookeeper) %{_localstatedir}/lib/zookeeper
%dir %attr(0750, zookeeper, zookeeper) %{_localstatedir}/lib/zookeeper/data
%dir %attr(0750, zookeeper, zookeeper) %{_localstatedir}/log/zookeeper
%{_zookeeper_noarch_libdir}
%{_initrddir}/zookeeper
%config(noreplace) %{_sysconfdir}/logrotate.d/zookeeper
%config(noreplace) %{_sysconfdir}/zookeeper
%{_sbindir}
%{_bindir}
# ------------------------------ libzookeeper ------------------------------
%package -n libzookeeper
Summary: C client interface to zookeeper server
Group: Development/Libraries
BuildRequires: gcc
%description -n libzookeeper
The client supports two types of APIs -- synchronous and asynchronous.
Asynchronous API provides non-blocking operations with completion callbacks and
relies on the application to implement event multiplexing on its behalf.
On the other hand, Synchronous API provides a blocking flavor of
zookeeper operations and runs its own event loop in a separate thread.
Sync and Async APIs can be mixed and matched within the same application.
%files -n libzookeeper
%defattr(-, root, root, -)
%doc src/c/README src/c/LICENSE
%{_libdir}/libzookeeper_mt.so.*
%{_libdir}/libzookeeper_st.so.*
# ------------------------------ libzookeeper-devel ------------------------------
%package -n libzookeeper-devel
Summary: Headers and static libraries for libzookeeper
Group: Development/Libraries
Requires: gcc
%description -n libzookeeper-devel
This package contains the libraries and header files needed for
developing with libzookeeper.
%files -n libzookeeper-devel
%defattr(-, root, root, -)
%{_includedir}
%{_libdir}/*.a
%{_libdir}/*.la
%{_libdir}/*.so
# ------------------------------ Python ------------------------------
%package -n python-zookeeper
Summary: Python client library for ZooKeeper
Group: Development/Libraries
Requires: python, libzookeeper
%description -n python-zookeeper
Python client library for ZooKeeper.
%files -n python-zookeeper
%defattr(-, root, root, -)
%doc src/contrib/zkpython/README src/contrib/zkpython/src/python/zk.py
%{python_sitearch}
# ======================================================================================
%pre
getent group zookeeper >/dev/null || groupadd -r zookeeper
getent passwd zookeeper >/dev/null || useradd -r -g zookeeper -d / -s /sbin/nologin zookeeper
exit 0
%post
/sbin/chkconfig --add zookeeper
%preun
if [ $1 = 0 ] ; then
/sbin/service zookeeper stop >/dev/null 2>&1
/sbin/chkconfig --del zookeeper
fi
%postun
if [ "$1" -ge "1" ] ; then
/sbin/service zookeeper condrestart >/dev/null 2>&1 || :
fi
%changelog
* Fri Apr 6 2012 Ed Marshall <[email protected]> - 3.3.5-1
- Updated to 3.3.5.
- Added several missing build and install requirements.
* Fri Nov 12 2010 Daniel Lundin <[email protected]> - 3.3.2-2
- Update to 3.3.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment