Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

noderunner: add support for alt dir and boot file

    This patch contains two additions to simplenode.runner:

1. Check if vm.args exists in CWD; if so, use it. This makes it
   easier to start multiple concurrent nodes on a single machine
   from one rebar-created release (starting each node from its
   own directory, with its own copy of vm.args and e.g.
   sys.config, log directory, database directory, etc.)

2. Add the targets start_boot <file> and console_boot <file>.
   This is used to select a different boot script. The 'setup'
   application (http://github.com/esl/setup) builds a special boot
   script for installation (all apps loaded but not started,
   making it possible to run install hooks with the full code path
   in place).
  • Loading branch information...
commit c028225d18d2b95dc8d294391e65a2dc455d0d4b 1 parent 47716a7
Ulf Wiger authored

Showing 1 changed file with 54 additions and 20 deletions. Show diff stats Hide diff stats

  1. +54 20 priv/templates/simplenode.runner
74 priv/templates/simplenode.runner
@@ -4,9 +4,10 @@
4 4
5 5 RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd)
6 6
  7 +CALLER_DIR=$PWD
  8 +
7 9 RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
8 10 RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
9   -RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log
10 11 # Note the trailing slash on $PIPE_DIR/
11 12 PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
12 13 RUNNER_USER=
@@ -16,11 +17,6 @@ if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
16 17 exec sudo -u $RUNNER_USER -i $0 $@
17 18 fi
18 19
19   -# Make sure CWD is set to runner base dir
20   -cd $RUNNER_BASE_DIR
21   -
22   -# Make sure log directory exists
23   -mkdir -p $RUNNER_LOG_DIR
24 20 # Identify the script name
25 21 SCRIPT=`basename $0`
26 22
@@ -29,18 +25,32 @@ START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
29 25 ERTS_VSN=${START_ERL% *}
30 26 APP_VSN=${START_ERL#* }
31 27
32   -# Use releases/VSN/vm.args if it exists otherwise use etc/vm.args
33   -if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then
34   - VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args"
  28 +# Use $CWD/vm.args if exists, otherwise releases/VSN/vm.args, then etc/vm.args
  29 +if [ -e "$CALLER_DIR/vm.args" ]; then
  30 + VMARGS_PATH=$CALLER_DIR/vm.args
  31 + USE_DIR=$CALLER_DIR
35 32 else
36   - VMARGS_PATH="$RUNNER_ETC_DIR/vm.args"
  33 + USE_DIR=$RUNNER_BASE_DIR
  34 + if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then
  35 + VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args"
  36 + else
  37 + VMARGS_PATH="$RUNNER_ETC_DIR/vm.args"
  38 + fi
37 39 fi
38 40
  41 +RUNNER_LOG_DIR=$USE_DIR/log
  42 +# Make sure log directory exists
  43 +mkdir -p $RUNNER_LOG_DIR
  44 +
39 45 # Use releases/VSN/sys.config if it exists otherwise use etc/app.config
40   -if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then
41   - CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config"
  46 +if [ -e "$USE_DIR/sys.config" ]; then
  47 + CONFIG_PATH="$USE_DIR/sys.config"
42 48 else
43   - CONFIG_PATH="$RUNNER_ETC_DIR/app.config"
  49 + if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then
  50 + CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config"
  51 + else
  52 + CONFIG_PATH="$RUNNER_ETC_DIR/app.config"
  53 + fi
44 54 fi
45 55
46 56 # Extract the target node name from node.args
@@ -57,6 +67,13 @@ if [ -z "$COOKIE_ARG" ]; then
57 67 exit 1
58 68 fi
59 69
  70 +# Make sure CWD is set to the right dir
  71 +cd $USE_DIR
  72 +
  73 +# Make sure log directory exists
  74 +mkdir -p $USE_DIR/log
  75 +
  76 +
60 77 # Add ERTS bin dir to our path
61 78 ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
62 79
@@ -65,19 +82,30 @@ NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
65 82
66 83 # Check the first argument for instructions
67 84 case "$1" in
68   - start)
  85 + start|start_boot)
69 86 # Make sure there is not already a node running
70 87 RES=`$NODETOOL ping`
71 88 if [ "$RES" = "pong" ]; then
72 89 echo "Node is already running!"
73 90 exit 1
74 91 fi
75   - shift # remove $1
  92 + case "$1" in
  93 + start)
  94 + shift
  95 + START_OPTION="console"
  96 + HEART_OPTION="start"
  97 + ;;
  98 + start_boot)
  99 + shift
  100 + START_OPTION="console_boot"
  101 + HEART_OPTION="start_boot"
  102 + ;;
  103 + esac
76 104 RUN_PARAM=$(printf "\'%s\' " "$@")
77   - HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT start $RUN_PARAM"
  105 + HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT $HEART_OPTION $RUN_PARAM"
78 106 export HEART_COMMAND
79 107 mkdir -p $PIPE_DIR
80   - $ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT console $RUN_PARAM" 2>&1
  108 + $ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT $START_OPTION $RUN_PARAM" 2>&1
81 109 ;;
82 110
83 111 stop)
@@ -171,12 +199,18 @@ case "$1" in
171 199 $ERTS_PATH/escript $RUNNER_BASE_DIR/bin/install_upgrade.escript $node_name $erlang_cookie $2
172 200 ;;
173 201
174   - console|console_clean)
  202 + console|console_clean|console_boot)
175 203 # .boot file typically just $SCRIPT (ie, the app name)
176   - # however, for debugging, sometimes start_clean.boot is useful:
  204 + # however, for debugging, sometimes start_clean.boot is useful.
  205 + # For e.g. 'setup', one may even want to name another boot script.
177 206 case "$1" in
178 207 console) BOOTFILE=$SCRIPT ;;
179 208 console_clean) BOOTFILE=start_clean ;;
  209 + console_boot)
  210 + shift
  211 + BOOTFILE="$1"
  212 + shift
  213 + ;;
180 214 esac
181 215 # Setup beam-required vars
182 216 ROOTDIR=$RUNNER_BASE_DIR
@@ -226,7 +260,7 @@ case "$1" in
226 260 exec $CMD -- ${1+"$@"}
227 261 ;;
228 262 *)
229   - echo "Usage: $SCRIPT {start|foreground|stop|restart|reboot|ping|console|console_clean|attach|upgrade}"
  263 + echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|console_clean|console_boot <file>|attach|upgrade}"
230 264 exit 1
231 265 ;;
232 266 esac

0 comments on commit c028225

Please sign in to comment.
Something went wrong with that request. Please try again.