aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rwxr-xr-xpriv/templates/bin.dtl9
-rw-r--r--priv/templates/extended_bin.dtl20
-rw-r--r--priv/templates/install_upgrade_escript.dtl32
4 files changed, 54 insertions, 9 deletions
diff --git a/README.md b/README.md
index f6fbb21..672290f 100644
--- a/README.md
+++ b/README.md
@@ -67,7 +67,7 @@ Options
| Short | Long | Type | Default | Description |
|:-----:|:------------:|:-------:|:------:|------------------------------------------------------------------------------------------- |
| -r | --root | string | ./ | Sets the root of the project |
-| -n | --name | string | | Name for the release that will be generated |
+| -n | --relname | string | | Name for the release that will be generated |
| -v | --relvsn | string | | Version for the release |
| -g | --goal | string | | A goal for the system. These are usually the OTP apps that are part of the release |
| -u | --upfrom | string | | The release to upgrade from. Only valid with relup target |
diff --git a/priv/templates/bin.dtl b/priv/templates/bin.dtl
index 434cbd4..3398d63 100755
--- a/priv/templates/bin.dtl
+++ b/priv/templates/bin.dtl
@@ -17,12 +17,11 @@ find_erts_dir() {
ROOTDIR="$RELEASE_ROOT_DIR"
else
local erl="$(which erl)"
- code="io:format(\"~s\", [code:root_dir()]), halt()."
- local erl_root="$("$erl" -noshell -eval "$code")"
+ code="io:format(\"~s\", [code:root_dir()])."
+ local erl_root="$("$erl" -noshell -eval "$code" -s init stop)"
ERTS_DIR="$erl_root/erts-$ERTS_VSN"
ROOTDIR="$erl_root"
fi
-
}
find_sys_config() {
@@ -48,7 +47,7 @@ export EMU="beam"
export PROGNAME="erl"
export LD_LIBRARY_PATH="$ERTS_DIR/lib:$LD_LIBRARY_PATH"
ERTS_LIB_DIR="$ERTS_DIR/../lib"
-
+[ -f "$REL_DIR/$REL_NAME.boot" ] && BOOTFILE="$REL_NAME" || BOOTFILE=start
cd "$ROOTDIR"
# Save extra arguments
@@ -58,7 +57,7 @@ ARGS="$@"
set -- "$ERL_OPTS"
[ "$SYS_CONFIG" ] && set -- "$@" -config "$SYS_CONFIG"
[ "$VM_ARGS" ] && set -- "$@" -args_file "$VM_ARGS"
-set -- "$@" -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" -boot "$REL_DIR/$REL_NAME" "$ARGS"
+set -- "$@" -boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" -boot "$REL_DIR/$BOOTFILE" "$ARGS"
# Boot the release
$BINDIR/erlexec $@
diff --git a/priv/templates/extended_bin.dtl b/priv/templates/extended_bin.dtl
index 70b4ee2..87f69ba 100644
--- a/priv/templates/extended_bin.dtl
+++ b/priv/templates/extended_bin.dtl
@@ -289,7 +289,25 @@ case "$1" in
fi
exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \
- "$REL_NAME" "$NAME" "$COOKIE" "$2"
+ "install" "$REL_NAME" "$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" "$COOKIE" "$2"
;;
console|console_clean|console_boot)
diff --git a/priv/templates/install_upgrade_escript.dtl b/priv/templates/install_upgrade_escript.dtl
index dce2e11..3fb9d04 100644
--- a/priv/templates/install_upgrade_escript.dtl
+++ b/priv/templates/install_upgrade_escript.dtl
@@ -6,8 +6,36 @@
-define(TIMEOUT, 300000).
-define(INFO(Fmt,Args), io:format(Fmt,Args)).
-%% Upgrades, to a new tar.gz release
-main([RelName, NodeName, Cookie, VersionArg]) ->
+%% Unpack or upgrade to a new tar.gz release
+main(["unpack", RelName, NodeName, Cookie, VersionArg]) ->
+ TargetNode = start_distribution(NodeName, 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, NodeName, Cookie, VersionArg]) ->
TargetNode = start_distribution(NodeName, Cookie),
WhichReleases = which_releases(TargetNode),
Version = parse_version(VersionArg),