emqx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. #!/bin/bash
  2. # -*- tab-width:4;indent-tabs-mode:nil -*-
  3. # ex: ts=4 sw=4 et
  4. set -e
  5. ROOT_DIR="$(cd "$(dirname "$(readlink "$0" || echo "$0")")"/..; pwd -P)"
  6. # shellcheck disable=SC1090
  7. . "$ROOT_DIR"/releases/emqx_vars
  8. RUNNER_SCRIPT="$RUNNER_BIN_DIR/$REL_NAME"
  9. CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}"
  10. REL_DIR="$RUNNER_ROOT_DIR/releases/$REL_VSN"
  11. WHOAMI=$(whoami)
  12. # Make sure log directory exists
  13. mkdir -p "$RUNNER_LOG_DIR"
  14. # Make sure data directory exists
  15. mkdir -p "$RUNNER_DATA_DIR"
  16. # cuttlefish try to read environment variables starting with "EMQX_", if not specified
  17. export CUTTLEFISH_ENV_OVERRIDE_PREFIX="${CUTTLEFISH_ENV_OVERRIDE_PREFIX:-EMQX_}"
  18. relx_usage() {
  19. command="$1"
  20. case "$command" in
  21. unpack)
  22. echo "Usage: $REL_NAME unpack [VERSION]"
  23. echo "Unpacks a release package VERSION, it assumes that this"
  24. echo "release package tarball has already been deployed at one"
  25. echo "of the following locations:"
  26. echo " releases/<relname>-<version>.tar.gz"
  27. echo " releases/<relname>-<version>.zip"
  28. ;;
  29. install)
  30. echo "Usage: $REL_NAME install [VERSION]"
  31. echo "Installs a release package VERSION, it assumes that this"
  32. echo "release package tarball has already been deployed at one"
  33. echo "of the following locations:"
  34. echo " releases/<relname>-<version>.tar.gz"
  35. echo " releases/<relname>-<version>.zip"
  36. echo ""
  37. echo " --no-permanent Install release package VERSION but"
  38. echo " don't make it permanent"
  39. ;;
  40. uninstall)
  41. echo "Usage: $REL_NAME uninstall [VERSION]"
  42. echo "Uninstalls a release VERSION, it will only accept"
  43. echo "versions that are not currently in use"
  44. ;;
  45. upgrade)
  46. echo "Usage: $REL_NAME upgrade [VERSION]"
  47. echo "Upgrades the currently running release to VERSION, it assumes"
  48. echo "that a release package tarball has already been deployed at one"
  49. echo "of the following locations:"
  50. echo " releases/<relname>-<version>.tar.gz"
  51. echo " releases/<relname>-<version>.zip"
  52. echo ""
  53. echo " --no-permanent Install release package VERSION but"
  54. echo " don't make it permanent"
  55. ;;
  56. downgrade)
  57. echo "Usage: $REL_NAME downgrade [VERSION]"
  58. echo "Downgrades the currently running release to VERSION, it assumes"
  59. echo "that a release package tarball has already been deployed at one"
  60. echo "of the following locations:"
  61. echo " releases/<relname>-<version>.tar.gz"
  62. echo " releases/<relname>-<version>.zip"
  63. echo ""
  64. echo " --no-permanent Install release package VERSION but"
  65. echo " don't make it permanent"
  66. ;;
  67. *)
  68. echo "Usage: $REL_NAME {start|start_boot <file>|ertspath|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|downgrade|install|uninstall|versions|escript|rpc|rpcterms|eval|root_dir}"
  69. ;;
  70. esac
  71. }
  72. # Simple way to check the correct user and fail early
  73. check_user() {
  74. # Validate that the user running the script is the owner of the
  75. # RUN_DIR.
  76. if [ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]; then
  77. if [ "x$WHOAMI" != "xroot" ]; then
  78. echo "You need to be root or use sudo to run this command"
  79. exit 1
  80. fi
  81. CMD="\"$RUNNER_SCRIPT\" "
  82. for ARG in "$@"; do
  83. CMD="${CMD} \"$ARG\""
  84. done
  85. # This will drop priviledges into the runner user
  86. # It exec's in a new shell and the current shell will exit
  87. exec su - "$RUNNER_USER" -c "$CMD"
  88. fi
  89. }
  90. # Make sure the user running this script is the owner and/or su to that user
  91. check_user "$@"
  92. ES=$?
  93. if [ "$ES" -ne 0 ]; then
  94. exit $ES
  95. fi
  96. if [ -z "$WITH_EPMD" ]; then
  97. EPMD_ARG="-start_epmd false -epmd_module ekka_epmd -proto_dist ekka"
  98. else
  99. EPMD_ARG="-start_epmd true $PROTO_DIST_ARG"
  100. fi
  101. # Warn the user if ulimit -n is less than 1024
  102. ULIMIT_F=$(ulimit -n)
  103. if [ "$ULIMIT_F" -lt 1024 ]; then
  104. echo "!!!!"
  105. echo "!!!! WARNING: ulimit -n is ${ULIMIT_F}; 1024 is the recommended minimum."
  106. echo "!!!!"
  107. fi
  108. # Echo to stderr on errors
  109. echoerr() { echo "$@" 1>&2; }
  110. # By default, use cuttlefish to generate app.config and vm.args
  111. CUTTLEFISH="${USE_CUTTLEFISH:-yes}"
  112. SED_REPLACE="sed -i "
  113. case $(sed --help 2>&1) in
  114. *GNU*) SED_REPLACE="sed -i ";;
  115. *BusyBox*) SED_REPLACE="sed -i ";;
  116. *) SED_REPLACE="sed -i '' ";;
  117. esac
  118. # Get node pid
  119. relx_get_pid() {
  120. if output="$(relx_nodetool rpcterms os getpid)"
  121. then
  122. # shellcheck disable=SC2001 # Escaped quote taken as closing quote in editor
  123. echo "$output" | sed -e 's/"//g'
  124. return 0
  125. else
  126. echo "$output"
  127. return 1
  128. fi
  129. }
  130. relx_get_nodename() {
  131. id="longname$(relx_gen_id)-${NAME}"
  132. "$BINDIR/erl" -boot "$REL_DIR/start_clean" -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell "${NAME_TYPE}" "$id"
  133. }
  134. # Connect to a remote node
  135. relx_rem_sh() {
  136. # Generate a unique id used to allow multiple remsh to the same node
  137. # transparently
  138. id="remsh$(relx_gen_id)-${NAME}"
  139. # Get the node's ticktime so that we use the same thing.
  140. TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)"
  141. # shellcheck disable=SC2086 # $EPMD_ARG is supposed to be split by whitespace
  142. # Setup remote shell command to control node
  143. exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot "$REL_DIR/start_clean" \
  144. -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
  145. -setcookie "$COOKIE" -hidden -kernel net_ticktime "$TICKTIME" $EPMD_ARG
  146. }
  147. # Generate a random id
  148. relx_gen_id() {
  149. od -t x -N 4 /dev/urandom | head -n1 | awk '{print $2}'
  150. }
  151. # Control a node
  152. relx_nodetool() {
  153. command="$1"; shift
  154. ERL_FLAGS="$ERL_FLAGS $EPMD_ARG" \
  155. "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
  156. -setcookie "$COOKIE" "$command" "$@"
  157. }
  158. # Run an escript in the node's environment
  159. relx_escript() {
  160. shift; scriptpath="$1"; shift
  161. export RUNNER_ROOT_DIR
  162. "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" "$@"
  163. }
  164. # Output a start command for the last argument of run_erl
  165. relx_start_command() {
  166. printf "exec \"%s\" \"%s\"" "$RUNNER_SCRIPT" \
  167. "$START_OPTION"
  168. }
  169. # Function to generate app.config and vm.args
  170. generate_config() {
  171. ## Delete the *.siz files first or it cann't start after
  172. ## changing the config 'log.rotation.size'
  173. rm -rf "${RUNNER_LOG_DIR}"/*.siz
  174. if [ "$CUTTLEFISH" != "yes" ]; then
  175. # Note: we have added a parameter '-vm_args' to this. It
  176. # appears redundant but it is not! the erlang vm allows us to
  177. # access all arguments to the erl command EXCEPT '-args_file',
  178. # so in order to get access to this file location from within
  179. # the vm, we need to pass it in twice.
  180. CONFIG_ARGS=" -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -vm_args $RUNNER_ETC_DIR/vm.args "
  181. else
  182. CONFIG_ARGS=$("$ERTS_PATH"/escript "$RUNNER_ROOT_DIR"/bin/cuttlefish -i "$REL_DIR"/emqx.schema -c "$RUNNER_ETC_DIR"/emqx.conf -d "$RUNNER_DATA_DIR"/configs generate)
  183. ## Merge cuttlefish generated *.args into the vm.args
  184. CUTTLE_GEN_ARG_FILE=$(echo "$CONFIG_ARGS" | sed -n 's/^.*\(vm_args[[:space:]]\)//p' | awk '{print $1}')
  185. TMP_ARG_FILE="$RUNNER_DATA_DIR/configs/vm.args.tmp"
  186. cp "$RUNNER_ETC_DIR/vm.args" "$TMP_ARG_FILE"
  187. echo "" >> "$TMP_ARG_FILE"
  188. sed '/^#/d' "$CUTTLE_GEN_ARG_FILE" | sed '/^$/d' | while IFS='' read -r ARG_LINE || [ -n "$ARG_LINE" ]; do
  189. ARG_KEY=$(echo "$ARG_LINE" | awk '{$NF="";print}')
  190. ARG_VALUE=$(echo "$ARG_LINE" | awk '{print $NF}')
  191. TMP_ARG_VALUE=$(grep "^$ARG_KEY" "$TMP_ARG_FILE" | awk '{print $NF}')
  192. if [ "$ARG_VALUE" != "$TMP_ARG_VALUE" ] ; then
  193. if [ -n "$TMP_ARG_VALUE" ]; then
  194. sh -c "$SED_REPLACE 's/^$ARG_KEY.*$/$ARG_LINE/' $TMP_ARG_FILE"
  195. else
  196. echo "$ARG_LINE" >> "$TMP_ARG_FILE"
  197. fi
  198. fi
  199. done
  200. mv -f "$TMP_ARG_FILE" "$CUTTLE_GEN_ARG_FILE"
  201. fi
  202. # shellcheck disable=SC2086
  203. if ! relx_nodetool chkconfig $CONFIG_ARGS; then
  204. echoerr "Error reading $CONFIG_ARGS"
  205. exit 1
  206. fi
  207. }
  208. # Call bootstrapd for daemon commands like start/stop/console
  209. bootstrapd() {
  210. if [ -e "$RUNNER_DATA_DIR/.erlang.cookie" ]; then
  211. chown "$RUNNER_USER" "$RUNNER_DATA_DIR"/.erlang.cookie
  212. fi
  213. }
  214. # Use $CWD/etc/sys.config if exists
  215. if [ -z "$RELX_CONFIG_PATH" ]; then
  216. if [ -f "$RUNNER_ETC_DIR/sys.config" ]; then
  217. RELX_CONFIG_PATH="-config $RUNNER_ETC_DIR/sys.config"
  218. else
  219. RELX_CONFIG_PATH=""
  220. fi
  221. fi
  222. if [ -z "$NAME_ARG" ]; then
  223. NODENAME="${EMQX_NODE_NAME:-}"
  224. # check if there is a node running, inspect its name
  225. # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
  226. [ -z "$NODENAME" ] && NODENAME=$(ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-name (\S*)' | awk '{print $2}')
  227. [ -z "$NODENAME" ] && NODENAME=$(grep -E '^[ \t]*node.name[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
  228. if [ -z "$NODENAME" ]; then
  229. echoerr "vm.args needs to have a -name parameter."
  230. echoerr " -sname is not supported."
  231. echoerr "perhaps you do not have read permissions on $RUNNER_ETC_DIR/emqx.conf"
  232. exit 1
  233. else
  234. NAME_ARG="-name ${NODENAME# *}"
  235. fi
  236. fi
  237. # Extract the name type and name from the NAME_ARG for REMSH
  238. NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
  239. NAME="$(echo "$NAME_ARG" | awk '{print $2}')"
  240. NODENAME="$(echo "$NAME" | awk -F'@' '{print $1}')"
  241. export ESCRIPT_NAME="$NODENAME"
  242. PIPE_DIR="${PIPE_DIR:-/$RUNNER_DATA_DIR/${WHOAMI}_erl_pipes/$NAME/}"
  243. # Extract the target cookie
  244. if [ -z "$COOKIE_ARG" ]; then
  245. COOKIE="${EMQX_NODE_COOKIE:-}"
  246. # check if there is a node running, steal its cookie
  247. # shellcheck disable=SC2009 # pgrep does not support Extended Regular Expressions
  248. [ -z "$COOKIE" ] && COOKIE=$(ps -ef | grep -E '\-progname\s.*emqx\s' | grep -o -E '\-setcookie (\S*)' | awk '{print $2}')
  249. [ -z "$COOKIE" ] && COOKIE=$(grep -E '^[ \t]*node.cookie[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
  250. if [ -z "$COOKIE" ]; then
  251. echoerr "vm.args needs to have a -setcookie parameter."
  252. echoerr "please check $RUNNER_ETC_DIR/emqx.conf"
  253. exit 1
  254. else
  255. COOKIE_ARG="-setcookie $COOKIE"
  256. fi
  257. fi
  258. # Extract cookie name from COOKIE_ARG
  259. COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')"
  260. # Support for IPv6 Dist. See: https://github.com/emqtt/emqttd/issues/1460
  261. PROTO_DIST=$(grep -E '^[ \t]*cluster.proto_dist[ \t]*=[ \t]*' "$RUNNER_ETC_DIR/emqx.conf" 2> /dev/null | tail -1 | cut -d = -f 2-)
  262. if [ -z "$PROTO_DIST" ]; then
  263. PROTO_DIST_ARG=""
  264. else
  265. PROTO_DIST_ARG="-proto_dist $PROTO_DIST"
  266. fi
  267. export ROOTDIR="$RUNNER_ROOT_DIR"
  268. export ERTS_DIR="$ROOTDIR/erts-$ERTS_VSN"
  269. export BINDIR="$ERTS_DIR/bin"
  270. export EMU="beam"
  271. export PROGNAME="erl"
  272. export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
  273. ERTS_LIB_DIR="$ERTS_DIR/../lib"
  274. MNESIA_DATA_DIR="$RUNNER_DATA_DIR/mnesia/$NAME"
  275. cd "$ROOTDIR"
  276. # User can specify an sname without @hostname
  277. # This will fail when creating remote shell
  278. # So here we check for @ and add @hostname if missing
  279. case $NAME in
  280. *@*)
  281. # Nothing to do
  282. ;;
  283. *)
  284. NAME=$NAME@$(relx_get_nodename)
  285. ;;
  286. esac
  287. # Check the first argument for instructions
  288. case "$1" in
  289. start|start_boot)
  290. # Make sure a node IS not running
  291. if relx_nodetool "ping" >/dev/null 2>&1; then
  292. echo "Node is already running!"
  293. exit 1
  294. fi
  295. # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
  296. bootstrapd
  297. # Save this for later.
  298. CMD=$1
  299. case "$1" in
  300. start)
  301. shift
  302. START_OPTION="console"
  303. HEART_OPTION="start"
  304. ;;
  305. start_boot)
  306. shift
  307. START_OPTION="console_boot"
  308. HEART_OPTION="start_boot"
  309. ;;
  310. esac
  311. RUN_PARAM="$*"
  312. # Set arguments for the heart command
  313. set -- "$RUNNER_SCRIPT" "$HEART_OPTION"
  314. [ "$RUN_PARAM" ] && set -- "$@" "$RUN_PARAM"
  315. # Export the HEART_COMMAND
  316. HEART_COMMAND="$RUNNER_SCRIPT $CMD"
  317. export HEART_COMMAND
  318. ## See: http://erlang.org/doc/man/run_erl.html
  319. # Export the RUN_ERL_LOG_GENERATIONS
  320. export RUN_ERL_LOG_GENERATIONS=${RUN_ERL_LOG_GENERATIONS:-"5"}
  321. # Export the RUN_ERL_LOG_MAXSIZE
  322. export RUN_ERL_LOG_MAXSIZE=${RUN_ERL_LOG_MAXSIZE:-"10485760"}
  323. mkdir -p "$PIPE_DIR"
  324. "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \
  325. "$(relx_start_command)"
  326. WAIT_TIME=${WAIT_FOR_ERLANG:-15}
  327. while [ "$WAIT_TIME" -gt 0 ]; do
  328. if ! relx_nodetool "ping" >/dev/null 2>&1; then
  329. WAIT_TIME=$((WAIT_TIME - 1))
  330. sleep 1
  331. continue
  332. fi
  333. sleep 1
  334. if relx_nodetool "ping" >/dev/null 2>&1; then
  335. echo "$EMQX_DISCR $REL_VSN is started successfully!"
  336. exit 0
  337. fi
  338. done && echo "$EMQX_DISCR $REL_VSN failed to start within ${WAIT_FOR_ERLANG:-15} seconds,"
  339. echo "see the output of '$0 console' for more information."
  340. echo "If you want to wait longer, set the environment variable"
  341. echo "WAIT_FOR_ERLANG to the number of seconds to wait."
  342. exit 1
  343. ;;
  344. stop)
  345. # Wait for the node to completely stop...
  346. PID="$(relx_get_pid)"
  347. if ! relx_nodetool "stop"; then
  348. exit 1
  349. fi
  350. while kill -s 0 "$PID" 2>/dev/null; do
  351. sleep 1
  352. done
  353. ;;
  354. restart|reboot)
  355. echo "$EMQX_DISCR $REL_VSN is stopped: $("$RUNNER_BIN_DIR"/emqx stop)"
  356. "$RUNNER_BIN_DIR"/emqx start
  357. ;;
  358. pid)
  359. ## Get the VM's pid
  360. if ! relx_get_pid; then
  361. exit 1
  362. fi
  363. ;;
  364. ping)
  365. ## See if the VM is alive
  366. if ! relx_nodetool "ping"; then
  367. exit 1
  368. fi
  369. ;;
  370. escript)
  371. ## Run an escript under the node's environment
  372. if ! relx_escript "$@"; then
  373. exit 1
  374. fi
  375. ;;
  376. attach)
  377. # Make sure a node IS running
  378. if ! relx_nodetool "ping" > /dev/null; then
  379. echo "Node is not running!"
  380. exit 1
  381. fi
  382. # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
  383. bootstrapd
  384. shift
  385. exec "$BINDIR/to_erl" "$PIPE_DIR"
  386. ;;
  387. remote_console)
  388. # Make sure a node IS running
  389. if ! relx_nodetool "ping" > /dev/null; then
  390. echo "Node is not running!"
  391. exit 1
  392. fi
  393. # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
  394. bootstrapd
  395. shift
  396. relx_rem_sh
  397. ;;
  398. upgrade|downgrade|install|unpack|uninstall)
  399. if [ -z "$2" ]; then
  400. echo "Missing version argument"
  401. echo "Usage: $REL_NAME $1 {version}"
  402. exit 1
  403. fi
  404. COMMAND="$1"; shift
  405. # Make sure a node IS running
  406. if ! relx_nodetool "ping" > /dev/null; then
  407. echo "Node is not running!"
  408. exit 1
  409. fi
  410. ERL_FLAGS="$ERL_FLAGS $EPMD_ARG" \
  411. exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \
  412. "$COMMAND" "{'$REL_NAME', \"$NAME_TYPE\", '$NAME', '$COOKIE'}" "$@"
  413. ;;
  414. versions)
  415. # Make sure a node IS running
  416. if ! relx_nodetool "ping" > /dev/null; then
  417. echo "Node is not running!"
  418. exit 1
  419. fi
  420. COMMAND="$1"; shift
  421. ERL_FLAGS="$ERL_FLAGS $EPMD_ARG" \
  422. exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \
  423. "versions" "{'$REL_NAME', \"$NAME_TYPE\", '$NAME', '$COOKIE'}" "$@"
  424. ;;
  425. console|console_clean|console_boot)
  426. # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
  427. bootstrapd
  428. # .boot file typically just $REL_NAME (ie, the app name)
  429. # however, for debugging, sometimes start_clean.boot is useful.
  430. # For e.g. 'setup', one may even want to name another boot script.
  431. case "$1" in
  432. console)
  433. if [ -f "$REL_DIR/$REL_NAME.boot" ]; then
  434. BOOTFILE="$REL_DIR/$REL_NAME"
  435. else
  436. BOOTFILE="$REL_DIR/start"
  437. fi
  438. ;;
  439. console_clean)
  440. BOOTFILE="$REL_DIR/start_clean"
  441. ;;
  442. console_boot)
  443. shift
  444. BOOTFILE="$1"
  445. shift
  446. ;;
  447. esac
  448. #generate app.config and vm.args
  449. generate_config
  450. # Setup beam-required vars
  451. EMU="beam"
  452. PROGNAME="${0#*/}"
  453. export EMU
  454. export PROGNAME
  455. # Store passed arguments since they will be erased by `set`
  456. ARGS="$*"
  457. # shellcheck disable=SC2086 # $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG are supposed to be split by whitespace
  458. # Build an array of arguments to pass to exec later on
  459. # Build it here because this command will be used for logging.
  460. set -- "$BINDIR/erlexec" -boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \
  461. -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
  462. -mnesia dir "\"${MNESIA_DATA_DIR}\"" \
  463. $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG
  464. # Dump environment info for logging purposes
  465. echo "Exec: $*" -- ${1+$ARGS}
  466. echo "Root: $ROOTDIR"
  467. # Log the startup
  468. echo "$RUNNER_ROOT_DIR"
  469. logger -t "${REL_NAME[$$]}" "Starting up"
  470. # Start the VM
  471. exec "$@" -- ${1+$ARGS}
  472. ;;
  473. foreground)
  474. # Bootstrap daemon command (check perms & drop to $RUNNER_USER)
  475. bootstrapd
  476. # start up the release in the foreground for use by runit
  477. # or other supervision services
  478. #generate app.config and vm.args
  479. generate_config
  480. [ -f "$REL_DIR/$REL_NAME.boot" ] && BOOTFILE="$REL_NAME" || BOOTFILE=start
  481. FOREGROUNDOPTIONS="-noshell -noinput +Bd"
  482. # Setup beam-required vars
  483. EMU=beam
  484. PROGNAME="${0#*/}"
  485. export EMU
  486. export PROGNAME
  487. # Store passed arguments since they will be erased by `set`
  488. ARGS="$*"
  489. # shellcheck disable=SC2086 # $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG are supposed to be split by whitespace
  490. # Build an array of arguments to pass to exec later on
  491. # Build it here because this command will be used for logging.
  492. set -- "$BINDIR/erlexec" $FOREGROUNDOPTIONS \
  493. -boot "$REL_DIR/$BOOTFILE" -mode "$CODE_LOADING_MODE" \
  494. -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
  495. -mnesia dir "\"${MNESIA_DATA_DIR}\"" \
  496. $RELX_CONFIG_PATH $CONFIG_ARGS $EPMD_ARG
  497. # Dump environment info for logging purposes
  498. echo "Exec: $*" -- ${1+$ARGS}
  499. echo "Root: $ROOTDIR"
  500. # Start the VM
  501. exec "$@" -- ${1+$ARGS}
  502. ;;
  503. ertspath)
  504. echo "$ERTS_PATH"
  505. ;;
  506. rpc)
  507. # Make sure a node IS running
  508. if ! relx_nodetool "ping" > /dev/null; then
  509. echo "Node is not running!"
  510. exit 1
  511. fi
  512. shift
  513. relx_nodetool rpc "$@"
  514. ;;
  515. rpcterms)
  516. # Make sure a node IS running
  517. if ! relx_nodetool "ping" > /dev/null; then
  518. echo "Node is not running!"
  519. exit 1
  520. fi
  521. shift
  522. relx_nodetool rpcterms "$@"
  523. ;;
  524. root_dir)
  525. # Make sure a node IS running
  526. if ! relx_nodetool "ping" > /dev/null; then
  527. echo "Node is not running!"
  528. exit 1
  529. fi
  530. shift
  531. relx_nodetool "eval" 'code:root_dir()'
  532. ;;
  533. eval)
  534. # Make sure a node IS running
  535. if ! relx_nodetool "ping" > /dev/null; then
  536. echo "Node is not running!"
  537. exit 1
  538. fi
  539. shift
  540. relx_nodetool "eval" "$@"
  541. ;;
  542. *)
  543. relx_usage "$1"
  544. exit 1
  545. ;;
  546. esac
  547. exit 0