Skip to content

Commit

Permalink
refactor and repair release assembly
Browse files Browse the repository at this point in the history
* resuscitate riak-chkconfig;
* make `make rel` relocatable again, fix riak-debug for it;
* remove runner_* substitution vars in all rel/**/vars.config;
  • Loading branch information
Andrei Zavada committed Dec 29, 2021
1 parent 757084e commit 7cff235
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 152 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ test : testclean eunit test-deps
rel: compile
@$(REBAR) as rel release
# freebsd tar won't write to stdout, so
@tar -c -f rel.tar --exclude '*/.git/*' -C _build/rel/rel riak && tar -x -f rel.tar -C rel && rm rel.tar
@tar -c -f rel.tar --exclude-vcs -C _build/rel/rel riak && tar -x -f rel.tar -C rel && rm rel.tar

rel-rpm: compile
@$(REBAR) as rpm release
@tar --exclude='*/.git/*' -c -C _build/rpm/rel riak | tar -x -C rel
@tar --exclude-vcs -c -C _build/rpm/rel riak | tar -x -C rel

rel-deb: compile
@$(REBAR) as deb release
@tar --exclude='*/.git/*' -c -C _build/deb/rel riak | tar -x -C rel
@tar --exclude=vcs -c -C _build/deb/rel riak | tar -x -C rel

rel-osx: compile
@$(REBAR) as osx release
Expand Down
12 changes: 8 additions & 4 deletions rel/files/riak
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

RUNNER_GEN_DIR={{platform_gen_dir}}
RELX_RIAK={{platform_bin_dir}}/riak
PID_DIR={{pid_dir}}
PIPE_DIR={{pipe_dir}}/ # terminating / (relx treats it as a prefix)
export PID_DIR={{pid_dir}}
export PIPE_DIR={{pipe_dir}}/ # terminating / (relx treats it as a prefix)

mkdir -p $PID_DIR $PIPE_DIR
chown riak:riak $PID_DIR $PIPE_DIR
Expand Down Expand Up @@ -53,12 +53,12 @@ function maybe_su {

case "$1" in
start)
maybe_su $RELX_RIAK $* -pa {{runner_patch_dir}} \
maybe_su $RELX_RIAK $* -pa {{platform_patch_dir}} \
&& write_pid_file
test -r $PID_DIR/riak.pid && exit 0
;;
console|foreground)
maybe_su $RELX_RIAK $* -pa {{runner_patch_dir}}
maybe_su $RELX_RIAK $* -pa {{platform_patch_dir}}
;;
stop)
maybe_su $RELX_RIAK $* \
Expand All @@ -68,6 +68,10 @@ case "$1" in
shift
maybe_su `which riak-admin` $*
;;
chkconfig)
shift
maybe_su `which riak-chkconfig` $*
;;
repl)
shift
maybe_su `which riak-repl` $*
Expand Down
49 changes: 35 additions & 14 deletions rel/files/riak-admin
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,35 @@
# Identify the script name
SCRIPT="riak-admin"

RPC_HOP="{{platform_bin_dir}}/riak rpc"
PLATFORM_BASE_DIR={{platform_base_dir}}
PLATFORM_BASE_DIR=${PLATFORM_BASE_DIR:-$(cd $(dirname "$0")/.. && pwd -P)}

PLATFORM_BIN_DIR={{platform_bin_dir}}
if [ "$PLATFORM_BIN_DIR" = "${PLATFORM_BIN_DIR#/}" ]; then
PLATFORM_BIN_DIR=$PLATFORM_BASE_DIR/$PLATFORM_BIN_DIR
fi

RPC_HOP="${PLATFORM_BIN_DIR}/riak rpc"
RPCt_HOP="${PLATFORM_BIN_DIR}/riak rpcterms"

PLATFORM_ETC_DIR={{platform_etc_dir}}
if [ "$PLATFORM_ETC_DIR" = "${PLATFORM_ETC_DIR#/}" ]; then
PLATFORM_ETC_DIR=$PLATFORM_BASE_DIR/$PLATFORM_ETC_DIR
fi

