Skip to content

Commit

Permalink
add unpack option to install escript
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Jun 28, 2014
1 parent dcd9809 commit a6640cd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
22 changes: 21 additions & 1 deletion priv/templates/extended_bin.dtl
Expand Up @@ -267,7 +267,27 @@ 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
relx_nodetool "ping" > /dev/null
ES="$?"
if [ "$ES" -ne 0 ]; then
echo "Node is not running!"
exit $ES
fi

exec "$BINDIR/escript" "$ROOTDIR/bin/install_upgrade.escript" \
"unpack" "$REL_NAME" "$NAME" "$COOKIE" "$2"
;;

console|console_clean|console_boot)
Expand Down
32 changes: 30 additions & 2 deletions priv/templates/install_upgrade_escript.dtl
Expand Up @@ -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),
Expand Down

0 comments on commit a6640cd

Please sign in to comment.