diff options
Diffstat (limited to 'priv/templates')
-rw-r--r-- | priv/templates/simpleevent.erl | 60 | ||||
-rw-r--r-- | priv/templates/simpleevent.template | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | priv/templates/simplenode.install_upgrade.escript | 8 | ||||
-rw-r--r-- | priv/templates/simplenode.reltool.config | 2 | ||||
-rwxr-xr-x | priv/templates/simplenode.runner | 78 |
5 files changed, 138 insertions, 12 deletions
diff --git a/priv/templates/simpleevent.erl b/priv/templates/simpleevent.erl new file mode 100644 index 0000000..1d529a3 --- /dev/null +++ b/priv/templates/simpleevent.erl @@ -0,0 +1,60 @@ +-module({{eventid}}). +-behaviour(gen_event). + +%% ------------------------------------------------------------------ +%% API Function Exports +%% ------------------------------------------------------------------ + +-export([start_link/0, + add_handler/2]). + +%% ------------------------------------------------------------------ +%% gen_event Function Exports +%% ------------------------------------------------------------------ + +-export([init/1, + handle_event/2, + handle_call/2, + handle_info/2, + terminate/2, + code_change/3]). + +-record(state, {}). + +%% ------------------------------------------------------------------ +%% API Function Definitions +%% ------------------------------------------------------------------ + +start_link() -> + gen_event:start_link({local, ?MODULE}). + +add_handler(Handler, Args) -> + gen_event:add_handler(?MODULE, Handler, Args). + +%% ------------------------------------------------------------------ +%% gen_event Function Definitions +%% ------------------------------------------------------------------ + +init([]) -> + {ok, #state{}}. + +handle_event(_Event, State) -> + {ok, State}. + +handle_call(_Request, State) -> + Reply = ok, + {ok, Reply, State}. + +handle_info(_Info, State) -> + {ok, State}. + +terminate(_Reason, _State) -> + ok. + +code_change(_OldVsn, State, _Extra) -> + {ok, State}. + +%% ------------------------------------------------------------------ +%% Internal Function Definitions +%% ------------------------------------------------------------------ + diff --git a/priv/templates/simpleevent.template b/priv/templates/simpleevent.template new file mode 100644 index 0000000..68f3894 --- /dev/null +++ b/priv/templates/simpleevent.template @@ -0,0 +1,2 @@ +{variables, [{eventid, "myevent"}]}. +{template, "simpleevent.erl", "src/{{eventid}}.erl"}. diff --git a/priv/templates/simplenode.install_upgrade.escript b/priv/templates/simplenode.install_upgrade.escript index 56cea19..0d4cbe3 100644..100755 --- a/priv/templates/simplenode.install_upgrade.escript +++ b/priv/templates/simplenode.install_upgrade.escript @@ -6,6 +6,14 @@ -define(TIMEOUT, 60000). -define(INFO(Fmt,Args), io:format(Fmt,Args)). +%% TODO: This script currently does NOT support slim releases. +%% Necessary steps to upgrade a slim release are as follows: +%% 1. unpack relup archive manually +%% 2. copy releases directory and necessary libraries +%% 3. using release_hander:set_unpacked/2 . +%% For more details, see https://github.com/rebar/rebar/pull/52 +%% and https://github.com/rebar/rebar/issues/202 + main([NodeName, Cookie, ReleasePackage]) -> TargetNode = start_distribution(NodeName, Cookie), {ok, Vsn} = rpc:call(TargetNode, release_handler, unpack_release, diff --git a/priv/templates/simplenode.reltool.config b/priv/templates/simplenode.reltool.config index bac7270..eae8ab3 100644 --- a/priv/templates/simplenode.reltool.config +++ b/priv/templates/simplenode.reltool.config @@ -32,7 +32,7 @@ {overlay, [ {mkdir, "log/sasl"}, {copy, "files/erl", "\{\{erts_vsn\}\}/bin/erl"}, - {copy, "files/nodetool", "\{\{erts_vsn\}\}/bin/nodetool"}, + {copy, "files/nodetool", "releases/\{\{rel_vsn\}\}/nodetool"}, {copy, "{{nodeid}}/bin/start_clean.boot", "\{\{erts_vsn\}\}/bin/start_clean.boot"}, {copy, "files/{{nodeid}}", "bin/{{nodeid}}"}, diff --git a/priv/templates/simplenode.runner b/priv/templates/simplenode.runner index 2786e72..3e9e10f 100755 --- a/priv/templates/simplenode.runner +++ b/priv/templates/simplenode.runner @@ -86,10 +86,36 @@ fi REMSH_TYPE=`echo $NAME_ARG | awk '{print $1}'` REMSH_NAME=`echo $NAME_ARG | awk '{print $2}'` +# Test if REMSH_NAME contains a @ and set REMSH_HOSTNAME_PART +# and REMSH_NAME_PART according REMSH_TYPE +MAYBE_FQDN_HOSTNAME=`hostname` +HOSTNAME=`echo $MAYBE_FQDN_HOSTNAME | awk -F. '{print $1}'` + +REMSH_HOSTNAME_PART="$MAYBE_FQDN_HOSTNAME" +case "$REMSH_NAME" in + *@*) + REMSH_HOSTNAME_PART=`echo $REMSH_NAME | awk -F@ '{print $2}'` + REMSH_NAME_PART=`echo $REMSH_NAME | awk -F@ '{print $1}'` + ;; + *) + REMSH_NAME_PART="$REMSH_NAME" + if [ "$REMSH_TYPE" = "-sname" ]; then + REMSH_HOSTNAME_PART="$HOSTNAME" + else + # -name type, check if `hostname` is fqdn + if [ "$MAYBE_FQDN_HOSTNAME" = "$HOSTNAME" ]; then + echo "Hostname must be a fqdn domain name when node is configured with long names" + echo "and the full node name isn't configured in vm.args" + exit 1 + fi + fi + ;; +esac + # Note the `date +%s`, used to allow multiple remsh to the same node # transparently -REMSH_NAME_ARG="$REMSH_TYPE remsh`date +%s`@`echo $REMSH_NAME | awk -F@ '{print $2}'`" -REMSH_REMSH_ARG="-remsh $REMSH_NAME" +REMSH_NAME_ARG="$REMSH_TYPE remsh`date +%s`@$REMSH_HOSTNAME_PART" +REMSH_REMSH_ARG="-remsh $REMSH_NAME_PART@$REMSH_HOSTNAME_PART" # Extract the target cookie COOKIE_ARG=`grep '^\-setcookie' $VMARGS_PATH` @@ -104,14 +130,46 @@ 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 +RUNNER_SCRIPT_DATA= +if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data" ]; then + RUNNER_SCRIPT_DATA=`cat $RUNNER_BASE_DIR/releases/$APP_VSN/runner_script.data` +fi -# Setup command to control the node -NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG" +if [ -z "$RUNNER_SCRIPT_DATA" ]; then + ROOTDIR=$RUNNER_BASE_DIR + ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin + if [ -e "$RUNNER_BASE_DIR/releases/$APP_VSN/nodetool" ]; then + NODETOOL="$ERTS_PATH/escript $RUNNER_BASE_DIR/releases/$APP_VSN/nodetool $NAME_ARG $COOKIE_ARG" + else + NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG" + fi + SLIM_ARGS= +elif [ "$RUNNER_SCRIPT_DATA" = "slim" ]; then + # Setup system paths + SYSTEM_ERL_PATH=`which erl` + if [ ! -x "$SYSTEM_ERL_PATH" ]; then + echo "Failed to find erl. Is Erlang/OTP available in PATH?" + exit 1 + fi + SYSTEM_HOME_BIN=${SYSTEM_ERL_PATH%/*} + ROOTDIR=$SYSTEM_HOME_BIN/../lib/erlang + ERTS_PATH=$ROOTDIR/erts-$ERTS_VSN/bin + unset SYSTEM_ERL_PATH + unset SYSTEM_HOME_BIN + + LOCAL_ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin + NODETOOL="$ERTS_PATH/escript $RUNNER_BASE_DIR/releases/$APP_VSN/nodetool $NAME_ARG $COOKIE_ARG" + unset LOCAL_ERL_PATH + + # Setup additional arguments for slim release + SLIM_ARGS="-boot_var RELTOOL_EXT_LIB $RUNNER_BASE_DIR/lib -sasl releases_dir \"$RUNNER_BASE_DIR/releases\"" +else + echo "Unknown runner_script.data" + exit 1 +fi # Setup remote shell command to control node -REMSH="$ERTS_PATH/erl $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG" +REMSH="$ERTS_PATH/erl -hidden $REMSH_NAME_ARG $REMSH_REMSH_ARG $COOKIE_ARG" # Common functions @@ -284,11 +342,10 @@ case "$1" in ;; esac # Setup beam-required vars - ROOTDIR=$RUNNER_BASE_DIR BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin EMU=beam PROGNAME=`echo $0 | sed 's/.*\\///'` - CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH" + CMD="$BINDIR/erlexec $SLIM_ARGS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -mode embedded -config $CONFIG_PATH -args_file $VMARGS_PATH" export EMU export ROOTDIR export BINDIR @@ -313,11 +370,10 @@ case "$1" in FOREGROUNDOPTIONS="-noinput +Bd" # Setup beam-required vars - ROOTDIR=$RUNNER_BASE_DIR BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin EMU=beam PROGNAME=`echo $0 | sed 's/.*\///'` - CMD="$BINDIR/erlexec $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -config $CONFIG_PATH -args_file $VMARGS_PATH" + CMD="$BINDIR/erlexec $SLIM_ARGS $FOREGROUNDOPTIONS -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$BOOTFILE -config $CONFIG_PATH -args_file $VMARGS_PATH" export EMU export ROOTDIR export BINDIR |