PLATFORM_PATCH_DIR={{platform_patch_dir}}
if [ "$PLATFORM_PATCH_DIR" = "${PLATFORM_PATCH_DIR#/}" ]; then
PLATFORM_PATCH_DIR=$PLATFORM_BASE_DIR/$PLATFORM_PATCH_DIR
fi

ERTS_VER=$(cd ${PLATFORM_BASE_DIR} && ls -d erts-*)
ERTS_PATH="${PLATFORM_BASE_DIR}/$ERTS_VER/bin"
COOKIE=`egrep '^[ \t]*distributed_cookie[ \t]*=[ \t]*' $PLATFORM_ETC_DIR/riak.conf 2> /dev/null | cut -d = -f 2 | tr -d ' '`

ERTS_PATH="{{runner_base_dir}}/`(cd {{runner_base_dir}} && ls -d erts-*)`/bin"
COOKIE=`egrep '^[ \t]*distributed_cookie[ \t]*=[ \t]*' {{platform_etc_dir}}/riak.conf 2> /dev/null | cut -d = -f 2 | tr -d ' '`
NODE={{node}}
HOST=${NODE#*@}

BOOT_FILE="{{runner_base_dir}}/releases/{{rel_vsn}}/start_clean"
BOOT_FILE="${PLATFORM_BASE_DIR}/releases/{{release_version}}/start_clean"

usage() {
echo "Usage: $SCRIPT { cluster | join | leave | backup | restore | test | "
Expand Down Expand Up @@ -804,7 +825,7 @@ case "$1" in
echo "Lists the services available on the node. See also: wait-for-service"
exit 1
fi
$RPC_HOPterms riak_core_node_watcher services ''
$RPCt_HOP riak_core_node_watcher services ''
;;

wait[_-]for[_-]service)
Expand All @@ -818,7 +839,7 @@ case "$1" in
while (true); do
# Make sure riak_core_node_watcher is up and running locally before trying to query it
# to avoid ugly (but harmless) error messages
NODEWATCHER=`$RPC_HOPterms erlang whereis "'riak_core_node_watcher'."`
NODEWATCHER=`$RPCt_HOP erlang whereis "'riak_core_node_watcher'."`
if [ "$NODEWATCHER" = "undefined" ]; then
echo "$SVC is not up: node watcher is not running"
continue
Expand All @@ -827,9 +848,9 @@ case "$1" in
# Get the list of services that are available on the requested node
# If no node is specified, get the list of services from the local node
if [ "X$TARGETNODE" = "X" ]; then
SERVICES=`$RPC_HOPterms riak_core_node_watcher services ''`
SERVICES=`$RPCt_HOP riak_core_node_watcher services ''`
else
SERVICES=`$RPC_HOPterms riak_core_node_watcher services "'${TARGETNODE}'."`
SERVICES=`$RPCt_HOP riak_core_node_watcher services "'${TARGETNODE}'."`
fi
echo "$SERVICES" | grep "[[,]$SVC[],]" > /dev/null 2>&1
if [ "X$?" = "X0" ]; then
Expand Down Expand Up @@ -870,7 +891,7 @@ case "$1" in
OLDNODE=$1
NEWNODE=$2
$ERTS_PATH/erl -noshell \
-pa {{runner_patch_dir}} \
-pa {{platform_patch_dir}} \
-boot $BOOT_FILE \
$CONFIG_ARGS \
-eval "riak_kv_console:$ACTION(['$OLDNODE', '$NEWNODE'])" \
Expand All @@ -891,7 +912,7 @@ case "$1" in
FILENAME=$3

$ERTS_PATH/erl -noshell -name riak_kv_backup@$HOST -setcookie $COOKIE \
-pa {{runner_patch_dir}} \
-pa {{platform_patch_dir}} \
-boot $BOOT_FILE \
-eval "riak_kv_backup:$ACTION('$NODE', \"$FILENAME\")" -s init stop
;;
Expand All @@ -911,20 +932,20 @@ case "$1" in
TYPE=$4

$ERTS_PATH/erl -noshell -name riak_kv_backup@$HOST -setcookie $COOKIE \
-pa {{runner_patch_dir}} \
-pa {{platform_patch_dir}} \
-boot $BOOT_FILE \
-eval "riak_kv_backup:$ACTION('$NODE', \"$FILENAME\", \"$TYPE\")" -s init stop
;;

test)
'test')
# Make sure the local node IS running

