emqx 20 KB

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