Skip to content

Commit

Permalink
[master] KAZOO-5578: update relx and change vm.args (2600hz#3907)
Browse files Browse the repository at this point in the history
* KAZOO-5578: bump relx version to 3.23.0 to fix vm.args issue

* KAZOO-5578: rewrite vm.args to a new file with node name

temperoray patch kazoo bin generated by relx to rewrite vm.args to a new
file with node name included on the file name.

* KAZOO-5578: use another approach in relx bin to support include config

`sys.config` file supports include from another config file, the catch is
the the actual config file should be named excatly _sys.config_.

Relx supports environment variable substitution in `vm.args` and `sys.config`.
They added a multi node option which basically would replace env vars in
(for example `vm.args`) file and save the result in `vm.NODE_NAME.args`.
In no multi node situation it just substitute env vars to `vm.args` and
would copy the the orignal file into` vm.args.orig`.

First issue is exctracting `NAME_ARGS ("-s?name NODE_NAME")`, which is always
uses vm.args (the file with substituted env vars) which is result of the previous
run and contains the previous `NODE_NAME`, which means not honoring current `NODE_NAME`
for commands of kazoo release script.

In other hand, it turns out sup command is unhappy when it calls multiple
times or simultaneously since `vm.args` is rewritten every time and could be
ends up corrupted or missed.

So removing `RELX_REPLACE_OS_VARS` could be a good solution since escript doesn't
have node name and cookie options. This turns out to copy the ``".orig"`` files to
the their env vars substituted ones.

This commit contains a patch for the script to fix those issues.

Other changes:

* Remove `RELX_REPLACE_OS_VARS` from sup command script.
* clean up `scripts/dev/kazoo.sh`
* paramertize cookie in `vm.args`

* KAZOO-5578: update relx.patch to remove +Bd argument and better logging

* KAZOO-5578: ad RELX_MULTI_NODE to kazoo.sh
  • Loading branch information
icehess authored and k-anderson committed Jul 6, 2017
1 parent b505bdb commit bfad83c
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 52 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ kazoo: core apps


$(RELX):
wget 'https://github.com/erlware/relx/releases/download/v3.19.0/relx' -O $@
wget 'https://github.com/erlware/relx/releases/download/v3.23.0/relx' -O $@
chmod +x $@

clean-release:
Expand All @@ -84,10 +84,13 @@ clean-release:

build-release: $(RELX) clean-release rel/relx.config rel/vm.args
$(RELX) --config rel/relx.config -V 2 release --relname 'kazoo'
patch _rel/kazoo/bin/kazoo -i rel/relx.patch
build-dev-release: $(RELX) clean-release rel/relx.config-dev rel/vm.args
$(RELX) --dev-mode true --config rel/relx.config -V 2 release --relname 'kazoo'
patch _rel/kazoo/bin/kazoo -i rel/relx.patch
build-ci-release: $(RELX) clean-release rel/relx.config rel/vm.args
$(RELX) --config rel/relx.config -V 2 release --relname 'kazoo' --sys_config rel/ci-sys.config
patch _rel/kazoo/bin/kazoo -i rel/relx.patch
tar-release: $(RELX) rel/relx.config rel/vm.args
$(RELX) --config rel/relx.config -V 2 release tar --relname 'kazoo'
rel/relx.config: rel/relx.config.src
Expand All @@ -99,7 +102,7 @@ rel/relx.config-dev: rel/relx.config.src
rel/dev-vm.args: rel/args # Used by scripts/dev-start-*.sh
cp $^ $@
rel/vm.args: rel/args rel/dev-vm.args
( cat $<; echo '$${KZname}' ) > $@
( echo '-setcookie $${COOKIE}'; cat $<; echo '-name $${NODE_NAME}' ) > $@

## More ACTs at //github.com/erlware/relx/priv/templates/extended_bin
release: ACT ?= console # start | attach | stop | console | foreground
Expand All @@ -108,14 +111,14 @@ ifneq ($(findstring kazoo_apps,$(REL)),kazoo_apps)
release: export KAZOO_APPS = 'ecallmgr'
endif
release:
@RELX_REPLACE_OS_VARS=true KZname='-name $(REL)' _rel/kazoo/bin/kazoo $(ACT) "$$@"
@NODE_NAME='$(REL)' COOKIE='change_me' $(ROOT)/scripts/dev/kazoo.sh $(ACT) "$$@"

install: compile build-release
cp -a _rel/kazoo /opt

read-release-cookie: REL ?= kazoo_apps
read-release-cookie:
@RELX_REPLACE_OS_VARS=true KZname='-name $(REL)' _rel/kazoo/bin/kazoo escript lib/kazoo_config-*/priv/read-cookie.escript "$$@"
@NODE_NAME='$(REL)' _rel/kazoo/bin/kazoo escript lib/kazoo_config-*/priv/read-cookie.escript "$$@"

DIALYZER ?= dialyzer
PLT ?= .kazoo.plt
Expand Down
2 changes: 1 addition & 1 deletion core/kazoo_config/priv/read-cookie.escript
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
%% API

main(_) ->
"-name "++Release = os:getenv("KZname"),
Release = os:getenv("NODE_NAME"),
REL = lists:takewhile(fun ($@) -> 'false'; (_) -> 'true' end, Release),
[Cookie] = kazoo_config_init:read_cookie(list_to_atom(REL)),
io:format("~s\n", [Cookie]).
Expand Down
22 changes: 12 additions & 10 deletions core/sup/priv/sup
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
#!/bin/bash

# The file to copy/symlink under /usr/bin or similar
DEFAULT_REL='sup@`hostname -f`'

if [[ ! -z "$KAZOO_ROOT" ]]; then
DEFAULT_ROOT="$KAZOO_ROOT"
elif [[ -d _rel/kazoo ]]; then
DEFAULT_ROOT=_rel/kazoo
DEFAULT_ROOT=${KAZOO_ROOT:-_rel/kazoo}
if [ -d "$DEFAULT_ROOT/_rel/kazoo" ]; then
DEFAULT_ROOT="$DEFAULT_ROOT"
elif [ -d "$DEFAULT_ROOT/bin" ]; then
DEFAULT_ROOT="$DEFAULT_ROOT"
elif [ -d /opt/kazoo/_rel/kazoo ]; then
DEFAULT_ROOT="/opt/kazoo/_rel/kazoo"
elif [ -d /opt/kazoo/bin ]; then
DEFAULT_ROOT="/opt/kazoo"
else
DEFAULT_ROOT=/opt/kazoo
echo "Can't find Kazoo release root directory, is the release built?"
exit -1
fi

export NAME_ARG="-name ${DEFAULT_REL}"

RELX_REPLACE_OS_VARS=true KZname="-name ${DEFAULT_REL}" "${DEFAULT_ROOT}"/bin/kazoo escript lib/sup-*/priv/sup.escript "$*"
"${DEFAULT_ROOT}"/bin/kazoo escript lib/sup-*/priv/sup.escript "$*"
exit $?
2 changes: 0 additions & 2 deletions rel/args
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
-setcookie change_me

# Tell SASL not to log progress reports, and log SASL errors to a file
-sasl errlog_type error
-sasl sasl_error_logger '{file, "log/error_log.sasl"}'
Expand Down
54 changes: 54 additions & 0 deletions rel/relx.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@@ -259,12 +259,16 @@
else
replace_os_vars "$IN_FILE_PATH" "$OUT_FILE_PATH"
fi
- else
- # If vm.arg.orig or sys.config.orig is present then use that
- if [ -f "$ORIG_FILE_PATH" ]; then
- cp "$ORIG_FILE_PATH" "$OUT_FILE_PATH"
- fi
fi
+
+ # If $RELX_REPLACE_OS_VARS is not set and vm.arg.orig or
+ # sys.config.orig is present this means that env variable
+ # substitution has occurred before and the result is
+ # already saved to vm.args and sys.config in previous run.
+ # This could happens for running escripts, etc... which
+ # really doesn't need these files if the user doesn't want
+ # vm.args to be written so often.
+
echo $OUT_FILE_PATH
}

