From ff0053b9fe702bd600aea85444afa9f2c5c3b388 Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Mon, 17 Jun 2013 14:36:27 +0000 Subject: [PATCH 1/2] Add spec and `make rpm` script for RHEL rpm build --- Makefile | 14 +++++++++ rhel/stud.spec | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 rhel/stud.spec diff --git a/Makefile b/Makefile index eba3e9c..b013ac4 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ BINDIR = $(PREFIX)/bin MANDIR = $(PREFIX)/share/man CFLAGS = -O2 -g -std=c99 -fno-strict-aliasing -Wall -W -D_GNU_SOURCE -I/usr/local/include +CFLAGS += -I/usr/include/libev LDFLAGS = -lssl -lcrypto -lev -L/usr/local/lib OBJS = stud.o ringbuffer.o configuration.o @@ -48,5 +49,18 @@ install: $(ALL) clean: rm -f stud $(OBJS) +GIT_VERSION=$(shell git describe) +VERSION_MAJOR=$(firstword $(subst -, ,$(GIT_VERSION))) +TMPDIR=$(shell pwd)/.rpmbuild + +rpm: + mkdir -p ${TMPDIR}/{BUILD,RPMS,SOURCES,SPECS,SRPMS} + git archive HEAD . --prefix=stud-$(VERSION_MAJOR)/ \ + > ${TMPDIR}/SOURCES/stud-source.tar + sed -re s/GIT_VERSION/$(shell git describe)/ \ + rhel/stud.spec > ${TMPDIR}/SPECS/stud.spec + rpmbuild --define "_topdir ${TMPDIR}" \ + -bb ${TMPDIR}/SPECS/stud.spec + find ${TMPDIR}/RPMS/ -type f -name "*.rpm" -exec mv {} . \; .PHONY: all realall diff --git a/rhel/stud.spec b/rhel/stud.spec new file mode 100644 index 0000000..9898b58 --- /dev/null +++ b/rhel/stud.spec @@ -0,0 +1,84 @@ +# The GIT_VERSION token below is automatically changed to the value of +# `git describe` by the top-level Makefile's "rpm" build target +%define git_version GIT_VERSION +# +# The git version is -#-sha1, where the is the most recent +# annotated git tag, # is the number of commits since the tag, and the +# sha1 is 'g' plus the first 7 chars of the most recent commit sha1-id +# on the branch being compiled +# +# This will split the version information back into the (version) +# and the #-sha1 (post_tag) parts +# +%define version %(echo %{git_version} | cut -d- -f1) +%define post_tag %(echo %{git_version} | cut -s -d- -f2- | sed -e s/-/_/g) +%if x%{post_tag} == "x" + %undefine post_tag +%endif + +Name: stud +Version: %{version} +Release: %{?post_tag}%{!?post_tag:1}%{?dist} +Summary: The Scalable TLS Unwrapping Daemon + +Group: Productivity/Networking/Web/Proxy +License: BSD +URL: https://github.com/bumptech/stud +Source0: stud-source.tar + +BuildRequires: libev-devel +Requires: libev openssl + +%description +stud is a network proxy that terminates TLS/SSL connections and forwards the +unencrypted traffic to some backend. It's designed to handle 10s of +thousands of connections efficiently on multicore machines. + +%prep +%setup -q + + +%build +make %{?_smp_mflags} + + +%install +rm -rf %{buildroot} +make install DESTDIR=%{buildroot} PREFIX=/usr +install -d %{buildroot}/etc/init.d +install init.stud %{buildroot}/etc/init.d/stud + +%clean +rm -rf %{buildroot} + + +%files +%defattr(-,root,root,-) +/usr/bin/stud +/etc/init.d/stud +%doc +/usr/share/man/man8 + + +%preun +if [ "$1" = "0" ]; then + service stud stop 2>/dev/null + true +fi + +%postun +if [ "$1" = "0" ]; then + # remove rundir + rm -rf /var/run/stud >/dev/null 2>&1 + + # remove config dir + rm -rf /etc/stud >/dev/null 2>&1 +fi + +%post +mkdir -p /var/run/stud +mkdir -p /etc/stud + + +%changelog + From a0910c3693c1a57ada8448dd32d676319f7bd630 Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Sat, 6 Jul 2013 13:41:54 +0000 Subject: [PATCH 2/2] Add USE_SHARED_CACHE option to `make rpm` The spec file can be build directly with the shared cache feature with `rpmbuild ... --with cache` --- Makefile | 2 +- rhel/stud.spec | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b013ac4..5941712 100644 --- a/Makefile +++ b/Makefile @@ -60,7 +60,7 @@ rpm: sed -re s/GIT_VERSION/$(shell git describe)/ \ rhel/stud.spec > ${TMPDIR}/SPECS/stud.spec rpmbuild --define "_topdir ${TMPDIR}" \ - -bb ${TMPDIR}/SPECS/stud.spec + -bb ${TMPDIR}/SPECS/stud.spec $(if $(USE_SHARED_CACHE),--with cache,) find ${TMPDIR}/RPMS/ -type f -name "*.rpm" -exec mv {} . \; .PHONY: all realall diff --git a/rhel/stud.spec b/rhel/stud.spec index 9898b58..f5a288a 100644 --- a/rhel/stud.spec +++ b/rhel/stud.spec @@ -16,6 +16,9 @@ %undefine post_tag %endif +# Use --with cache to build the RPM with the USE_SHARED_CACHE feature +%bcond_with cache + Name: stud Version: %{version} Release: %{?post_tag}%{!?post_tag:1}%{?dist} @@ -36,15 +39,18 @@ thousands of connections efficiently on multicore machines. %prep %setup -q - +%if %{with cache} +mkdir ebtree +curl http://1wt.eu/tools/ebtree/ebtree-6.0.8.tar.gz | tar xzf - -C "ebtree" --strip 1 +%endif %build -make %{?_smp_mflags} +make %{?_smp_mflags} %{?_with_cache:USE_SHARED_CACHE=1} %install rm -rf %{buildroot} -make install DESTDIR=%{buildroot} PREFIX=/usr +make install DESTDIR=%{buildroot} PREFIX=/usr %{?_with_cache:USE_SHARED_CACHE=1} install -d %{buildroot}/etc/init.d install init.stud %{buildroot}/etc/init.d/stud