#!/bin/bash # Echo to stderr on errors echoerr() { echo "ERROR: $*" 1>&2; } die() { echoerr "ERROR: $1" errno=${2:-1} exit "$errno" } assert_node_alive() { if ! relx_nodetool "ping" > /dev/null; then die "node_is_not_running!" 1 fi } check_erlang_start() { "$BINDIR/$PROGNAME" \ -noshell \ -boot_var RELEASE_LIB "$ERTS_LIB_DIR/lib" \ -boot "$REL_DIR/start_clean" \ -s crypto start \ -s erlang halt } # Simple way to check the correct user and fail early check_user() { # Validate that the user running the script is the owner of the # RUN_DIR. if [ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]; then if [ "x$WHOAMI" != "xroot" ]; then echo "You need to be root or use sudo to run this command" exit 1 fi CMD="DEBUG=$DEBUG \"$RUNNER_SCRIPT\" " for ARG in "$@"; do CMD="${CMD} \"$ARG\"" done # This will drop priviledges into the runner user # It exec's in a new shell and the current shell will exit exec su - "$RUNNER_USER" -c "$CMD" fi } # Get node pid relx_get_pid() { if output="$(relx_nodetool rpcterms os getpid)" then # shellcheck disable=SC2001 # Escaped quote taken as closing quote in editor echo "$output" | sed -e 's/"//g' return 0 else echo "$output" return 1 fi } # Connect to a remote node relx_rem_sh() { # Generate a unique id used to allow multiple remsh to the same node # transparently id="remsh$(relx_gen_id)-${NAME}" # Get the node's ticktime so that we use the same thing. TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)" # shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace # shellcheck disable=SC2153 # $NAME_TYPE is defined by `common_defs2.sh`, which runs before this is called # Setup remote shell command to control node if [ "$IS_ELIXIR" = "yes" ] then exec "$REL_DIR/iex" \ --remsh "$NAME" \ --boot-var RELEASE_LIB "$ERTS_LIB_DIR" \ --cookie "$COOKIE" \ --hidden \ --erl "-kernel net_ticktime $TICKTIME" \ --erl "$EPMD_ARG" \ --erl "$NAME_TYPE $id" \ --boot "$REL_DIR/start_clean" else exec "$BINDIR/erl" "$NAME_TYPE" "$id" \ -remsh "$NAME" -boot "$REL_DIR/start_clean" \ -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ -setcookie "$COOKIE" -hidden -kernel net_ticktime "$TICKTIME" \ $EPMD_ARG fi } # Generate a random id relx_gen_id() { od -t x -N 4 /dev/urandom | head -n1 | awk '{print $2}' } # Control a node relx_nodetool() { command="$1"; shift ERL_FLAGS="${ERL_FLAGS:-} $EPMD_ARG" \ "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ -setcookie "$COOKIE" "$command" "$@" } call_hocon() { "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" hocon "$@" \ || die "call_hocon_failed: $*" $? } # Run an escript in the node's environment relx_escript() { shift; scriptpath="$1"; shift "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" "$@" } # Output a start command for the last argument of run_erl. # The calling script defines `$START_OPTION`, when the command is to # start EMQX in the background. relx_start_command() { printf "exec \"%s\" \"%s\"" "$RUNNER_SCRIPT" \ "$START_OPTION" } # Function to generate app.config and vm.args generate_config() { local name_type="$1" local node_name="$2" ## Delete the *.siz files first or it cann't start after ## changing the config 'log.rotation.size' rm -rf "${RUNNER_LOG_DIR}"/*.siz EMQX_LICENSE_CONF_OPTION="" if [ "${EMQX_LICENSE_CONF:-}" != "" ]; then EMQX_LICENSE_CONF_OPTION="-c ${EMQX_LICENSE_CONF}" fi ## timestamp for each generation local NOW_TIME NOW_TIME="$(call_hocon now_time)" ## ths command populates two files: app.