diff options
Diffstat (limited to 'priv')
-rw-r--r-- | priv/shell-completion/bash/rebar | 7 | ||||
-rwxr-xr-x | priv/templates/simplenode.runner | 74 | ||||
-rw-r--r-- | priv/templates/simplenode.windows.runner.cmd | 38 | ||||
-rw-r--r-- | priv/templates/simplenode.windows.start_erl.cmd | 21 |
4 files changed, 94 insertions, 46 deletions
diff --git a/priv/shell-completion/bash/rebar b/priv/shell-completion/bash/rebar index 005325d..d76e2ba 100644 --- a/priv/shell-completion/bash/rebar +++ b/priv/shell-completion/bash/rebar @@ -10,9 +10,10 @@ _rebar() lopts=" --help --commands --verbose --force --jobs= --version" cmdsnvars="check-deps clean compile create create-app create-node ct \ doc delete-deps escriptize eunit get-deps generate generate-upgrade \ - help list-deps list-templates update-deps version xref overlay \ - apps= case= force=1 jobs= suites= verbose=1 appid= previous_release= \ - nodeid= root_dir= skip_deps=true skip_apps= template= template_dir=" + help list-deps list-templates qc update-deps version xref overlay \ + apps= case= force=1 jobs= suites= verbose=1 appid= \ + previous_release= nodeid= root_dir= skip_deps=true skip_apps= \ + template= template_dir=" if [[ ${cur} == --* ]] ; then COMPREPLY=( $(compgen -W "${lopts}" -- ${cur}) ) diff --git a/priv/templates/simplenode.runner b/priv/templates/simplenode.runner index 0293340..43d90bc 100755 --- a/priv/templates/simplenode.runner +++ b/priv/templates/simplenode.runner @@ -4,9 +4,10 @@ RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd) +CALLER_DIR=$PWD + RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*} RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc -RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log # Note the trailing slash on $PIPE_DIR/ PIPE_DIR=/tmp/$RUNNER_BASE_DIR/ RUNNER_USER= @@ -16,11 +17,6 @@ if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then exec sudo -u $RUNNER_USER -i $0 $@ fi -# Make sure CWD is set to runner base dir -cd $RUNNER_BASE_DIR - -# Make sure log directory exists -mkdir -p $RUNNER_LOG_DIR # Identify the script name SCRIPT=`basename $0` @@ -29,18 +25,32 @@ START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data` ERTS_VSN=${START_ERL% *} APP_VSN=${START_ERL#* } -# Use releases/VSN/vm.args if it exists otherwise use etc/vm.args -if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then - VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" +# Use $CWD/vm.args if exists, otherwise releases/APP_VSN/vm.args, or else etc/vm.args +if [ -e "$CALLER_DIR/vm.args" ]; then + VMARGS_PATH=$CALLER_DIR/vm.args + USE_DIR=$CALLER_DIR else - VMARGS_PATH="$RUNNER_ETC_DIR/vm.args" + USE_DIR=$RUNNER_BASE_DIR + if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" ]; then + VMARGS_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/vm.args" + else + VMARGS_PATH="$RUNNER_ETC_DIR/vm.args" + fi fi +RUNNER_LOG_DIR=$USE_DIR/log +# Make sure log directory exists +mkdir -p $RUNNER_LOG_DIR + # Use releases/VSN/sys.config if it exists otherwise use etc/app.config -if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then - CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" +if [ -e "$USE_DIR/sys.config" ]; then + CONFIG_PATH="$USE_DIR/sys.config" else - CONFIG_PATH="$RUNNER_ETC_DIR/app.config" + if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" ]; then + CONFIG_PATH="$RUNNER_BASE_DIR/releases/$APP_VSN/sys.config" + else + CONFIG_PATH="$RUNNER_ETC_DIR/app.config" + fi fi # Extract the target node name from node.args @@ -65,6 +75,13 @@ if [ -z "$COOKIE_ARG" ]; then exit 1 fi +# Make sure CWD is set to the right dir +cd $USE_DIR + +# Make sure log directory exists +mkdir -p $USE_DIR/log + + # Add ERTS bin dir to our path ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin @@ -76,19 +93,30 @@ REMSH="$ERTS_PATH/erl $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG" # Check the first argument for instructions case "$1" in - start) + start|start_boot) # Make sure there is not already a node running RES=`$NODETOOL ping` if [ "$RES" = "pong" ]; then echo "Node is already running!" exit 1 fi - shift # remove $1 + case "$1" in + start) + shift + START_OPTION="console" + HEART_OPTION="start" + ;; + start_boot) + shift + START_OPTION="console_boot" + HEART_OPTION="start_boot" + ;; + esac RUN_PARAM=$(printf "\'%s\' " "$@") - HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT start $RUN_PARAM" + HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT $HEART_OPTION $RUN_PARAM" export HEART_COMMAND mkdir -p $PIPE_DIR - $ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT console $RUN_PARAM" 2>&1 + $ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT $START_OPTION $RUN_PARAM" 2>&1 ;; stop) @@ -195,12 +223,18 @@ case "$1" in $ERTS_PATH/escript $RUNNER_BASE_DIR/bin/install_upgrade.escript $node_name $erlang_cookie $2 ;; - console|console_clean) + console|console_clean|console_boot) # .boot file typically just $SCRIPT (ie, the app name) - # however, for debugging, sometimes start_clean.boot is useful: + # however, for debugging, sometimes start_clean.boot is useful. + # For e.g. 'setup', one may even want to name another boot script. case "$1" in console) BOOTFILE=$SCRIPT ;; console_clean) BOOTFILE=start_clean ;; + console_boot) + shift + BOOTFILE="$1" + shift + ;; esac # Setup beam-required vars ROOTDIR=$RUNNER_BASE_DIR @@ -250,7 +284,7 @@ case "$1" in exec $CMD -- ${1+"$@"} ;; *) - echo "Usage: $SCRIPT {start|foreground|stop|restart|reboot|ping|console|console_clean|attach|remote_console|upgrade}" + echo "Usage: $SCRIPT {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade}" exit 1 ;; esac diff --git a/priv/templates/simplenode.windows.runner.cmd b/priv/templates/simplenode.windows.runner.cmd index b4e6b00..16da5b9 100644 --- a/priv/templates/simplenode.windows.runner.cmd +++ b/priv/templates/simplenode.windows.runner.cmd @@ -9,19 +9,28 @@ @set releases_dir=%node_root%\releases @rem Parse ERTS version and release version from start_erl.data -@for /F "tokens=1,2" %%I in (%releases_dir%\start_erl.data) do @( +@for /F "usebackq tokens=1,2" %%I in ("%releases_dir%\start_erl.data") do @( @call :set_trim erts_version %%I @call :set_trim release_version %%J ) -@rem extract erlang cookie from vm.args @set vm_args=%releases_dir%\%release_version%\vm.args -@for /f "usebackq tokens=1-2" %%I in (`findstr /b \-setcookie %vm_args%`) do @set erlang_cookie=%%J +@set sys_config=%releases_dir%\%release_version%\sys.config +@set node_boot_script=%releases_dir%\%release_version%\%node_name% +@set clean_boot_script=%releases_dir%\%release_version%\start_clean + +@rem extract erlang cookie from vm.args +@for /f "usebackq tokens=1-2" %%I in (`findstr /b \-setcookie "%vm_args%"`) do @set erlang_cookie=%%J @set erts_bin=%node_root%\erts-%erts_version%\bin @set service_name=%node_name%_%release_version% +@set erlsrv="%erts_bin%\erlsrv.exe" +@set epmd="%erts_bin%\epmd.exe" +@set escript="%erts_bin%\escript.exe" +@set werl="%erts_bin%\werl.exe" + @if "%1"=="usage" @goto usage @if "%1"=="install" @goto install @if "%1"=="uninstall" @goto uninstall @@ -39,34 +48,37 @@ @goto :EOF :install -@%erts_bin%\erlsrv.exe add %service_name% -c "Erlang node %node_name% in %node_root%" -sname %node_name% -w %node_root% -m %node_root%\bin\start_erl.cmd -args " ++ %node_name% ++ %node_root%" -stopaction "init:stop()." +@set description=Erlang node %node_name% in %node_root% +@set start_erl=%node_root%\bin\start_erl.cmd +@set args= ++ %node_name% ++ %node_root% +@%erlsrv% add %service_name% -c "%description%" -sname %node_name% -w "%node_root%" -m "%start_erl%" -args "%args%" -stopaction "init:stop()." @goto :EOF :uninstall -@%erts_bin%\erlsrv.exe remove %service_name% -@%erts_bin%\epmd.exe -kill +@%erlsrv% remove %service_name% +@%epmd% -kill @goto :EOF :start -@%erts_bin%\erlsrv.exe start %service_name% +@%erlsrv% start %service_name% @goto :EOF :stop -@%erts_bin%\erlsrv.exe stop %service_name% +@%erlsrv% stop %service_name% @goto :EOF :console -@start %erts_bin%\werl.exe -boot %releases_dir%\%release_version%\%node_name% -config %releases_dir%\%release_version%\sys.config -args_file %vm_args% -sname %node_name% +@start "%node_name% console" %werl% -boot "%node_boot_script%" -config "%sys_config%" -args_file "%vm_args%" -sname %node_name% @goto :EOF :query -@%erts_bin%\erlsrv.exe list %service_name% -@exit /b %ERRORLEVEL% +@%erlsrv% list %service_name% +@exit %ERRORLEVEL% @goto :EOF :attach @for /f "usebackq" %%I in (`hostname`) do @set hostname=%%I -start %erts_bin%\werl.exe -boot %releases_dir%\%release_version%\start_clean -remsh %node_name%@%hostname% -sname console -setcookie %erlang_cookie% +start "%node_name% attach" %werl% -boot "%clean_boot_script%" -remsh %node_name%@%hostname% -sname console -setcookie %erlang_cookie% @goto :EOF :upgrade @@ -76,7 +88,7 @@ start %erts_bin%\werl.exe -boot %releases_dir%\%release_version%\start_clean -re @echo NOTE {package base name} MUST NOT include the .tar.gz suffix @goto :EOF ) -@%erts_bin%\escript.exe %node_root%\bin\install_upgrade.escript %node_name% %erlang_cookie% %2 +@%escript% %node_root%\bin\install_upgrade.escript %node_name% %erlang_cookie% %2 @goto :EOF :set_trim diff --git a/priv/templates/simplenode.windows.start_erl.cmd b/priv/templates/simplenode.windows.start_erl.cmd index ef38d52..c0f2072 100644 --- a/priv/templates/simplenode.windows.start_erl.cmd +++ b/priv/templates/simplenode.windows.start_erl.cmd @@ -6,30 +6,31 @@ @for /F "delims=++ tokens=1,2,3" %%I in (%args%) do @( @set erl_args=%%I @call :set_trim node_name %%J - @call :set_trim node_root %%K + @rem Trim spaces from the left of %%K (node_root), which may have spaces inside + @for /f "tokens=* delims= " %%a in ("%%K") do @set node_root=%%a ) @set releases_dir=%node_root%\releases @rem parse ERTS version and release version from start_erl.dat -@for /F "tokens=1,2" %%I in (%releases_dir%\start_erl.data) do @( +@for /F "usebackq tokens=1,2" %%I in ("%releases_dir%\start_erl.data") do @( @call :set_trim erts_version %%I @call :set_trim release_version %%J ) -@set erl_exe=%node_root%\erts-%erts_version%\bin\erl.exe -@set boot_file=%releases_dir%\%release_version%\%node_name% +@set erl_exe="%node_root%\erts-%erts_version%\bin\erl.exe" +@set boot_file="%releases_dir%\%release_version%\%node_name%" -@if exist %releases_dir%\%release_version%\sys.config ( - @set app_config=%releases_dir%\%release_version%\sys.config +@if exist "%releases_dir%\%release_version%\sys.config" ( + @set app_config="%releases_dir%\%release_version%\sys.config" ) else ( - @set app_config=%node_root%\etc\app.config + @set app_config="%node_root%\etc\app.config" ) -@if exist %releases_dir%\%release_version%\vm.args ( - @set vm_args=%releases_dir%\%release_version%\vm.args +@if exist "%releases_dir%\%release_version%\vm.args" ( + @set vm_args="%releases_dir%\%release_version%\vm.args" ) else ( - @set vm_args=%node_root%\etc\vm.args + @set vm_args="%node_root%\etc\vm.args" ) @%erl_exe% %erl_args% -boot %boot_file% -config %app_config% -args_file %vm_args% |