@@ -293,7 +297,12 @@
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
ERTS_LIB_DIR="$(dirname "$ERTS_DIR")/lib"

-VMARGS_PATH=$(add_path vm.args $VMARGS_PATH)
+VMARGS_ORIG_PATH=$(add_path vm.args.orig)
+if [ -f "$VMARGS_ORIG_PATH" ]; then
+ VMARGS_PATH="$VMARGS_ORIG_PATH"
+else
+ VMARGS_PATH=$(add_path vm.args $VMARGS_PATH)
+fi
# Extract the target node name from node.args
NAME_ARG=$(egrep '^-s?name' "$VMARGS_PATH" || true)
# Perform replacement of variables in ${NAME_ARG}
@@ -515,7 +524,7 @@
else
BOOTFILE="$REL_DIR/start"
fi
- FOREGROUNDOPTIONS="-noshell -noinput +Bd"
+ FOREGROUNDOPTIONS="-noshell -noinput"
;;
console_clean)
__code_paths=$(relx_get_code_paths)
@@ -552,7 +561,7 @@

# Log the startup
echo "$RELEASE_ROOT_DIR"
- logger -t "$REL_NAME[$$]" "Starting up"
+ logger -t "$REL_NAME[$$]" "Starting up $NAME ($REL_NAME-$REL_VSN - Erts $ERTS_VSN)"

