diff --git a/.gitignore b/.gitignore index edda063..15545ff 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,10 @@ pom.xml.asc /.nrepl-port .hgignore .hg/ +rpmbuild/BUILD +rpmbuild/BUILDROOT +rpmbuild/RPMS +rpmbuild/SRPMS +rpmbuild/SOURCES/*.tar.gz +yum +.DS_Store diff --git a/Dockerfile.centos6 b/Dockerfile.centos6 new file mode 100644 index 0000000..b778e52 --- /dev/null +++ b/Dockerfile.centos6 @@ -0,0 +1,6 @@ +FROM centos:6 +MAINTAINER Junegunn Choi + +RUN yum clean all && yum install -y rpm-build rpmdevtools createrepo + +WORKDIR /root diff --git a/Dockerfile.centos7 b/Dockerfile.centos7 new file mode 100644 index 0000000..796cf4e --- /dev/null +++ b/Dockerfile.centos7 @@ -0,0 +1,6 @@ +FROM centos:7 +MAINTAINER Junegunn Choi + +RUN yum clean all && yum install -y rpm-build rpmdevtools createrepo + +WORKDIR /root diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3101230 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +NAME := hbase-packet-inspector +VERSION := 0.2.0 +UBERJAR := target/$(NAME)-$(VERSION).jar + +RPM6 := rpmbuild/RPMS/x86_64/$(NAME)-$(VERSION)-1.el6.x86_64.rpm +RPM7 := rpmbuild/RPMS/x86_64/$(NAME)-$(VERSION)-1.el7.centos.x86_64.rpm + +TARBALL := rpmbuild/SOURCES/$(NAME)-$(VERSION).tar.gz + +build: $(UBERJAR) + +$(UBERJAR): $(shell find src/ -name "*.clj") + lein uberjar + +$(TARBALL): $(UBERJAR) + mkdir -p rpmbuild/{BUILD,BUILDROOT,RPMS,SRPMS} + mkdir -p rpmbuild/SOURCES/$(NAME)/lib + cp -f $(UBERJAR) rpmbuild/SOURCES/$(NAME)/lib/$(NAME).jar + cd rpmbuild/SOURCES && tar -cvzf $(NAME)-$(VERSION).tar.gz $(NAME) + +$(RPM6): $(TARBALL) + make centos6 + docker run -v $(CURDIR)/rpmbuild:/root/rpmbuild -t hpi-centos6 rpmbuild -ba rpmbuild/SPECS/hbase-packet-inspector.spec + +$(RPM7): $(TARBALL) + make centos7 + docker run -v $(CURDIR)/rpmbuild:/root/rpmbuild -t hpi-centos7 rpmbuild -ba rpmbuild/SPECS/hbase-packet-inspector.spec + +rpm6: $(RPM6) +rpm7: $(RPM7) +rpm: $(RPM6) $(RPM7) + +yum: + rm -rf yum + mkdir -p yum/{6,7} + cp -f rpmbuild/RPMS/x86_64/hbase-packet-inspector-0.2.0-1.el6.x86_64.rpm yum/6 + cp -f rpmbuild/RPMS/x86_64/hbase-packet-inspector-0.2.0-1.el7.centos.x86_64.rpm yum/7 + docker run -v $(CURDIR)/rpmbuild:/root/rpmbuild -v $(CURDIR)/yum:/root/yum -it hpi-centos6 createrepo /root/yum/6 + docker run -v $(CURDIR)/rpmbuild:/root/rpmbuild -v $(CURDIR)/yum:/root/yum -it hpi-centos7 createrepo /root/yum/7 + +yum-server: + cd yum && python -m SimpleHTTPServer 8080 + +%: Dockerfile.% + docker build -t hpi-$@ - < Dockerfile.$@ + # docker run -v $(CURDIR)/rpmbuild:/root/rpmbuild -it hpi-$@ + +clean: + rm -rf rpmbuild/{BUILD,BUILDROOT,RPMS,SRPMS} \ + rpmbuild/SOURCES/$(NAME)-$(VERSION).tar.gz \ + rpmbuild/SOURCES/$(NAME)/lib yum + +.PHONY: all build rpm rpm6 rpm7 yum yum-server clean diff --git a/README.md b/README.md index 14019c5..645ed20 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,17 @@ sent to Kafka as JSON record. lein uberjar ``` +### RPM for Centos 6 and 7 + +This repository includes [Makefile](Makefile) for building RPM files for +Centos 6 and 7 using Docker. + +```sh +make rpm +``` + +RPM files will be created under `rpmbuild/RPMS/x86_64` directory. + ## Development ### Test diff --git a/rpmbuild/SOURCES/hbase-packet-inspector/conf/hbase-packet-inspector.properties b/rpmbuild/SOURCES/hbase-packet-inspector/conf/hbase-packet-inspector.properties new file mode 100644 index 0000000..13b1271 --- /dev/null +++ b/rpmbuild/SOURCES/hbase-packet-inspector/conf/hbase-packet-inspector.properties @@ -0,0 +1,2 @@ +# kafka = bootstrap1:9092,bootstrap2:9092/hbase-traffic +device = eth0 diff --git a/rpmbuild/SOURCES/hbase-packet-inspector/conf/log4j.properties b/rpmbuild/SOURCES/hbase-packet-inspector/conf/log4j.properties new file mode 100644 index 0000000..cb6755b --- /dev/null +++ b/rpmbuild/SOURCES/hbase-packet-inspector/conf/log4j.properties @@ -0,0 +1,7 @@ +log4j.rootLogger=INFO, FILE +log4j.appender.FILE=org.apache.log4j.RollingFileAppender +log4j.appender.FILE.File=/var/log/hbase-packet-inspector.log +log4j.appender.FILE.MaxFileSize=256MB +log4j.appender.FILE.MaxBackupIndex=10 +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%d %-5p: %m%n diff --git a/rpmbuild/SOURCES/hbase-packet-inspector/init.d/hbase-packet-inspector b/rpmbuild/SOURCES/hbase-packet-inspector/init.d/hbase-packet-inspector new file mode 100644 index 0000000..96bff78 --- /dev/null +++ b/rpmbuild/SOURCES/hbase-packet-inspector/init.d/hbase-packet-inspector @@ -0,0 +1,124 @@ +#!/bin/bash +# Starts hbase-packet-inspector daemon +# +# chkconfig: 345 90 10 +# description: hbase-packet-inspector daemon +# +### BEGIN INIT INFO +# Provides: hbase-packet-inspector +# Required-Stop: $local_fs $network +# Required-Start: $local_fs $network +# Default-Start: 3 4 5 +# Default-Stop: 0 1 2 6 +# Short-Description: start and stop hbase-packet-inspector daemon +# Description: Monitors HBase packets and sends them to Kafka +### END INIT INFO + +# Sample in /usr/share/doc/initscripts-*/sysvinitfiles + +. /etc/rc.d/init.d/functions + +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - insufficient privilege +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running + +[ $EUID = 0 ] || exit 4 + +prog=hbase-packet-inspector +proghome=/usr/lib/$prog +jar=$proghome/lib/$prog.jar +conf=$proghome/conf/$prog.properties +logconf=$proghome/conf/log4j.properties + +[ -f "$jar" ] || exit 5 + +check_file() { + local f + for f in "$@"; do + if [ ! -f "$f" ]; then + echo "$f is not found" + exit 6 + fi + done +} + +check_file "$conf" "$logconf" + +getval() { + local val + val=$(grep -Po "^ *$1 *= *\K[^#]*" < "$conf" | tail -1) + if [ -z "$val" ]; then + echo "$1 not found in $conf" + return 1 + fi + echo "$val" +} + +get_cluster() { + if [ -f /etc/hadoop/conf/core-site.xml ]; then + local cluster + cluster=$(sed -n '/fs.defaultFS/ {n; s|.*://||; s|<.*||; p}' /etc/hadoop/conf/core-site.xml) + [ -n "$cluster" ] && echo "?cluster=$cluster" + fi +} + +kafka=$(getval kafka) || exit 6 +[[ "$kafka" =~ '?' ]] || kafka=$kafka$(get_cluster) +device=$(getval device) || exit 6 +options="--interface $device --kafka $kafka" +cmd="java -Xmx2g -Dlog4j.configuration=file:$logconf -jar $jar $options" + +pidfile=/var/run/$prog.pid + +start() { + status "$prog" && exit 1 + + echo -n "Starting $prog: " + java -jar "$jar" --help > /dev/null || exit 1 + daemon --check "$prog" "nohup $cmd < /dev/null > /dev/null 2>&1 & echo \$! > $pidfile" + ret=$? + touch /var/lock/subsys/$prog + echo + return $ret +} + +stop() { + echo -n "Shutting down $prog: " + killproc "$prog" + ret=$? + rm -f /var/lock/subsys/$prog + echo + return $ret +} + +case "$1" in +start) + start + ;; +stop) + stop + ;; +restart|reload) + stop + start + ;; +condrestart) + if [ -f /var/lock/subsys/$prog ]; then + stop + start + fi + ;; +status) + status "$prog" + ;; +*) + echo "Usage: $0 {start|stop|status|reload|restart|condrestart}" + exit 2 +esac + +exit $? diff --git a/rpmbuild/SPECS/hbase-packet-inspector.spec b/rpmbuild/SPECS/hbase-packet-inspector.spec new file mode 100644 index 0000000..2cfbd6e --- /dev/null +++ b/rpmbuild/SPECS/hbase-packet-inspector.spec @@ -0,0 +1,47 @@ +Name: hbase-packet-inspector +Version: 0.2.0 +Release: 1%{?dist} +Summary: hbase-packet-inspector monitors HBase packets + +Group: Development/Tools +License: Apache 2 +URL: https://github.com/kakao/hbase-packet-inspector +Source0: %{name}-%{version}.tar.gz + +Requires: libpcap >= 1.4.0 + +%define __jar_repack 0 + +%description +hbase-packet-inspector is a command-line tool for analyzing network traffic of +HBase RegionServers. + + +%prep +# Without -n, it expects %{name}-%{version} after extracting the tarball + +%setup -q -n %{name} + +%build +# Nothing to do + + +%install +install -m 0755 -d %{buildroot}/etc/init.d +install -m 0755 -d %{buildroot}/usr/lib/%{name} +install -m 0755 -d %{buildroot}/usr/lib/%{name}/lib +install -m 0755 -d %{buildroot}/usr/lib/%{name}/conf +install -m 0755 lib/%{name}.jar %{buildroot}/usr/lib/%{name}/lib/%{name}.jar +install -m 0755 init.d/%{name} %{buildroot}/etc/init.d/%{name} +install -m 0644 conf/log4j.properties %{buildroot}/usr/lib/%{name}/conf/log4j.properties +install -m 0644 conf/%{name}.properties %{buildroot}/usr/lib/%{name}/conf/%{name}.properties + + +%files +/etc/init.d/hbase-packet-inspector +%dir /usr/lib/%{name} +%dir /usr/lib/%{name}/lib +/usr/lib/%{name}/lib/%{name}.jar +%dir /usr/lib/%{name}/conf +/usr/lib/%{name}/conf/log4j.properties +/usr/lib/%{name}/conf/%{name}.properties