shift

# Parse out the node name to pass to the client

$ERTS_PATH/erl -noshell -name riak_test@$HOST -setcookie $COOKIE \
-pa {{runner_patch_dir}} \
-pa {{platform_patch_dir}} \
-boot $BOOT_FILE \
-eval "case catch(riak:client_test(\"$NODE\")) of \
ok -> init:stop(); \
Expand Down Expand Up @@ -959,7 +980,7 @@ case "$1" in
RAND=$(($(($$ % 1000)) + 1))
# Using np_etop instead of riak_etop to follow node_package convention
$ERTS_PATH/erl -noshell -noinput \
-pa {{runner_base_dir}} \
-pa {{platform_patch_dir}} \
-boot $BOOT_FILE \
-hidden -name np_etop$RAND@$HOST -setcookie $COOKIE \
-s etop -s erlang halt -output text \
Expand Down
38 changes: 32 additions & 6 deletions rel/files/riak-chkconfig
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@
# -*- tab-width:4;indent-tabs-mode:nil -*-
# ex: ts=4 sw=4 et

## cf_config defines the config arguments needed
. bin/cf_config
PLATFORM_BASE_DIR={{platform_base_dir}}
PLATFORM_BASE_DIR=${PLATFORM_BASE_DIR:-$(cd $(dirname "$0")/.. && pwd -P)}
RPC_HOP="${PLATFORM_BASE_DIR}/bin/riak rpc"
RPCt_HOP="${PLATFORM_BASE_DIR}/bin/riak rpcterms"

## "vm.args = $VMARGS_PATH"
## "app.config = $CONFIG_PATH"
ERTS_VER=$(cd ${PLATFORM_BASE_DIR} && ls -d erts-*)
ERTS_PATH="${PLATFORM_BASE_DIR}/$ERTS_VER/bin"

PLATFORM_ETC_DIR={{platform_etc_dir}}
if [ "$PLATFORM_ETC_DIR" = "${PLATFORM_ETC_DIR#/}" ]; then
PLATFORM_ETC_DIR=$PLATFORM_BASE_DIR/$PLATFORM_ETC_DIR
fi

COOKIE=`egrep '^[ \t]*distributed_cookie[ \t]*=[ \t]*' "$PLATFORM_ETC_DIR"/riak.conf 2> /dev/null | cut -d = -f 2 | tr -d ' '`
NODE={{node}}
HOST=${NODE#*@}

BOOT_FILE="${PLATFORM_BASE_DIR}/releases/{{release_version}}/start_clean"

PLATFORM_GEN_DIR={{platform_gen_dir}}
if [ "$PLATFORM_GEN_DIR" = "${PLATFORM_GEN_DIR#/}" ]; then
PLATFORM_GEN_DIR=$PLATFORM_BASE_DIR/$PLATFORM_GEN_DIR
fi

CONFIG_PATH=`ls -1r ${PLATFORM_GEN_DIR}/generated.conf/app.*.config | head -n1`
VMARGS_PATH=`ls -1r ${PLATFORM_GEN_DIR}/generated.conf/vm.*.args | head -n1`

CODE=" try
{ok, _} = file:consult(\"$CONFIG_PATH\"),
Expand All @@ -18,6 +39,11 @@ CODE=" try
halt(1)
end."

$BINDIR/erl -noshell -boot start_clean -eval "$CODE"
$ERTS_PATH/erl -noshell -noinput \
-pa $PLATFORM_PATCH_DIR \
-boot $BOOT_FILE \
-hidden -name riak_chkconfig$RAND@$HOST -setcookie $COOKIE \
-node $NODE -tracing off \
-eval "$CODE"

echo $CUTTLE_CONF
echo $CONFIG_PATH $VMARGS_PATH
Loading

0 comments on commit 7cff235

Please sign in to comment.