diff --git a/Makefile b/Makefile index 65abe29cf..ba2bf658e 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,9 @@ test : test-deps rel: locked-deps compile $(REBAR) as rel release +rel-rpm: locked-deps compile + $(REBAR) as rpm release + relclean: rm -rf $(REL_DIR) rm -rf rel/riak @@ -256,11 +259,7 @@ get_dist_deps = mkdir distdir && \ # This enables the toplevel repository package to change names # when underlying dependencies change. NAME_HASH = $(shell git hash-object distdir/$(CLONEDIR)/$(MANIFEST_FILE) 2>/dev/null | cut -c 1-8) -ifeq ($(REVISION), $(MAJOR_VERSION)) PKG_ID := $(REPO_TAG) -else -PKG_ID = $(REPO)-$(MAJOR_VERSION)-$(NAME_HASH) -endif # To ensure a clean build, copy the CLONEDIR at a specific tag to a new directory # which will be the basis of the src tar file (and packages) @@ -305,9 +304,13 @@ pkgclean: ballclean # which differs from $REVISION that is repo-- PKG_VERSION = $(shell echo $(PKG_ID) | sed -e 's/^$(REPO)-//') -package: distdir/$(PKG_ID).tar.gz - ln -s distdir package - $(MAKE) -C package -f $(PKG_ID)/deps/node_package/Makefile +package: + git archive --format=tar HEAD | gzip >rel/pkg/out/riak-3.0.tar.gz + $(MAKE) -C rel/pkg/ -f Makefile + +packageclean: + rm -rf rel/pkg/out/* + .PHONY: package export PKG_VERSION PKG_ID PKG_BUILD BASE_DIR ERLANG_BIN REBAR OVERLAY_VARS RELEASE diff --git a/rebar.config b/rebar.config index 9860dde90..64001f14c 100644 --- a/rebar.config +++ b/rebar.config @@ -20,7 +20,7 @@ ]}. {project_plugins, [ - {rebar3_cuttlefish, {git, "https://github.com/martincox/rebar3_cuttlefish", {branch, "fix/output-dir-awareness"}}} + {rebar3_cuttlefish, {git, "https://github.com/martincox/rebar3_cuttlefish", {branch, "fix/runner_dirs"}}} ]}. {cuttlefish, [ @@ -69,11 +69,13 @@ yokozuna, riak_auth_mods]}, + {overlay_vars, "rel/vars.config"}, {dev_mode, false}, {include_erts, true}, {overlay, [ - {mkdir, "lib/riak-patches"}, + {mkdir, "lib/patches"}, + {mkdir, "data/ring"}, {template, "rel/files/advanced.config", "etc/advanced.config"}, @@ -111,14 +113,22 @@ {dialyzer, [{plt_apps, all_deps}]}. {profiles, [ - {rel, [ + {dev, [ {relx, [ - {overlay_vars, "rel/vars.config"} + {dev_mode, true} ]} ]}, - {dev, [ + {rpm, [ {relx, [ - {dev_mode, true} + {overlay_vars, "rpm.vars.config"}, + {overlay, [ + {template, "rel/pkg/rpm/riak", "usr/bin/riak"} + ]} + ]} + ]}, + {deb, [ + {relx, [ + {overlay_vars, "deb.vars.config"} ]} ]} ]}. diff --git a/rel/pkg/Makefile b/rel/pkg/Makefile new file mode 100644 index 000000000..81bf3c246 --- /dev/null +++ b/rel/pkg/Makefile @@ -0,0 +1,91 @@ +## +## Export all variables to sub-invocation +## +export + +OS = $(shell uname -s) +ERLANG_BIN ?= $(shell dirname $(shell which erl)) +DEPS_DIR ?= deps + +## +## Support RPM and Debian based linux systems +## +ifeq ($(OS),Linux) +ARCH = $(shell uname -m) +ISRPM = $(shell cat /etc/redhat-release 2> /dev/null) +ISDEB = $(shell cat /etc/debian_version 2> /dev/null) +ISSLES = $(shell cat /etc/SuSE-release 2> /dev/null) +ifneq ($(ISRPM),) +OSNAME = RedHat +PKGERDIR = rpm +BUILDDIR = rpmbuild +else +ifneq ($(ISDEB),) +OSNAME = Debian +PKGERDIR = deb +BUILDDIR = debuild +else +ifneq ($(ISSLES),) +OSNAME = SLES +PKGERDIR = rpm +BUILDDIR = rpmbuild +endif # SLES +endif # deb +endif # rpm +endif # linux + +ifeq ($(OS),Darwin) # OSX +OSNAME = OSX +ARCH = $(shell file `which erlc` | grep -c x86_64 2> /dev/null | awk \ + '{if ($$1 == "0") {print "i386"} else {print "x86_64"}}') +PKGERDIR = osx +BUILDDIR = osxbuild +endif + +ifeq ($(OS),FreeBSD) +OSNAME = FreeBSD +ARCH = $(shell uname -m) +BUILDDIR = fbsdbuild +PKGNG = $(shell uname -r | awk -F. '{ print ($$1 > 9) ? "true" : "false" }') +ifeq ($(PKGNG),true) # FreeBSD 10.0 or greater +PKGERDIR = fbsdng +else # Older FreeBSD pkg_add +PKGERDIR = fbsd +endif +endif + +ifeq ($(OS),SunOS) # Solaris flavors +KERNELVER = $(shell uname -v | grep -c joyent 2> /dev/null) +ARCH = $(shell file `which erlc` | grep -c 64-bit 2> /dev/null | awk \ + '{if ($$1 == "0") {print "i386"} else {print "x86_64"}}') + +ifneq ($(KERNELVER),0) # SmartOS +OSNAME = SmartOS +PKGERDIR = smartos +BUILDDIR = smartosbuild +else # Solaris / OmniOS +DISTRO = $(shell head -1 /etc/release|awk \ + '{if ($$1 == "OmniOS") {print $$1} else {print "Solaris"}}') +OSNAME = ${DISTRO} +PKGERDIR = solaris +BUILDDIR = solarisbuild +endif + +endif + +DATE = $(shell date +%Y-%m-%d) + +# Default the package build version to 1 if not already set +PKG_BUILD ?= 1 + +.PHONY: ostype varcheck + +## Call platform dependent makefile +ostype: varcheck + $(if $(PKGERDIR),,$(error "Operating system '$(OS)' not supported by node_package")) + $(MAKE) -C $(PKGERDIR) -f Makefile + +## Check required settings before continuing +varcheck: + $(if $(PKG_VERSION),,$(error "Variable PKG_VERSION must be set and exported, see basho/node_package readme")) + $(if $(PKG_ID),,$(error "Variable PKG_ID must be set and exported, see basho/node_package readme")) diff --git a/rel/pkg/deb/Makefile b/rel/pkg/deb/Makefile new file mode 100644 index 000000000..79fda8215 --- /dev/null +++ b/rel/pkg/deb/Makefile @@ -0,0 +1,19 @@ + +default: + ln -sf $(PKG_ID).tar.gz ../{{package_name}}_$(PKG_VERSION).orig.tar.gz + export DEBFULLNAME="{{vendor_contact_name}}"; \ + export DEBEMAIL="{{vendor_contact_email}}"; \ + dch --create --package {{package_name}} -v "$(PKG_VERSION)-$(PKG_BUILD)" \ + "Build from $(PKG_VERSION)";\ + debuild --prepend-path=$(ERLANG_BIN) \ + -e REVISION=$(PKG_VERSION) \ + -e RELEASE=$(PKG_BUILD) \ + -e REBAR=$(REBAR) \ + {{debuild_extra_options}} \ + -uc -us + mkdir -p ../packages + cd .. && mv *$(PKG_VERSION)-$(PKG_BUILD)_*.deb packages + cd ../packages && \ + for debfile in *.deb; do \ + sha256sum $${debfile} > $${debfile}.sha \ + ; done diff --git a/rel/pkg/deb/compat b/rel/pkg/deb/compat new file mode 100644 index 000000000..7f8f011eb --- /dev/null +++ b/rel/pkg/deb/compat @@ -0,0 +1 @@ +7 diff --git a/rel/pkg/deb/control b/rel/pkg/deb/control new file mode 100644 index 000000000..37090553f --- /dev/null +++ b/rel/pkg/deb/control @@ -0,0 +1,16 @@ +Source: {{package_name}} +Section: net +Priority: extra +Maintainer: {{vendor_contact_name}} <{{vendor_contact_email}}> +Build-Depends: debhelper (>= 7) +Standards-Version: 3.9.3 +Homepage: {{vendor_url}} + +Package: {{package_name}} +Architecture: any +Depends: ${misc:Depends}, ${shlibs:Depends}, adduser, logrotate, sudo, {{deb_depends}} +Homepage: {{vendor_url}} +Description: {{package_shortdesc}} + {{package_desc}} +{{package_replacement_line}} +{{package_conflicts_line}} diff --git a/rel/pkg/deb/copyright b/rel/pkg/deb/copyright new file mode 100644 index 000000000..d02cb9889 --- /dev/null +++ b/rel/pkg/deb/copyright @@ -0,0 +1,8 @@ +Format: http://dep.debian.net/deps/dep5 +Upstream-Name: {{package_name}} +Upstream-Contact: {{vendor_contact_name}} <{{vendor_contact_email}}> + +Files: * +Copyright: {{copyright}} +License: {{license_type}} + {{license_full_text}} diff --git a/rel/pkg/deb/deb.template b/rel/pkg/deb/deb.template new file mode 100644 index 000000000..1f0c07c13 --- /dev/null +++ b/rel/pkg/deb/deb.template @@ -0,0 +1,41 @@ +%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% +{variables, [ + {package_name, "package_name"}, + {package_install_name, "package_install_name"}, + {package_install_user, "package_install_user"}, + {package_install_user_desc, "package_install_user_desc"}, + {package_install_group, "package_install_group"}, + {package_replacement_line, "{{package_replacement_line_debian}}"}, + {package_conflicts_line, "{{package_conflicts_line_debian}}"}, + {vendor_name, "vendor_name"}, + {vendor_url, "vendor_url"}, + {vendor_contact_name, "vendor_contact_name"}, + {vendor_contact_email, "vendor_contact_email"}, + {copyright, "copyright"}, + {license_type, "license_type"}, + {license_full_text, ""}, + {bin_or_sbin, "bin"}, + + %% Platform Specific Settings + {platform_bin_dir, "/usr/{{bin_or_sbin}}"}, + {platform_data_dir, "/var/lib/{{package_install_name}}"}, + {platform_etc_dir, "/etc/{{package_install_name}}"}, + {platform_base_dir, "/usr/lib/{{package_install_name}}"}, + {platform_lib_dir, "/usr/lib/{{package_install_name}}/lib"}, + {platform_log_dir, "/var/log/{{package_install_name}}"} + ] +}. +{template, "Makefile", "Makefile"}. +{template, "compat", "compat"}. +{template, "control", "control"}. +{template, "copyright", "copyright"}. +{template, "dirs", "dirs"}. +{template, "install", "install"}. +{template, "postinst", "postinst"}. +{template, "postrm", "postrm"}. +{template, "rules", "rules"}. +{template, "vars.config", "vars.config"}. +{template, "init.script", "{{package_name}}.{{package_install_name}}.init"}. +{template, "package.service", "{{package_name}}.{{package_install_name}}.service"}. +{template, "package.manpages", "{{package_name}}.manpages"}. diff --git a/rel/pkg/deb/dirs b/rel/pkg/deb/dirs new file mode 100644 index 000000000..3220e0d31 --- /dev/null +++ b/rel/pkg/deb/dirs @@ -0,0 +1,2 @@ +etc/logrotate.d +var/log/{{package_install_name}} diff --git a/rel/pkg/deb/init.script b/rel/pkg/deb/init.script new file mode 100755 index 000000000..c0fbd9055 --- /dev/null +++ b/rel/pkg/deb/init.script @@ -0,0 +1,152 @@ +#! /bin/bash +### BEGIN INIT INFO +# Provides: {{package_name}} +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: {{package_shortdesc}} +# Description: {{package_desc}} +### END INIT INFO + +NAME={{package_install_name}} +DAEMON=/usr/{{bin_or_sbin}}/$NAME +SCRIPTNAME=/etc/init.d/$NAME +RUNDIR=/var/run/$NAME + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh +. /lib/lsb/init-functions + +# `service` strips all environmental VARS so +# if no HOME was set in /etc/default/$NAME then set one here +# to the data directory for erlexec's sake +if [ -z "$HOME" ]; then + export HOME={{platform_data_dir}} +fi + +# +# Function that starts the daemon/service +# +do_start() +{ + if [ ! -d $RUNDIR ]; then + mkdir $RUNDIR + chown {{package_install_user}}:{{package_install_group}} $RUNDIR + fi + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + + # Startup with the appropriate user + start-stop-daemon --start \ + --name {{package_install_name}} \ + --user {{package_install_user}} \ + --exec $DAEMON -- start \ + || return 2 +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Identify the erts directory + ERTS_PATH=`$DAEMON ertspath` + + # Attempt a clean shutdown. + $DAEMON stop + + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + # Make sure it's down by using a more direct approach + start-stop-daemon --stop \ + --quiet \ + --retry=TERM/30/KILL/5 \ + --user {{package_install_user}} \ + --exec $ERTS_PATH/run_erl + return $? +} + +# +# Function that graceful reload the daemon/service +# +do_reload() { + # Restart the VM without exiting the process + $DAEMON restart && return $? || return 2 +} + +# Checks the status of a node +do_status() { + $DAEMON ping && echo $"$NAME is running" && return 0 + echo $"$NAME is stopped" && return 2 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $NAME" + $DAEMON ping >/dev/null 2>&1 && echo $"$NAME is already running" && exit 0 + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 + exit 1 + ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 + exit 1 + ;; + esac + ;; + ping) + # See if the VM is alive + $DAEMON ping || exit $? + ;; + reload|force-reload) + log_daemon_msg "Reloading $NAME" + do_reload + ES=$? + log_end_msg $ES + exit $ES + ;; + restart) + log_daemon_msg "Restarting $NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 && exit 1 ;; # Old process is still running + *) log_end_msg 1 && exit 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 && exit 1 + ;; + esac + ;; + status) + do_status && exit 0 || exit $? + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|ping|restart|force-reload|status}" >&2 + exit 3 + ;; +esac + +: diff --git a/rel/pkg/deb/install b/rel/pkg/deb/install new file mode 100644 index 000000000..5f314b5f2 --- /dev/null +++ b/rel/pkg/deb/install @@ -0,0 +1,10 @@ +rel/{{package_install_name}}/lib usr/lib/{{package_install_name}} +rel/{{package_install_name}}/erts* usr/lib/{{package_install_name}} +rel/{{package_install_name}}/releases usr/lib/{{package_install_name}} + +{{#package_commands}} +rel/{{package_install_name}}/bin/{{name}} usr/{{bin_or_sbin}} +{{/package_commands}} + +rel/{{package_install_name}}/etc/* etc/{{package_install_name}} +rel/{{package_install_name}}/data/* var/lib/{{package_install_name}} \ No newline at end of file diff --git a/rel/pkg/deb/package.manpages b/rel/pkg/deb/package.manpages new file mode 100644 index 000000000..e3db37c1b --- /dev/null +++ b/rel/pkg/deb/package.manpages @@ -0,0 +1 @@ +doc/man/man1/*.1.gz \ No newline at end of file diff --git a/rel/pkg/deb/package.service b/rel/pkg/deb/package.service new file mode 100644 index 000000000..751414252 --- /dev/null +++ b/rel/pkg/deb/package.service @@ -0,0 +1,14 @@ +[Unit] +Description={{package_shortdesc}} + +[Service] +ExecStart=/usr/{{bin_or_sbin}}/{{package_install_name}} start +ExecStop=/usr/{{bin_or_sbin}}/{{package_install_name}} stop +User={{package_install_user}} +Type=forking +PIDFile=/var/run/{{package_install_name}}/{{package_install_name}}.pid +EnvironmentFile=-/etc/default/{{package_install_name}} +RuntimeDirectory={{package_install_name}} + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/rel/pkg/deb/postinst b/rel/pkg/deb/postinst new file mode 100755 index 000000000..88f272a5f --- /dev/null +++ b/rel/pkg/deb/postinst @@ -0,0 +1,44 @@ +#!/bin/sh +# postinst script for {{package_name}} +# +# see: dh_installdeb(1) + +set -e + +# create group +if ! getent group {{package_install_group}} >/dev/null; then + addgroup --system {{package_install_group}} +fi + +# create user +if ! getent passwd {{package_install_user}} >/dev/null; then + adduser --ingroup {{package_install_group}} \ + --home /var/lib/{{package_install_name}} \ + --disabled-password \ + --system --shell /bin/bash --no-create-home \ + --gecos "{{package_install_user_desc}}" {{package_install_user}} +fi + +for i in lib log; do + chown -R {{package_install_user}}:{{package_install_group}} /var/$i/{{package_install_name}} +done + +case "$1" in + configure) + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/rel/pkg/deb/postrm b/rel/pkg/deb/postrm new file mode 100755 index 000000000..df83a1fb8 --- /dev/null +++ b/rel/pkg/deb/postrm @@ -0,0 +1,61 @@ +#!/bin/sh +# postrm script for {{package_name}} +# +# see: dh_installdeb(1) + + +# summary of how this script can be called: +# * `remove' +# * `purge' +# * `upgrade' +# * `failed-upgrade' +# * `abort-install' +# * `abort-install' +# * `abort-upgrade' +# * `disappear' +# +# for details, see http://www.debian.org/doc/debian-policy/ or +# the debian-policy package + +set -e + +case "$1" in + purge) + rm -f /etc/default/{{package_install_name}} + if [ -d /var/log/{{package_install_name}} ]; then + rm -r /var/log/{{package_install_name}} + fi + if [ -d /var/run/{{package_install_name}} ]; then + rm -r /var/run/{{package_install_name}} + fi + if [ -d /etc/{{package_install_name}} ]; then + rm -r /etc/{{package_install_name}} + fi + if [ -e /etc/init.d/{{package_install_name}} ]; then + rm /etc/init.d/{{package_install_name}} + fi + # Remove User & Group, killing any process owned by them + if getent passwd {{package_install_user}} >/dev/null; then + pkill -u {{package_install_user}} || true + deluser --quiet --system {{package_install_user}} + fi + if getent group {{package_install_group}} >/dev/null; then + delgroup --quiet --system --only-if-empty {{package_install_group}} || true + fi + ;; + + remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) + ;; + + *) + echo "postrm called with unknown argument \`$1\`" >&2 + exit 1 + ;; +esac + +# dh_installdeb will replace this with shell code automatically +# generated by other debhelper scripts. + +#DEBHELPER# + +exit 0 diff --git a/rel/pkg/deb/rules b/rel/pkg/deb/rules new file mode 100755 index 000000000..d06fee81f --- /dev/null +++ b/rel/pkg/deb/rules @@ -0,0 +1,63 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# modified for node_package by dizzyd@basho.com and jared@basho.com + +# Uncomment this to turn on verbose mode. +export DH_VERBOSE=1 + +ROOTDIR := debian/{{package_name}} + +## Clear variables that may confound our build of sub-projects; also +## note that it is necessary to use overlay_vars relative to .. as +## the generate command EXECUTES in rel/ +build: + unset CC CFLAGS CPPFLAGS LDFLAGS CXX CXXFLAGS \ + && OVERLAY_VARS="overlay_vars=../debian/vars.config" make rel + touch build + +clean: + dh_clean + rm -f build + make clean + +## dh_shlibdeps was added to figure out the dependencies on shared libraries +## and will populate the ${shlibs:Depends} callout in the control file +install: LIBDIR := $(ROOTDIR)/usr/lib/{{package_install_name}} +install: build + dh_testdir + dh_testroot + dh_prep + dh_installdirs + dh_install + dh_installman + dh_installinit --name={{package_install_name}} --no-start + dh_fixperms + chmod 0755 $(ROOTDIR)/etc/{{package_install_name}} + chmod -R a+rX $(ROOTDIR)/etc/{{package_install_name}} + for file in lib/env.sh lib/app_epath.sh erts-*/bin/nodetool; do \ + if [ -f $(LIBDIR)/$$file ]; then \ + chmod 0755 $(LIBDIR)/$$file; \ + fi; \ + done + chmod -R go+rX debian/{{package_name}}/usr/lib/{{package_install_name}}/lib/ + dh_shlibdeps + +# We have nothing to do by default. +binary-indep: install build-stamp +build-stamp: + +# Build architecture-dependent files here. +binary-arch: install + dh_strip -a + dh_compress -a + dh_installdeb + dh_gencontrol + dh_builddeb + +binary: binary-indep binary-arch diff --git a/rel/pkg/deb/vars.config b/rel/pkg/deb/vars.config new file mode 100644 index 000000000..6e3f56ed4 --- /dev/null +++ b/rel/pkg/deb/vars.config @@ -0,0 +1,21 @@ +%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ft=erlang ts=4 sw=4 et + +%% Platform-specific installation paths +{platform_bin_dir, "{{platform_bin_dir}}"}. +{platform_data_dir, "{{platform_data_dir}}"}. +{platform_etc_dir, "{{platform_etc_dir}}"}. +{platform_base_dir, "{{platform_base_dir}}"}. +{platform_lib_dir, "{{platform_lib_dir}}"}. +{platform_log_dir, "{{platform_log_dir}}"}. + +{runner_script_dir, "{{platform_bin_dir}}"}. +{runner_base_dir, "{{platform_base_dir}}"}. +{runner_etc_dir, "{{platform_etc_dir}}"}. +{runner_log_dir, "{{platform_log_dir}}"}. +{runner_user, "{{package_install_user}}"}. +{runner_lib_dir, "{{platform_lib_dir}}"}. +{runner_patch_dir, "{{platform_lib_dir}}/{{package_patch_dir}}"}. +{pipe_dir, "/tmp/{{package_install_name}}/"}. +{package_replacement_line, "{{package_replacement_line_debian}}"}. +{package_conflicts_line, "{{package_replacement_line_debian}}"}. diff --git a/rel/pkg/out/.gitignore b/rel/pkg/out/.gitignore new file mode 100644 index 000000000..5e7d2734c --- /dev/null +++ b/rel/pkg/out/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/rel/pkg/rpm/Makefile b/rel/pkg/rpm/Makefile new file mode 100644 index 000000000..19e50e426 --- /dev/null +++ b/rel/pkg/rpm/Makefile @@ -0,0 +1,24 @@ + +PWD = $(shell pwd) + + +# No hyphens are allowed in the _version field in RPM +PKG_VERSION_NO_H ?= $(shell echo $(PKG_VERSION) | tr - .) + +default: + rpmbuild --define "_rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}$(DISTRO)%%{ARCH}.rpm" \ + --define '_topdir $(BASE_DIR)/rel/pkg/out/' \ + --define '_sourcedir $(BASE_DIR)/rel/pkg/out/' \ + --define '_specdir $(BASE_DIR)/rel/pkg/out/' \ + --define '_rpmdir $(BASE_DIR)/rel/pkg/out/packages' \ + --define '_srcrpmdir $(BASE_DIR)/rel/pkg/out/packages' \ + --define "_revision $(PKG_VERSION)" \ + --define "_version $(PKG_VERSION_NO_H)" \ + --define "_release $(PKG_BUILD)" \ + --define "_tarname riak-$(PKG_ID).tar.gz" \ + --define "_tarname_base riak-$(PKG_ID)" \ + -ba specfile + cd $(BASE_DIR)/rel/pkg/out/packages && \ + for rpmfile in *.rpm; do \ + sha256sum $${rpmfile} > $${rpmfile}.sha \ + ; done diff --git a/rel/pkg/rpm/riak b/rel/pkg/rpm/riak new file mode 100755 index 000000000..3a6372f53 --- /dev/null +++ b/rel/pkg/rpm/riak @@ -0,0 +1,17 @@ +#!/bin/sh + +COMMAND={{platform_bin_dir}}/riak + +if [[ $EUID -ne 0 ]]; then + echo "You need to be root or use sudo to run this command." + exit 1 +fi + +case "$1" in + start|console|foreground) + su - riak -c "PIPE_DIR=${PIPE_DIR} ${COMMAND} ${*} -pa {{platform_lib_dir}}/patches" + ;; + *) + su - riak -c "PIPE_DIR=${PIPE_DIR} ${COMMAND} ${*}" + ;; +esac diff --git a/rel/pkg/rpm/specfile b/rel/pkg/rpm/specfile new file mode 100644 index 000000000..d6001015f --- /dev/null +++ b/rel/pkg/rpm/specfile @@ -0,0 +1,150 @@ +## ------------------------------------------------------------------- +## +## Copyright (c) 2014 Basho Technologies, Inc. +## +## This file is provided to you under the Apache License, +## Version 2.0 (the "License"); you may not use this file +## except in compliance with the License. You may obtain +## a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, +## software distributed under the License is distributed on an +## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +## KIND, either express or implied. See the License for the +## specific language governing permissions and limitations +## under the License. +## +## ------------------------------------------------------------------- + +Name: riak +Version: %{_version} +Release: %{_release}%{?dist} +License: "Apacke 2.0" +Group: Development/Libraries +Source: %{_tarname} +URL: "https://riak.com" +Vendor: "Riak" +Packager: "Riak Package Maint" <"packaging@riak.com"> +BuildRoot: %{_tmppath}/%{name}-%{_revision}-%{release}-root +Summary: "Riak is a distributed data store" +Obsoletes: riak + +%description +"Riak is a distributed data store" + +%define init_script %{_sysconfdir}/init.d/riak +%define debug_package %{nil} +%define __prelink_undo_cmd /bin/cat prelink library + +%define platform_data_dir %{_localstatedir}/lib/riak +%define platform_etc_dir %{_sysconfdir}/riak +%define platform_base_dir %{_libdir}/riak +%define platform_bin_dir %{platform_base_dir}/bin +%define platform_lib_dir %{platform_base_dir}/lib +%define platform_log_dir %{_localstatedir}/log/riak + + +%prep +%setup -q -n %{_tarname_base} -c %{_tarname_base} + +# Setup vars.config like other platforms, but do it inside of spec file +cat > rpm.vars.config </dev/null 2>&1; then + groupadd -r riak +fi + +if getent passwd riak >/dev/null 2>&1; then + usermod -d %{_localstatedir}/lib/riak riak || true +else + useradd -r -g riak \ + --home %{_localstatedir}/lib/riak \ + --comment "Riak User" \ + --shell /bin/bash \ + riak +fi + + +%post +# Post Installation Script + +# For distros with SELinux (RHEL/Fedora) +if [ `which selinuxenabled > /dev/null 2>&1` ] ; then + # Fixup perms for SELinux (if it is enabled) + selinuxenabled && find %{_localstatedir}/lib/riak -name "*.so" -exec chcon -t textrel_shlib_t {} \; +fi + +%preun +# Pre-uninstall script + +# Only on uninstall, not upgrades +if [ "$1" = 0 ] ; then + /sbin/service riak stop > /dev/null 2>&1 +fi +exit 0 + + +# Man pages are optional and might be missing, read from file +%files +%defattr(-,riak,riak) +%{_localstatedir}/lib/riak +%{_localstatedir}/log/riak +%{_libdir}/* +%defattr(-,root,root) +%dir %{_sysconfdir}/riak +/usr/bin/* +%config(noreplace) %{_sysconfdir}/riak/* + +%clean +#rm -rf %{buildroot}