# Start the VM
exec "$@" -- ${1+$ARGS}
12 changes: 4 additions & 8 deletions scripts/check-release-startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ rel=${REL:-kazoo_apps} # kazoo_apps | ecallmgr | ...

echo "Checking release startup with node $rel..."

sup_() {
RELX_REPLACE_OS_VARS=true KZname="-name $rel" $PWD/_rel/kazoo/bin/kazoo escript lib/sup-*/priv/sup.escript "$*"
}

script() {
sup_ crossbar_maintenance create_account 'compte_maitre' 'royaume' 'superduperuser' 'pwd!'
$PWD/core/sup/priv/sup crossbar_maintenance create_account 'compte_maitre' 'royaume' 'superduperuser' 'pwd!'
sleep 3
sup_ kapps_maintenance migrate
$PWD/core/sup/priv/sup kapps_maintenance migrate
sleep 3
sup_ kapps_maintenance migrate_to_4_0
$PWD/core/sup/priv/sup kapps_maintenance migrate_to_4_0
sleep 9
sup_ init stop
$PWD/core/sup/priv/sup init stop
}

sleep 240 && script &
Expand Down
55 changes: 37 additions & 18 deletions scripts/dev/kazoo.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
#!/bin/bash
#!/bin/sh

if [ "$KAZOO_CONFIG" = "" ]
then
export KAZOO_CONFIG=$HOME/config.ini
echo Using default config: $KAZOO_CONFIG
# look for kazoo release root directory
DEFAULT_ROOT=${KAZOO_ROOT:-_rel/kazoo}
if [ -d "$DEFAULT_ROOT/_rel/kazoo" ]; then
DEFAULT_ROOT="$DEFAULT_ROOT"
elif [ -d "$DEFAULT_ROOT/bin" ]; then
DEFAULT_ROOT="$DEFAULT_ROOT"
elif [ -d /opt/kazoo/_rel/kazoo ]; then
DEFAULT_ROOT="/opt/kazoo/_rel/kazoo"
elif [ -d /opt/kazoo/bin ]; then
DEFAULT_ROOT="/opt/kazoo"
else
echo "Can't find Kazoo release root directory, is the release built?"
exit -1
fi
echo "Release path: $DEFAULT_ROOT"

if [ ! -f $KAZOO_CONFIG ]; then
echo "Specified kazoo config doesn't exists, please provide readable kazoo config file"
exit
# look for kazoo config file path
if [ -f "$KAZOO_CONFIG" ]; then
KAZOO_CONFIG="$KAZOO_CONFIG"
elif [ -f $HOME/config.ini ]; then
KAZOO_CONFIG=$HOME/config.ini
elif [ -f /etc/kazoo/config.ini ]; then
KAZOO_CONFIG="/etc/kazoo/config.ini"
elif [ -f /etc/kazoo/core/config.ini ]; then
KAZOO_CONFIG="/etc/kazoo/core/config.ini"
else
echo "Kazoo config doesn't exists, please provide readable kazoo config file"
exit -1
fi
echo "Kazoo config file path: $KAZOO_CONFIG"

if [ "$KAZOO_NODE" = "" ]
then
KAZOO_NODE=kazoo_apps@$(hostname)
echo Using default node name: $KAZOO_NODE
fi
NODE_NAME=${NODE_NAME:-kazoo_apps@$(hostname -f)}
echo "Node name: $NODE_NAME"

COOKIE=${COOKIE:-"change_me"}
echo "Cookie: $COOKIE"

CMD=$1
if [ "$CMD" = "" ]
then
CMD=console
if [ "$CMD" = "" ]; then
CMD=console
else
shift
shift
fi

RELX_REPLACE_OS_VARS=true KZname="-name $KAZOO_NODE" _rel/kazoo/bin/kazoo $CMD "$*"
RELX_REPLACE_OS_VARS=true RELX_MULTI_NODE=true NODE_NAME="$NODE_NAME" COOKIE="$COOKIE" "$DEFAULT_ROOT"/bin/kazoo $CMD "$*"
10 changes: 1 addition & 9 deletions scripts/dev/sup.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
#!/bin/bash
KAZOO_NODE=${KAZOO_NODE:-kazoo_apps@$(hostname)}
echo Connecting to node: $KAZOO_NODE

IFS='@' read -r -a NH <<< "$KAZOO_NODE"
NAME="${NH[0]}"

RELX_REPLACE_OS_VARS=true KZname="-name $KAZOO_NODE" \
exec _rel/kazoo/bin/kazoo escript lib/sup-*/priv/sup.escript \
-n $NAME \
"$*"
_rel/kazoo/bin/kazoo escript lib/sup-*/priv/sup.escript "$*"

0 comments on commit bfad83c

Please sign in to comment.