Skip to content

Commit 2b62099

Browse files
author
Martin Cox
authored
Bring RPM packaging inline with DEB (#1024)
* Bring RPM build inline with DEB and include init script. * Changed rel target to build deps from rebar.lock - was previously calling rebar3 upgrade and ignoring lock. * Cleaned up some of the old packaging targets that are no longer used.
1 parent 4a408d5 commit 2b62099

File tree

7 files changed

+237
-93
lines changed

7 files changed

+237
-93
lines changed

Makefile

Lines changed: 9 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,15 @@ compile:
2828
$(REBAR) compile
2929

3030
deps:
31-
$(if $(HEAD_REVISION),$(warning "Warning: you have checked out a tag ($(HEAD_REVISION)) and should use the locked-deps target"))
32-
$(REBAR) get-deps
31+
$(if $(HEAD_REVISION),$(warning "Warning: you have checked out a tag ($(HEAD_REVISION)) and should use the compile target"))
32+
$(REBAR) upgrade
3333

3434
clean: testclean
3535
$(REBAR) clean
3636

3737
distclean: clean devclean relclean ballclean
3838
@rm -rf _build
3939

40-
locked-deps:
41-
$(REBAR) upgrade
42-
4340
##
4441
## Test targets
4542
##
@@ -75,14 +72,15 @@ test : testclean eunit test-deps
7572
##
7673
## Release targets
7774
##
78-
rel: locked-deps compile
75+
rel: compile
7976
$(REBAR) as rel release
8077
cp -a _build/rel/rel/riak rel/
8178

82-
rel-rpm: locked-deps compile
83-
$(REBAR) as rel,rpm release
79+
rel-rpm: compile
80+
$(REBAR) as rpm release
81+
cp -a _build/rpm/rel/riak rel/
8482

85-
rel-deb: locked-deps compile
83+
rel-deb: compile
8684
$(REBAR) as deb release
8785
cp -a _build/deb/rel/riak rel/
8886

@@ -214,46 +212,6 @@ REVISION = $(shell echo $(REPO_TAG) | sed -e 's/^$(REPO)-//')
214212
# Changes to 1.0.3 or 1.1.0pre1 from example above
215213
MAJOR_VERSION ?= $(shell echo $(REVISION) | sed -e 's/\([0-9.]*\)-.*/\1/')
216214

217-
218-
##
219-
## Release tarball creation
220-
## Generates a tarball that includes all the deps sources so no checkouts are necessary
221-
##
222-
223-
# Use git archive make a clean copy of a repository at a current
224-
# revision and copy to a new directory
225-
archive_git = git archive --format=tar --prefix=$(1)/ HEAD | (cd $(2) && tar xf -)
226-
227-
# Alternative to git archive to remove .git directory, but not any
228-
# other files outside of the source tree (used for eleveldb which
229-
# brings in leveldb)
230-
clean_git = cp -R ../../$(1) $(2)/deps/ && find $(2)/$(1) -name .git -type d | xargs rm -rf
231-
232-
# Determines which function to call. eleveldb is treated as a special case
233-
archive = if [ "$(1)" = "deps/eleveldb" ]; then \
234-
$(call clean_git,$(1),$(2)); \
235-
else \
236-
$(call archive_git,$(1),$(2)); \
237-
fi
238-
239-
240-
# Checkout tag, fetch deps (so we don't have to do it multiple times) and collect
241-
# the version of all the dependencies into the MANIFEST_FILE
242-
CLONEDIR ?= riak-clone
243-
MANIFEST_FILE ?= dependency_manifest.git
244-
get_dist_deps = mkdir distdir && \
245-
git clone . distdir/$(CLONEDIR) && \
246-
cd distdir/$(CLONEDIR) && \
247-
git checkout $(REPO_TAG) && \
248-
$(MAKE) locked-deps && \
249-
echo "- Dependencies and their tags at build time of $(REPO) at $(REPO_TAG)" > $(MANIFEST_FILE) && \
250-
for dep in deps/*; do \
251-
cd $${dep} && \
252-
printf "$${dep} version `git describe --long --tags 2>/dev/null || git rev-parse HEAD`\n" >> ../../$(MANIFEST_FILE) && \
253-
cd ../..; done && \
254-
LC_ALL=POSIX && export LC_ALL && sort $(MANIFEST_FILE) > $(MANIFEST_FILE).tmp && mv $(MANIFEST_FILE).tmp $(MANIFEST_FILE);
255-
256-
257215
# Name resulting directory & tar file based on current status of the git tag
258216
# If it is a tagged release (PKG_VERSION == MAJOR_VERSION), use the toplevel
259217
# tag as the package name, otherwise generate a unique hash of all the
@@ -263,41 +221,6 @@ get_dist_deps = mkdir distdir && \
263221
NAME_HASH = $(shell git hash-object distdir/$(CLONEDIR)/$(MANIFEST_FILE) 2>/dev/null | cut -c 1-8)
264222
PKG_ID := $(REPO_TAG)
265223

266-
# To ensure a clean build, copy the CLONEDIR at a specific tag to a new directory
267-
# which will be the basis of the src tar file (and packages)
268-
# The vsn.git file is required by rebar to be able to build from the resulting
269-
# tar file
270-
build_clean_dir = cd distdir/$(CLONEDIR) && \
271-
$(call archive_git,$(PKG_ID),..) && \
272-
cp $(MANIFEST_FILE) ../$(PKG_ID)/ && \
273-
mkdir ../$(PKG_ID)/deps && \
274-
for dep in deps/*; do \
275-
cd $${dep} && \
276-
$(call archive,$${dep},../../../$(PKG_ID)) && \
277-
mkdir -p ../../../$(PKG_ID)/$${dep}/priv && \
278-
printf "`git describe --long --tags 2>/dev/null || git rev-parse HEAD`" > ../../../$(PKG_ID)/$${dep}/priv/vsn.git && \
279-
cd ../..; \
280-
done
281-
282-
283-
distdir/$(CLONEDIR)/$(MANIFEST_FILE):
284-
$(if $(REPO_TAG), $(call get_dist_deps), $(error "You can't generate a release tarball from a non-tagged revision. Run 'git checkout <tag>', then 'make dist'"))
285-
286-
distdir/$(PKG_ID): distdir/$(CLONEDIR)/$(MANIFEST_FILE)
287-
$(call build_clean_dir)
288-
289-
distdir/$(PKG_ID).tar.gz: distdir/$(PKG_ID)
290-
tar -C distdir -czf distdir/$(PKG_ID).tar.gz $(PKG_ID)
291-
292-
dist: distdir/$(PKG_ID).tar.gz
293-
cp distdir/$(PKG_ID).tar.gz .
294-
295-
ballclean:
296-
rm -rf $(PKG_ID).tar.gz distdir
297-
298-
pkgclean: ballclean
299-
rm -rf package
300-
301224
##
302225
## Packaging targets
303226
##
@@ -319,10 +242,10 @@ packageclean:
319242
export PKG_VERSION PKG_ID PKG_BUILD BASE_DIR ERLANG_BIN REBAR OVERLAY_VARS RELEASE
320243

321244
# Package up a devrel to save time later rebuilding it
322-
pkg-devrel: locked-deps devrel
245+
pkg-devrel: devrel
323246
echo -n $(PKG_REVISION) > VERSION
324247
tar -czf $(PKG_ID)-devrel.tar.gz dev/ VERSION
325248
rm -rf VERSION
326249

327-
pkg-rel: locked-deps rel
250+
pkg-rel: rel
328251
tar -czf $(PKG_ID)-rel.tar.gz -C rel/ .

rebar.config

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@
125125
]},
126126
{rpm, [
127127
{relx, [
128-
{overlay_vars, "rpm.vars.config"},
128+
{overlay_vars, "rel/pkg/rpm/vars.config"},
129129
{overlay, [
130130

131+
]},
132+
{overlay, [
133+
{template, "rel/files/riak", "usr/bin/riak"},
134+
{template, "rel/files/riakpre", "usr/bin/riakpre"},
135+
{template, "rel/files/riakrun", "usr/bin/riakrun"},
136+
{template, "rel/pkg/rpm/init.script", "etc/init.d/init.script"}
131137
]},
132138
{extended_start_script_hooks,
133139
[{pre_start,

rebar.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
2},
127127
{<<"riak_kv">>,
128128
{git,"git://github.com/basho/riak_kv.git",
129-
{ref,"56528b78d9b8a7f6560f3b7c48e426a530dec78b"}},
129+
{ref,"ccd1e369500b96f27dbfcc65d3de9ab0b0ac8846"}},
130130
0},
131131
{<<"riak_pb">>,
132132
{git,"git://github.com/basho/riak_pb.git",

rel/pkg/rpm/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ default:
1515
--define "_revision $(PKG_VERSION)" \
1616
--define "_version $(PKG_VERSION_NO_H)" \
1717
--define "_release $(PKG_BUILD)" \
18-
--define "_tarname riak-$(PKG_ID).tar.gz" \
19-
--define "_tarname_base riak-$(PKG_ID)" \
20-
-ba specfile
18+
--define "_tarname $(PKG_ID).tar.gz" \
19+
--define "_tarname_base $(PKG_ID)" \
20+
-ba $(BASE_DIR)/rel/pkg/rpm/specfile
2121
cd $(BASE_DIR)/rel/pkg/out/packages && \
2222
for rpmfile in *.rpm; do \
2323
sha256sum $${rpmfile} > $${rpmfile}.sha \

rel/pkg/rpm/init.script

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#!/bin/sh
2+
#
3+
# riak
4+
#
5+
# chkconfig: 2345 80 30
6+
# description: Riak KV Database
7+
# processname: beam
8+
#
9+
10+
# Source function library.
11+
. /etc/rc.d/init.d/functions
12+
13+
RETVAL=0
14+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
15+
DESC="Riak KV Database"
16+
NAME=riak
17+
DAEMON=/usr/bin/$NAME
18+
lockfile=/var/lock/subsys/$NAME
19+
pidfile=/var/run/$NAME/$NAME.pid
20+
21+
# Check for script, config and data dirs
22+
[ -x /usr/bin/$NAME ] || exit 0
23+
[ -d /etc/$NAME ] || exit 0
24+
[ -d /var/lib/$NAME ] || exit 0
25+
26+
# Read configuration variable file if it is present and readable
27+
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
28+
29+
# `service` strips all environmental VARS so
30+
# if no HOME was set in /etc/sysconfig/$NAME then set one here
31+
# to the data directory for erlexec's sake
32+
if [ -z "$HOME" ]; then
33+
export HOME={{platform_data_dir}}
34+
fi
35+
36+
status -p $pidfile -l $(basename $lockfile) $NAME >/dev/null 2>&1
37+
running=$?
38+
39+
check_pid_status() {
40+
pid=$(ps ax | grep beam.smp | grep "\-progname $NAME " | awk '{print $1}')
41+
if [ "$pid" = "" ]; then
42+
# prog not running?
43+
return 1
44+
else
45+
# running
46+
return 0
47+
fi
48+
}
49+
50+
start() {
51+
# Start daemons.
52+
echo -n $"Starting riak: "
53+
$DAEMON start
54+
RETVAL=$?
55+
if [ $RETVAL -eq 0 ]; then
56+
touch $lockfile
57+
success
58+
else
59+
failure $"$NAME start"
60+
fi
61+
echo
62+
return $RETVAL
63+
}
64+
65+
stop() {
66+
# Stop daemon.
67+
echo -n $"Shutting down riak: "
68+
$DAEMON stop 2>/dev/null
69+
for n in $(seq 1 10); do
70+
sleep 1
71+
check_pid_status
72+
RETVAL=$?
73+
if [ $RETVAL -eq 1 ]; then
74+
break
75+
fi
76+
done
77+
if [ $RETVAL -eq 1 ]; then
78+
rm -f $lockfile $pidfile
79+
success
80+
echo && return 0
81+
else
82+
failure $"$NAME stop"
83+
echo && return 1
84+
fi
85+
}
86+
87+
hardstop() {
88+
echo -n $"Shutting down $NAME: "
89+
su - riak -c "ps -ef | grep beam.smp | grep '\-progname $NAME ' | grep -v grep | awk '{print \$2}' | xargs kill -9"
90+
for n in $(seq 1 10); do
91+
sleep 1
92+
check_pid_status
93+
RETVAL=$?
94+
if [ $RETVAL -eq 1 ]; then
95+
break
96+
fi
97+
done
98+
if [ $RETVAL -eq 1 ]; then
99+
rm -f $lockfile $pidfile
100+
success
101+
echo && return 0
102+
else
103+
failure $"$NAME hardstop"
104+
echo && return 1
105+
fi
106+
}
107+
108+
# See how we were called.
109+
case "$1" in
110+
start)
111+
[ $running -eq 0 ] && exit 0
112+
start
113+
;;
114+
stop)
115+
if [ $running -eq 0 ]; then
116+
stop
117+
else
118+
check_pid_status
119+
RETVAL=$?
120+
if [ $RETVAL -eq 1 ]; then
121+
rm -f $lockfile $pidfile
122+
fi
123+
exit 0
124+
fi
125+
;;
126+
restart|force-reload)
127+
[ $running -eq 0 ] && stop
128+
start
129+
;;
130+
hardstop)
131+
[ $running -eq 0 ] || exit 0
132+
hardstop
133+
;;
134+
condrestart|try-restart)
135+
[ $running -eq 0 ] || exit 0
136+
restart
137+
;;
138+
status)
139+
status -p $pidfile -l $(basename $lockfile) $NAME
140+
;;
141+
ping)
142+
$DAEMON ping || exit $?
143+
;;
144+
*)
145+
echo $"Usage: $0 {start|stop|restart|force-reload|hardstop|condrestart|try-restart|status|ping}"
146+
exit 1
147+
esac
148+
149+
exit $?

rel/pkg/rpm/specfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ EOF
6464
make rel-rpm
6565

6666
%install
67-
%define relpath %{_builddir}/%{buildsubdir}/_build/rel+rpm/rel/riak
67+
%define relpath %{_builddir}/%{buildsubdir}/_build/rpm/rel/riak
6868
%define buildroot_lib %{buildroot}%{_libdir}/riak
6969
%define buildroot_etc %{buildroot}%{_sysconfdir}/riak
7070
%define buildroot_bin %{buildroot_lib}/bin
@@ -88,12 +88,17 @@ if [ -d %{relpath}/bin ]; then \
8888
fi
8989

9090
cp %{relpath}/usr/bin/riak %{buildroot}%{_bindir}
91+
cp %{relpath}/usr/bin/riakpre %{buildroot}%{_bindir}
92+
cp %{relpath}/usr/bin/riakrun %{buildroot}%{_bindir}
9193
cp -R %{relpath}/etc/* %{buildroot_etc}
9294

9395
mkdir -p %{buildroot}%{_localstatedir}/lib/riak
9496
cp -R %{relpath}/data/* \
9597
%{buildroot}%{_localstatedir}/lib/riak
9698

99+
mkdir -p %{buildroot}%{_sysconfdir}/init.d
100+
install -m755 %{relpath}/etc/init.d/init.script %{buildroot}%{_sysconfdir}/init.d/riak
101+
97102
# Needed to work around check-rpaths which seems to be hardcoded into recent
98103
# RPM releases
99104
export QA_RPATHS=3
@@ -142,9 +147,10 @@ exit 0
142147
%{_localstatedir}/log/riak
143148
%{_libdir}/*
144149
%defattr(-,root,root)
150+
%{_sysconfdir}/init.d/riak
145151
%dir %{_sysconfdir}/riak
146152
/usr/bin/*
147153
%config(noreplace) %{_sysconfdir}/riak/*
148154

149155
%clean
150-
#rm -rf %{buildroot}
156+
rm -rf %{buildroot}

0 commit comments

Comments
 (0)