Skip to content

Commit

Permalink
Add Makefile for building RPM files for Centos
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Oct 10, 2017
1 parent 59cfc63 commit e3abd02
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions Dockerfile.centos6
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM centos:6
MAINTAINER Junegunn Choi <[email protected]>

RUN yum clean all && yum install -y rpm-build rpmdevtools createrepo

WORKDIR /root
6 changes: 6 additions & 0 deletions Dockerfile.centos7
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM centos:7
MAINTAINER Junegunn Choi <[email protected]>

RUN yum clean all && yum install -y rpm-build rpmdevtools createrepo

WORKDIR /root
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# kafka = bootstrap1:9092,bootstrap2:9092/hbase-traffic
device = eth0
7 changes: 7 additions & 0 deletions rpmbuild/SOURCES/hbase-packet-inspector/conf/log4j.properties
Original file line number Diff line number Diff line change
@@ -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
124 changes: 124 additions & 0 deletions rpmbuild/SOURCES/hbase-packet-inspector/init.d/hbase-packet-inspector
Original file line number Diff line number Diff line change
@@ -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 $?
47 changes: 47 additions & 0 deletions rpmbuild/SPECS/hbase-packet-inspector.spec
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e3abd02

Please sign in to comment.