From 55097d9aa9759418c612a6c6e6fc2751e968f27e Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Thu, 21 Jul 2016 18:05:46 +0800 Subject: [PATCH] 2.0 - move to emqttd-relx --- bin/emqttd | 473 ------------------------------------ bin/emqttd.cmd | 108 -------- bin/emqttd_ctl | 83 ------- bin/install_upgrade_escript | 143 ----------- bin/nodetool | 238 ------------------ bin/start_erl.cmd | 50 ---- 6 files changed, 1095 deletions(-) delete mode 100755 bin/emqttd delete mode 100644 bin/emqttd.cmd delete mode 100755 bin/emqttd_ctl delete mode 100755 bin/install_upgrade_escript delete mode 100755 bin/nodetool delete mode 100644 bin/start_erl.cmd diff --git a/bin/emqttd b/bin/emqttd deleted file mode 100755 index e04524fd4..000000000 --- a/bin/emqttd +++ /dev/null @@ -1,473 +0,0 @@ -#!/bin/sh -# -*- tab-width:4;indent-tabs-mode:nil -*- -# ex: ts=4 sw=4 et - -set -e - -SCRIPT=$(readlink $0 || true) -if [ -z $SCRIPT ]; then - SCRIPT=$0 -fi; -SCRIPT_DIR="$(cd `dirname "$SCRIPT"` && pwd -P)" -RELEASE_ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)" -REL_NAME="emqttd" -REL_VSN="{{ rel_vsn }}" -ERTS_VSN="{{ erts_vsn }}" -CODE_LOADING_MODE="${CODE_LOADING_MODE:-embedded}" -REL_DIR="$RELEASE_ROOT_DIR/releases/$REL_VSN" -ERL_OPTS="{{ erl_opts }}" -RUNNER_LOG_DIR="${RUNNER_LOG_DIR:-$RELEASE_ROOT_DIR/log}" - -# Warn the user if ulimit -n is less than 1024 -ULIMIT_F=`ulimit -n` -if [ "$ULIMIT_F" -lt 1024 ]; then - echo "!!!!" - echo "!!!! WARNING: ulimit -n is ${ULIMIT_F}; 1024 is the recommended minimum." - echo "!!!!" -fi - -find_erts_dir() { - __erts_dir="$RELEASE_ROOT_DIR/erts-$ERTS_VSN" - if [ -d "$__erts_dir" ]; then - ERTS_DIR="$__erts_dir"; - ROOTDIR="$RELEASE_ROOT_DIR" - else - __erl="$(which erl)" - code="io:format(\"~s\", [code:root_dir()]), halt()." - __erl_root="$("$__erl" -noshell -eval "$code")" - ERTS_DIR="$__erl_root/erts-$ERTS_VSN" - ROOTDIR="$__erl_root" - fi -} - -# Get node pid -relx_get_pid() { - if output="$(relx_nodetool rpcterms os getpid)" - then - echo "$output" | sed -e 's/"//g' - return 0 - else - echo "$output" - return 1 - fi -} - -relx_get_nodename() { - id="longname$(relx_gen_id)-${NAME}" - "$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell ${NAME_TYPE} $id -} - -# Connect to a remote node -relx_rem_sh() { - # Generate a unique id used to allow multiple remsh to the same node - # transparently - id="remsh$(relx_gen_id)-${NAME}" - - # Get the node's ticktime so that we use the same thing. - TICKTIME="$(relx_nodetool rpcterms net_kernel get_net_ticktime)" - - # Setup remote shell command to control node - exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot start_clean \ - -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ - -setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME -} - -# Generate a random id -relx_gen_id() { - od -t x -N 4 /dev/urandom | head -n1 | awk '{print $2}' -} - -# Control a node -relx_nodetool() { - command="$1"; shift - - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ - -setcookie "$COOKIE" "$command" $@ -} - -# Run an escript in the node's environment -relx_escript() { - shift; scriptpath="$1"; shift - export RELEASE_ROOT_DIR - - "$ERTS_DIR/bin/escript" "$ROOTDIR/$scriptpath" $@ -} - -# Output a start command for the last argument of run_erl -relx_start_command() { - printf "exec \"%s\" \"%s\"" "$RELEASE_ROOT_DIR/bin/$REL_NAME" \ - "$START_OPTION" -} - -# Use $CWD/vm.args if exists, otherwise releases/VSN/vm.args -if [ -z "$VMARGS_PATH" ]; then - if [ -f "$RELEASE_ROOT_DIR/vm.args" ]; then - VMARGS_PATH="$RELEASE_ROOT_DIR/vm.args" - else - VMARGS_PATH="$REL_DIR/vm.args" - fi -fi - -orig_vmargs_path="$VMARGS_PATH.orig" -if [ $RELX_REPLACE_OS_VARS ]; then - #Make sure we don't break dev mode by keeping the symbolic link to - #the user's vm.args - if [ ! -L "$orig_vmargs_path" ]; then - #we're in copy mode, rename the vm.args file to vm.args.orig - mv "$VMARGS_PATH" "$orig_vmargs_path" - fi - - awk '{while(match($0,"[$]{[^}]*}")) {var=substr($0,RSTART+2,RLENGTH -3);gsub("[$]{"var"}",ENVIRON[var])}}1' < "$orig_vmargs_path" > "$VMARGS_PATH" - else - #We don't need to replace env. vars, just rename the - #symlink vm.args.orig to vm.args, and keep it as a - #symlink. - if [ -L "$orig_vmargs_path" ]; then - mv "$orig_vmargs_path" "$VMARGS_PATH" - fi -fi - -# Make sure log directory exists -mkdir -p "$RUNNER_LOG_DIR" - -# Use $CWD/sys.config if exists, otherwise releases/VSN/sys.config -if [ -z "$RELX_CONFIG_PATH" ]; then - if [ -f "$RELEASE_ROOT_DIR/sys.config" ]; then - RELX_CONFIG_PATH="$RELEASE_ROOT_DIR/sys.config" - else - RELX_CONFIG_PATH="$REL_DIR/sys.config" - fi -fi - -orig_relx_config_path="$RELX_CONFIG_PATH.orig" -if [ $RELX_REPLACE_OS_VARS ]; then - #Make sure we don't break dev mode by keeping the symbolic link to - #the user's sys.config - if [ ! -L "$orig_relx_config_path" ]; then - #We're in copy mode, rename sys.config to sys.config.orig - mv "$RELX_CONFIG_PATH" "$orig_relx_config_path" - fi - - awk '{while(match($0,"[$]{[^}]*}")) {var=substr($0,RSTART+2,RLENGTH -3);gsub("[$]{"var"}",ENVIRON[var])}}1' < "$orig_relx_config_path" > "$RELX_CONFIG_PATH" - else - #We don't need to replace env. vars, just rename the - #symlink sys.config.orig to sys.config. Keep it as - #a symlink. - if [ -L "$orig_relx_config_path" ]; then - mv "$orig_relx_config_path" "$RELX_CONFIG_PATH" - fi -fi - -# Extract the target node name from node.args -NAME_ARG=$(egrep '^-s?name' "$VMARGS_PATH" || true) -if [ -z "$NAME_ARG" ]; then - echo "vm.args needs to have either -name or -sname parameter." - exit 1 -fi - -# Extract the name type and name from the NAME_ARG for REMSH -NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" -NAME="$(echo "$NAME_ARG" | awk '{print $2}')" - -PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}" - -# Extract the target cookie -COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)" -if [ -z "$COOKIE_ARG" ]; then - echo "vm.args needs to have a -setcookie parameter." - exit 1 -fi - -# Extract cookie name from COOKIE_ARG -COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" - -find_erts_dir -export ROOTDIR="$RELEASE_ROOT_DIR" -export BINDIR="$ERTS_DIR/bin" -export EMU="beam" -export PROGNAME="erl" -export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH" -ERTS_LIB_DIR="$ERTS_DIR/../lib" -MNESIA_DATA_DIR="$ROOTDIR/data/mnesia/$NAME" - -cd "$ROOTDIR" - -# User can specify an sname without @hostname -# This will fail when creating remote shell -# So here we check for @ and add @hostname if missing -case $NAME in - *@*) - # Nothing to do - ;; - *) - NAME=$NAME@$(relx_get_nodename) - ;; -esac - -# Check the first argument for instructions -case "$1" in - 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 - # Save this for later. - CMD=$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="$@" - - # Set arguments for the heart command - set -- "$SCRIPT_DIR/$REL_NAME" "$HEART_OPTION" - [ "$RUN_PARAM" ] && set -- "$@" "$RUN_PARAM" - - # Export the HEART_COMMAND - HEART_COMMAND="$RELEASE_ROOT_DIR/bin/$REL_NAME $CMD" - export HEART_COMMAND - - mkdir -p "$PIPE_DIR" - - "$BINDIR/run_erl" -daemon "$PIPE_DIR" "$RUNNER_LOG_DIR" \ - "$(relx_start_command)" - ;; - - stop) - # Wait for the node to completely stop... - PID="$(relx_get_pid)" - if ! relx_nodetool "stop"; then - exit 1 - fi - while $(kill -s 0 "$PID" 2>/dev/null); - do - sleep 1 - done - ;; - - restart) - ## Restart the VM without exiting the process - if ! relx_nodetool "restart"; then - exit 1 - fi - ;; - - reboot) - ## Restart the VM completely (uses heart to restart it) - if ! relx_nodetool "reboot"; then - exit 1 - fi - ;; - - pid) - ## Get the VM's pid - if ! relx_get_pid; then - exit 1 - fi - ;; - - ping) - ## See if the VM is alive - if ! relx_nodetool "ping"; then - exit 1 - fi - ;; - - escript) - ## Run an escript under the node's environment - if ! relx_escript $@; then - exit 1 - fi - ;; - - attach) - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - shift - exec "$BINDIR/to_erl" "$PIPE_DIR" - ;; - - remote_console) - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - shift - relx_rem_sh - ;; - - upgrade|downgrade|install) - if [ -z "$2" ]; then - echo "Missing package argument" - echo "Usage: $REL_NAME $1 {package base name}" - echo "NOTE {package base name} MUST NOT include the .tar.gz suffix" - exit 1 - fi - - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \ - "install" "$REL_NAME" "$NAME_TYPE" "$NAME" "$COOKIE" "$2" - ;; - - unpack) - if [ -z "$2" ]; then - echo "Missing package argument" - echo "Usage: $REL_NAME $1 {package base name}" - echo "NOTE {package base name} MUST NOT include the .tar.gz suffix" - exit 1 - fi - - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \ - "unpack" "$REL_NAME" "$NAME_TYPE" "$NAME" "$COOKIE" "$2" - ;; - - console|console_clean|console_boot) - # .boot file typically just $REL_NAME (ie, the app name) - # 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) - if [ -f "$REL_DIR/$REL_NAME.boot" ]; then - BOOTFILE="$REL_DIR/$REL_NAME" - else - BOOTFILE="$REL_DIR/start" - fi - ;; - console_clean) - BOOTFILE="$ROOTDIR/bin/start_clean" - ;; - console_boot) - shift - BOOTFILE="$1" - shift - ;; - esac - # Setup beam-required vars - EMU="beam" - PROGNAME="${0#*/}" - - export EMU - export PROGNAME - - # Store passed arguments since they will be erased by `set` - ARGS="$@" - - # Build an array of arguments to pass to exec later on - # Build it here because this command will be used for logging. - set -- "$BINDIR/erlexec" -boot "$BOOTFILE" -mode "$CODE_LOADING_MODE" \ - -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ - -config "$RELX_CONFIG_PATH" \ - -mnesia dir "\"${MNESIA_DATA_DIR}\"" \ - -args_file "$VMARGS_PATH" - - # Dump environment info for logging purposes - echo "Exec: $@" -- ${1+$ARGS} - echo "Root: $ROOTDIR" - - # Log the startup - echo "$RELEASE_ROOT_DIR" - logger -t "$REL_NAME[$$]" "Starting up" - - # Start the VM - exec "$@" -- ${1+$ARGS} - ;; - - foreground) - # start up the release in the foreground for use by runit - # or other supervision services - - [ -f "$REL_DIR/$REL_NAME.boot" ] && BOOTFILE="$REL_NAME" || BOOTFILE=start - FOREGROUNDOPTIONS="-noshell -noinput +Bd" - - # Setup beam-required vars - EMU=beam - PROGNAME="${0#*/}" - - export EMU - export PROGNAME - - # Store passed arguments since they will be erased by `set` - ARGS="$@" - - # Build an array of arguments to pass to exec later on - # Build it here because this command will be used for logging. - set -- "$BINDIR/erlexec" $FOREGROUNDOPTIONS \ - -boot "$REL_DIR/$BOOTFILE" -mode "$CODE_LOADING_MODE" -config "$RELX_CONFIG_PATH" \ - -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \ - -mnesia dir "\"${MNESIA_DATA_DIR}\"" \ - -args_file "$VMARGS_PATH" - - # Dump environment info for logging purposes - echo "Exec: $@" -- ${1+$ARGS} - echo "Root: $ROOTDIR" - - # Start the VM - exec "$@" -- ${1+$ARGS} - ;; - rpc) - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - shift - - relx_nodetool rpc $@ - ;; - rpcterms) - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - shift - - relx_nodetool rpcterms $@ - ;; - eval) - # Make sure a node IS running - if ! relx_nodetool "ping" > /dev/null; then - echo "Node is not running!" - exit 1 - fi - - shift - relx_nodetool "eval" $@ - ;; - *) - echo "Usage: $REL_NAME {start|start_boot |foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot |attach|remote_console|upgrade|escript|rpc|rpcterms|eval}" - exit 1 - ;; -esac - -exit 0 diff --git a/bin/emqttd.cmd b/bin/emqttd.cmd deleted file mode 100644 index effa49536..000000000 --- a/bin/emqttd.cmd +++ /dev/null @@ -1,108 +0,0 @@ -@echo off -@setlocal -@setlocal enabledelayedexpansion - -@set node_name=emqttd - -@rem Get the absolute path to the parent directory, -@rem which is assumed to be the node root. -@for /F "delims=" %%I in ("%~dp0..") do @set node_root=%%~fI - -@set releases_dir=%node_root%\releases -@set runner_etc_dir=%node_root%\etc - -@rem Parse ERTS version and release version from start_erl.data -@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 vm_args=%runner_etc_dir%\vm.args -@set sys_config=%runner_etc_dir%\emqttd.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 -@if "%1"=="start" @goto start -@if "%1"=="stop" @goto stop -@if "%1"=="restart" @call :stop && @goto start -@if "%1"=="console" @goto console -@if "%1"=="query" @goto query -@if "%1"=="attach" @goto attach -@if "%1"=="upgrade" @goto upgrade -@echo Unknown command: "%1" - -:usage -@echo Usage: %~n0 [install^|uninstall^|start^|stop^|restart^|console^|query^|attach^|upgrade] -@goto :EOF - -:install -@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 -@%erlsrv% remove %service_name% -@%epmd% -kill -@goto :EOF - -:start -@%erlsrv% start %service_name% -@goto :EOF - -:stop -@%erlsrv% stop %service_name% -@goto :EOF - -:console -set dest_path=%~dp0 -cd /d !dest_path!..\plugins -set current_path=%cd% -set plugins= -for /d %%P in (*) do ( -set "plugins=!plugins!"!current_path!\%%P\ebin" " -) -cd /d %node_root% - -@start "%node_name% console" %werl% -boot "%node_boot_script%" -config "%sys_config%" -args_file "%vm_args%" -sname %node_name% -pa %plugins% -@goto :EOF - -:query -@%erlsrv% list %service_name% -@exit %ERRORLEVEL% -@goto :EOF - -:attach -@for /f "usebackq" %%I in (`hostname`) do @set hostname=%%I -start "%node_name% attach" %werl% -boot "%clean_boot_script%" -remsh %node_name%@%hostname% -sname console -setcookie %erlang_cookie% -@goto :EOF - -:upgrade -@if "%2"=="" ( - @echo Missing upgrade package argument - @echo Usage: %~n0 upgrade {package base name} - @echo NOTE {package base name} MUST NOT include the .tar.gz suffix - @goto :EOF -) -@%escript% %node_root%\bin\install_upgrade.escript %node_name% %erlang_cookie% %2 -@goto :EOF - -:set_trim -@set %1=%2 -@goto :EOF diff --git a/bin/emqttd_ctl b/bin/emqttd_ctl deleted file mode 100755 index a2d1a28bc..000000000 --- a/bin/emqttd_ctl +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/sh -# -*- tab-width:4;indent-tabs-mode:nil -*- -# ex: ts=4 sw=4 et - -set -e - -SCRIPT=$(readlink $0 || true) -if [ -z $SCRIPT ]; then - SCRIPT=$0 -fi; -SCRIPT_DIR="$(cd `dirname "$SCRIPT"` && pwd -P)" -RELEASE_ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd -P)" -REL_NAME="emqttd" -REL_VSN="{{ rel_vsn }}" -ERTS_VSN="{{ erts_vsn }}" -REL_DIR="$RELEASE_ROOT_DIR/releases/$REL_VSN" -ERL_OPTS="{{ erl_opts }}" -RUNNER_LOG_DIR="${RUNNER_LOG_DIR:-$RELEASE_ROOT_DIR/log}" - -find_erts_dir() { - __erts_dir="$RELEASE_ROOT_DIR/erts-$ERTS_VSN" - if [ -d "$__erts_dir" ]; then - ERTS_DIR="$__erts_dir"; - ROOTDIR="$RELEASE_ROOT_DIR" - else - __erl="$(which erl)" - code="io:format(\"~s\", [code:root_dir()]), halt()." - __erl_root="$("$__erl" -noshell -eval "$code")" - ERTS_DIR="$__erl_root/erts-$ERTS_VSN" - ROOTDIR="$__erl_root" - fi -} - -relx_get_nodename() { - id="longname$(relx_gen_id)-${NAME}" - "$BINDIR/erl" -boot start_clean -eval '[Host] = tl(string:tokens(atom_to_list(node()),"@")), io:format("~s~n", [Host]), halt()' -noshell ${NAME_TYPE} $id -} - -# Control a node -relx_nodetool() { - command="$1"; shift - - "$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \ - -setcookie "$COOKIE" "$command" $@ -} - -# Use $CWD/vm.args if exists, otherwise releases/VSN/vm.args -if [ -z "$VMARGS_PATH" ]; then - if [ -f "$RELEASE_ROOT_DIR/vm.args" ]; then - VMARGS_PATH="$RELEASE_ROOT_DIR/vm.args" - else - VMARGS_PATH="$REL_DIR/vm.args" - fi -fi - -# Extract the target node name from node.args -NAME_ARG=$(egrep '^-s?name' "$VMARGS_PATH" || true) -if [ -z "$NAME_ARG" ]; then - echo "vm.args needs to have either -name or -sname parameter." - exit 1 -fi - -# Extract the name type and name from the NAME_ARG for REMSH -NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')" -NAME="$(echo "$NAME_ARG" | awk '{print $2}')" - -# Extract the target cookie -COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)" -if [ -z "$COOKIE_ARG" ]; then - echo "vm.args needs to have a -setcookie parameter." - exit 1 -fi - -# Extract cookie name from COOKIE_ARG -COOKIE="$(echo "$COOKIE_ARG" | awk '{print $2}')" - -find_erts_dir -export ROOTDIR="$RELEASE_ROOT_DIR" -export BINDIR="$ERTS_DIR/bin" -cd "$ROOTDIR" - -relx_nodetool rpc emqttd_ctl run $@ - diff --git a/bin/install_upgrade_escript b/bin/install_upgrade_escript deleted file mode 100755 index 4abce858d..000000000 --- a/bin/install_upgrade_escript +++ /dev/null @@ -1,143 +0,0 @@ -#!/usr/bin/env escript -%%! -noshell -noinput -%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et - --define(TIMEOUT, 300000). --define(INFO(Fmt,Args), io:format(Fmt,Args)). - -%% Unpack or upgrade to a new tar.gz release -main(["unpack", RelName, NameTypeArg, NodeName, Cookie, VersionArg]) -> - TargetNode = start_distribution(NodeName, NameTypeArg, Cookie), - WhichReleases = which_releases(TargetNode), - Version = parse_version(VersionArg), - case proplists:get_value(Version, WhichReleases) of - undefined -> - %% not installed, so unpack tarball: - ?INFO("Release ~s not found, attempting to unpack releases/~s/~s.tar.gz~n",[Version,Version,RelName]), - ReleasePackage = Version ++ "/" ++ RelName, - case rpc:call(TargetNode, release_handler, unpack_release, - [ReleasePackage], ?TIMEOUT) of - {ok, Vsn} -> - ?INFO("Unpacked successfully: ~p~n", [Vsn]); - {error, UnpackReason} -> - print_existing_versions(TargetNode), - ?INFO("Unpack failed: ~p~n",[UnpackReason]), - erlang:halt(2) - end; - old -> - %% no need to unpack, has been installed previously - ?INFO("Release ~s is marked old, switching to it.~n",[Version]); - unpacked -> - ?INFO("Release ~s is already unpacked, now installing.~n",[Version]); - current -> - ?INFO("Release ~s is already installed and current. Making permanent.~n",[Version]); - permanent -> - ?INFO("Release ~s is already installed, and set permanent.~n",[Version]) - end; -main(["install", RelName, NameTypeArg, NodeName, Cookie, VersionArg]) -> - TargetNode = start_distribution(NodeName, NameTypeArg, Cookie), - WhichReleases = which_releases(TargetNode), - Version = parse_version(VersionArg), - case proplists:get_value(Version, WhichReleases) of - undefined -> - %% not installed, so unpack tarball: - ?INFO("Release ~s not found, attempting to unpack releases/~s/~s.tar.gz~n",[Version,Version,RelName]), - ReleasePackage = Version ++ "/" ++ RelName, - case rpc:call(TargetNode, release_handler, unpack_release, - [ReleasePackage], ?TIMEOUT) of - {ok, Vsn} -> - ?INFO("Unpacked successfully: ~p~n", [Vsn]), - install_and_permafy(TargetNode, RelName, Vsn); - {error, UnpackReason} -> - print_existing_versions(TargetNode), - ?INFO("Unpack failed: ~p~n",[UnpackReason]), - erlang:halt(2) - end; - old -> - %% no need to unpack, has been installed previously - ?INFO("Release ~s is marked old, switching to it.~n",[Version]), - install_and_permafy(TargetNode, RelName, Version); - unpacked -> - ?INFO("Release ~s is already unpacked, now installing.~n",[Version]), - install_and_permafy(TargetNode, RelName, Version); - current -> %% installed and in-use, just needs to be permanent - ?INFO("Release ~s is already installed and current. Making permanent.~n",[Version]), - permafy(TargetNode, RelName, Version); - permanent -> - ?INFO("Release ~s is already installed, and set permanent.~n",[Version]) - end; -main(_) -> - erlang:halt(1). - -parse_version(V) when is_list(V) -> - hd(string:tokens(V,"/")). - -install_and_permafy(TargetNode, RelName, Vsn) -> - case rpc:call(TargetNode, release_handler, check_install_release, [Vsn], ?TIMEOUT) of - {ok, _OtherVsn, _Desc} -> - ok; - {error, Reason} -> - ?INFO("ERROR: release_handler:check_install_release failed: ~p~n",[Reason]), - erlang:halt(3) - end, - case rpc:call(TargetNode, release_handler, install_release, [Vsn], ?TIMEOUT) of - {ok, _, _} -> - ?INFO("Installed Release: ~s~n", [Vsn]), - permafy(TargetNode, RelName, Vsn), - ok; - {error, {no_such_release, Vsn}} -> - VerList = - iolist_to_binary( - [io_lib:format("* ~s\t~s~n",[V,S]) || {V,S} <- which_releases(TargetNode)]), - ?INFO("Installed versions:~n~s", [VerList]), - ?INFO("ERROR: Unable to revert to '~s' - not installed.~n", [Vsn]), - erlang:halt(2) - end. - -permafy(TargetNode, RelName, Vsn) -> - ok = rpc:call(TargetNode, release_handler, make_permanent, [Vsn], ?TIMEOUT), - file:copy(filename:join(["bin", RelName++"-"++Vsn]), - filename:join(["bin", RelName])), - ?INFO("Made release permanent: ~p~n", [Vsn]), - ok. - -which_releases(TargetNode) -> - R = rpc:call(TargetNode, release_handler, which_releases, [], ?TIMEOUT), - [ {V, S} || {_,V,_, S} <- R ]. - -print_existing_versions(TargetNode) -> - VerList = iolist_to_binary([ - io_lib:format("* ~s\t~s~n",[V,S]) - || {V,S} <- which_releases(TargetNode) ]), - ?INFO("Installed versions:~n~s", [VerList]). - -start_distribution(NodeName, NameTypeArg, Cookie) -> - MyNode = make_script_node(NodeName), - {ok, _Pid} = net_kernel:start([MyNode, get_name_type(NameTypeArg)]), - erlang:set_cookie(node(), list_to_atom(Cookie)), - TargetNode = list_to_atom(NodeName), - case {net_kernel:connect_node(TargetNode), - net_adm:ping(TargetNode)} of - {true, pong} -> - ok; - {_, pang} -> - io:format("Node ~p not responding to pings.\n", [TargetNode]), - erlang:halt(1) - end, - {ok, Cwd} = file:get_cwd(), - ok = rpc:call(TargetNode, file, set_cwd, [Cwd], ?TIMEOUT), - TargetNode. - -make_script_node(Node) -> - [Name, Host] = string:tokens(Node, "@"), - list_to_atom(lists:concat([Name, "_upgrader_", os:getpid(), "@", Host])). - -%% get name type from arg -get_name_type(NameTypeArg) -> - case NameTypeArg of - "-sname" -> - shortnames; - _ -> - longnames - end. diff --git a/bin/nodetool b/bin/nodetool deleted file mode 100755 index d76c228b1..000000000 --- a/bin/nodetool +++ /dev/null @@ -1,238 +0,0 @@ -#!/usr/bin/env escript -%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et -%% ------------------------------------------------------------------- -%% -%% nodetool: Helper Script for interacting with live nodes -%% -%% ------------------------------------------------------------------- --mode(compile). - -main(Args) -> - ok = start_epmd(), - %% Extract the args - {RestArgs, TargetNode} = process_args(Args, [], undefined), - - %% process_args() has side-effects (e.g. when processing "-name"), - %% so take care of app-starting business first. - [application:start(App) || App <- [crypto, public_key, ssl]], - - %% any commands that don't need a running node - case RestArgs of - ["chkconfig", File] -> - case file:consult(File) of - {ok, Terms} -> - case validate(Terms) of - ok -> - io:format("ok\n"), - halt(0); - {error, Problems} -> - lists:foreach(fun print_issue/1, Problems), - %% halt(1) if any problems were errors - halt(case [x || {error, _} <- Problems] of - [] -> 0; - _ -> 1 - end) - end; - {error, {Line, Mod, Term}} -> - io:format(standard_error, ["Error on line ", file:format_error({Line, Mod, Term}), "\n"], []), - halt(1); - {error, Error} -> - io:format(standard_error, ["Error reading config file: ", file:format_error(Error), "\n"], []), - halt(1) - end; - _ -> - ok - end, - - %% See if the node is currently running -- if it's not, we'll bail - case {net_kernel:hidden_connect_node(TargetNode), net_adm:ping(TargetNode)} of - {true, pong} -> - ok; - {false,pong} -> - io:format("Failed to connect to node ~p .\n", [TargetNode]), - halt(1); - {_, pang} -> - io:format("Node ~p not responding to pings.\n", [TargetNode]), - halt(1) - end, - - case RestArgs of - ["getpid"] -> - io:format("~p\n", [list_to_integer(rpc:call(TargetNode, os, getpid, []))]); - ["ping"] -> - %% If we got this far, the node already responsed to a ping, so just dump - %% a "pong" - io:format("pong\n"); - ["stop"] -> - io:format("~p\n", [rpc:call(TargetNode, init, stop, [], 60000)]); - ["restart"] -> - io:format("~p\n", [rpc:call(TargetNode, init, restart, [], 60000)]); - ["reboot"] -> - io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]); - ["rpc", Module, Function | RpcArgs] -> - case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), - [RpcArgs], 60000) of - ok -> - ok; - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - _ -> - halt(1) - end; - ["rpc_infinity", Module, Function | RpcArgs] -> - case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), [RpcArgs], infinity) of - ok -> - ok; - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - _ -> - halt(1) - end; - ["rpcterms", Module, Function, ArgsAsString] -> - case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), - consult(lists:flatten(ArgsAsString)), 60000) of - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1); - Other -> - io:format("~p\n", [Other]) - end; - ["eval" | ListOfArgs] -> - % shells may process args into more than one, and end up stripping - % spaces, so this converts all of that to a single string to parse - String = binary_to_list( - list_to_binary( - string:join(ListOfArgs," ") - ) - ), - - % then just as a convenience to users, if they forgot a trailing - % '.' add it for them. - Normalized = - case lists:reverse(String) of - [$. | _] -> String; - R -> lists:reverse([$. | R]) - end, - - % then scan and parse the string - {ok, Scanned, _} = erl_scan:string(Normalized), - {ok, Parsed } = erl_parse:parse_exprs(Scanned), - - % and evaluate it on the remote node - case rpc:call(TargetNode, erl_eval, exprs, [Parsed, [] ]) of - {value, Value, _} -> - io:format ("~p\n",[Value]); - {badrpc, Reason} -> - io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), - halt(1) - end; - Other -> - io:format("Other: ~p\n", [Other]), - io:format("Usage: nodetool {chkconfig|getpid|ping|stop|restart|reboot|rpc|rpc_infinity|rpcterms|eval [Terms]} [RPC]\n") - end, - net_kernel:stop(). - -process_args([], Acc, TargetNode) -> - {lists:reverse(Acc), TargetNode}; -process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) -> - erlang:set_cookie(node(), list_to_atom(Cookie)), - process_args(Rest, Acc, TargetNode); -process_args(["-name", TargetName | Rest], Acc, _) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, longnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args(["-sname", TargetName | Rest], Acc, _) -> - ThisNode = append_node_suffix(TargetName, "_maint_"), - {ok, _} = net_kernel:start([ThisNode, shortnames]), - process_args(Rest, Acc, nodename(TargetName)); -process_args([Arg | Rest], Acc, Opts) -> - process_args(Rest, [Arg | Acc], Opts). - - -start_epmd() -> - [] = os:cmd("\"" ++ epmd_path() ++ "\" -daemon"), - ok. - -epmd_path() -> - ErtsBinDir = filename:dirname(escript:script_name()), - Name = "epmd", - case os:find_executable(Name, ErtsBinDir) of - false -> - case os:find_executable(Name) of - false -> - io:format("Could not find epmd.~n"), - halt(1); - GlobalEpmd -> - GlobalEpmd - end; - Epmd -> - Epmd - end. - - -nodename(Name) -> - case string:tokens(Name, "@") of - [_Node, _Host] -> - list_to_atom(Name); - [Node] -> - [_, Host] = string:tokens(atom_to_list(node()), "@"), - list_to_atom(lists:concat([Node, "@", Host])) - end. - -append_node_suffix(Name, Suffix) -> - case string:tokens(Name, "@") of - [Node, Host] -> - list_to_atom(lists:concat([Node, Suffix, os:getpid(), "@", Host])); - [Node] -> - list_to_atom(lists:concat([Node, Suffix, os:getpid()])) - end. - -%% -%% Given a string or binary, parse it into a list of terms, ala file:consult/0 -%% -consult(Str) when is_list(Str) -> - consult([], Str, []); -consult(Bin) when is_binary(Bin)-> - consult([], binary_to_list(Bin), []). - -consult(Cont, Str, Acc) -> - case erl_scan:tokens(Cont, Str, 0) of - {done, Result, Remaining} -> - case Result of - {ok, Tokens, _} -> - {ok, Term} = erl_parse:parse_term(Tokens), - consult([], Remaining, [Term | Acc]); - {eof, _Other} -> - lists:reverse(Acc); - {error, Info, _} -> - {error, Info} - end; - {more, Cont1} -> - consult(Cont1, eof, Acc) - end. - -%% -%% Validation functions for checking the emqttd.config -%% -validate([Terms]) -> - Results = [ValidateFun(Terms) || ValidateFun <- get_validation_funs()], - Failures = [Res || Res <- Results, Res /= true], - case Failures of - [] -> - ok; - _ -> - {error, Failures} - end. - -%% Some initial and basic checks for the app.config file -get_validation_funs() -> - [ ]. - -print_issue({warning, Warning}) -> - io:format(standard_error, "Warning in emqttd.config: ~s~n", [Warning]); -print_issue({error, Error}) -> - io:format(standard_error, "Error in emqttd.config: ~s~n", [Error]). - diff --git a/bin/start_erl.cmd b/bin/start_erl.cmd deleted file mode 100644 index 8285c0534..000000000 --- a/bin/start_erl.cmd +++ /dev/null @@ -1,50 +0,0 @@ -@setlocal -@echo off -@setlocal enabledelayedexpansion - -@rem Parse arguments. erlsrv.exe prepends erl arguments prior to first ++. -@rem Other args are position dependent. -@set args="%*" -@for /F "delims=++ tokens=1,2,3" %%I in (%args%) do @( - @set erl_args=%%I - @call :set_trim node_name %%J - @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 "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%" - -@if exist "%releases_dir%\%release_version%\sys.config" ( - @set app_config="%releases_dir%\%release_version%\sys.config" -) else ( - @set app_config="%node_root%\etc\emqttd.config" -) - -@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 dest_path=%~dp0 -cd /d !dest_path!..\plugins -set current_path=%cd% -set plugins= -for /d %%P in (*) do ( -set "plugins=!plugins!"!current_path!\%%P\ebin" " -) -cd /d %node_root% -@%erl_exe% %erl_args% -boot %boot_file% -config %app_config% -args_file %vm_args% -pa %plugins% - -:set_trim -@set %1=%2 -@goto :EOF