diff --git a/Makefile b/Makefile index a099edfc79f..c07c2bd395f 100644 --- a/Makefile +++ b/Makefile @@ -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: @@ -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 @@ -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 @@ -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 diff --git a/core/kazoo_config/priv/read-cookie.escript b/core/kazoo_config/priv/read-cookie.escript index a6c5b48c3aa..ca50531437c 100755 --- a/core/kazoo_config/priv/read-cookie.escript +++ b/core/kazoo_config/priv/read-cookie.escript @@ -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]). diff --git a/core/sup/priv/sup b/core/sup/priv/sup index f0658895a1c..4ab6bba65cb 100755 --- a/core/sup/priv/sup +++ b/core/sup/priv/sup @@ -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 $? diff --git a/rel/args b/rel/args index ff0502f6b14..3171131bc6e 100644 --- a/rel/args +++ b/rel/args @@ -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"}' diff --git a/rel/relx.patch b/rel/relx.patch new file mode 100644 index 00000000000..55c343fbea8 --- /dev/null +++ b/rel/relx.patch @@ -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} diff --git a/scripts/check-release-startup.sh b/scripts/check-release-startup.sh index 55cd0110227..4dba28d64e4 100755 --- a/scripts/check-release-startup.sh +++ b/scripts/check-release-startup.sh @@ -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 & diff --git a/scripts/dev/kazoo.sh b/scripts/dev/kazoo.sh index 1871b5788cf..55a64c7145b 100755 --- a/scripts/dev/kazoo.sh +++ b/scripts/dev/kazoo.sh @@ -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 "$*" diff --git a/scripts/dev/sup.sh b/scripts/dev/sup.sh index f2e77056fa6..df3cefbf65a 100755 --- a/scripts/dev/sup.sh +++ b/scripts/dev/sup.sh @@ -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 "$*"