diff --git a/apps/emqx_config_helper/lib/emqx_config_helper.ex b/apps/emqx_config_helper/lib/emqx_config_helper.ex index 1f2e0781d..186be4456 100644 --- a/apps/emqx_config_helper/lib/emqx_config_helper.ex +++ b/apps/emqx_config_helper/lib/emqx_config_helper.ex @@ -1,2 +1,9 @@ defmodule EmqxConfigHelper do + def hocon_cli(arg) do + arg + |> String.split() + |> Enum.map(&to_charlist/1) + |> :hocon_cli.main() + :ok + end end diff --git a/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex b/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex index fda0388d7..5ad4e93aa 100644 --- a/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex +++ b/apps/emqx_release_helper/lib/emqx_release_helper/applications.ex @@ -7,13 +7,20 @@ defmodule EmqxReleaseHelper.Applications do overlay %{release_type: release_type} do copy "etc/certs", "etc/certs" - template "etc/emqx.conf", "etc/emqx.conf" template "etc/ssl_dist.conf", "etc/ssl_dist.conf" template "etc/emqx_#{release_type}/vm.args", "etc/vm.args" end end application :emqx_machine do + start_type :permanent + + overlay do + template "etc/emqx.conf.all", "etc/emqx.conf" + end + end + + application :emqx_gateway do start_type :permanent end diff --git a/rel/overlays/ex_bin/emqx b/rel/overlays/ex_bin/emqx new file mode 100755 index 000000000..e668b7b64 --- /dev/null +++ b/rel/overlays/ex_bin/emqx @@ -0,0 +1,247 @@ +#!/bin/sh +set -e + +SELF=$(readlink "$0" || true) +if [ -z "$SELF" ]; then SELF="$0"; fi +RELEASE_ROOT="$(CDPATH='' cd "$(dirname "$SELF")/.." && pwd -P)" +export RELEASE_ROOT +export RELEASE_NAME="${RELEASE_NAME:-"emqx"}" +export RELEASE_VSN="${RELEASE_VSN:-"$(cut -d' ' -f2 "$RELEASE_ROOT/releases/start_erl.data")"}" +export RELEASE_COMMAND="$1" +export RELEASE_MODE="${RELEASE_MODE:-"embedded"}" +export RELEASE_PROG="${RELEASE_PROG:-"$(echo "$0" | sed 's/.*\///')"}" + +REL_VSN_DIR="$RELEASE_ROOT/releases/$RELEASE_VSN" +. "$REL_VSN_DIR/env.sh" +. "$RELEASE_ROOT/releases/emqx_vars" + +export RELEASE_COOKIE="${RELEASE_COOKIE:-"$(cat "$RELEASE_ROOT/releases/COOKIE")"}" +export RELEASE_NODE="${RELEASE_NODE:-"$RELEASE_NAME"}" +export RELEASE_TMP="${RELEASE_TMP:-"$RELEASE_ROOT/tmp"}" +export RELEASE_VM_ARGS="${RELEASE_VM_ARGS:-"$REL_VSN_DIR/vm.args"}" +export RELEASE_REMOTE_VM_ARGS="${RELEASE_REMOTE_VM_ARGS:-"$REL_VSN_DIR/remote.vm.args"}" +export RELEASE_DISTRIBUTION="${RELEASE_DISTRIBUTION:-"sname"}" +export RELEASE_BOOT_SCRIPT="${RELEASE_BOOT_SCRIPT:-"start"}" +export RELEASE_BOOT_SCRIPT_CLEAN="${RELEASE_BOOT_SCRIPT_CLEAN:-"start_clean"}" +export RELEASE_SYS_CONFIG="${RELEASE_SYS_CONFIG:-"$REL_VSN_DIR/sys"}" + +export SCHEMA_MOD=emqx_machine_schema +export CONFIGS_DIR="$RUNNER_DATA_DIR/configs" +export NAME='emqx' +export NAME_TYPE='-sname' + +SED_REPLACE="sed -i " +case $(sed --help 2>&1) in + *GNU*) SED_REPLACE="sed -i ";; + *BusyBox*) SED_REPLACE="sed -i ";; + *) SED_REPLACE="sed -i '' ";; +esac + +rand () { + dd count=1 bs=2 if=/dev/urandom 2> /dev/null | od -x | awk 'NR==1{print $2}' +} + +call_hocon () { + eval_elixir "EmqxConfigHelper.hocon_cli(\"$1 $2 $3 $4 $5 $6 $7 $8 $9\")" +} + +generate_config () { + local name_type="$NAME_TYPE" + local node_name="$NAME" + + ## 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.