aboutsummaryrefslogtreecommitdiffstats
path: root/priv
diff options
context:
space:
mode:
authorLuis Rascão <[email protected]>2016-10-30 16:10:36 +0000
committerGitHub <[email protected]>2016-10-30 16:10:36 +0000
commit7e8ea5a9a059c9e42ec2c71f382552622f01cfbc (patch)
treec9bd1c1a70daff3bba6c40ac8f157b2d75f4b772 /priv
parente4fa9a276e81f409daba0e43eb209e1353698ef3 (diff)
parent6a5cb0e46107ed70fcaa42624859d9167ff9bde1 (diff)
downloadrelx-7e8ea5a9a059c9e42ec2c71f382552622f01cfbc.tar.gz
relx-7e8ea5a9a059c9e42ec2c71f382552622f01cfbc.tar.bz2
relx-7e8ea5a9a059c9e42ec2c71f382552622f01cfbc.zip
Merge pull request #474 from soranoba/uninstall
Support the uninstall command. (release_handler:remove_release/1)
Diffstat (limited to 'priv')
-rwxr-xr-xpriv/templates/extended_bin4
-rw-r--r--priv/templates/install_upgrade_escript34
2 files changed, 36 insertions, 2 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin
index d133570..0881a08 100755
--- a/priv/templates/extended_bin
+++ b/priv/templates/extended_bin
@@ -312,7 +312,7 @@ case "$1" in
relx_rem_sh
;;
- upgrade|downgrade|install|unpack)
+ upgrade|downgrade|install|unpack|uninstall)
if [ -z "$2" ]; then
echo "Missing version argument"
echo "Usage: $REL_NAME $1 {version}"
@@ -461,7 +461,7 @@ case "$1" in
relx_nodetool "eval" $@
;;
*)
- echo "Usage: $REL_NAME {start|start_boot <file>|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|downgrade|install|escript|rpc|rpcterms|eval}"
+ echo "Usage: $REL_NAME {start|start_boot <file>|foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade|downgrade|install|uninstall|versions|escript|rpc|rpcterms|eval}"
exit 1
;;
esac
diff --git a/priv/templates/install_upgrade_escript b/priv/templates/install_upgrade_escript
index 4daf526..9c74445 100644
--- a/priv/templates/install_upgrade_escript
+++ b/priv/templates/install_upgrade_escript
@@ -9,6 +9,7 @@
unpack/2,
upgrade/2,
downgrade/2,
+ uninstall/2,
versions/2]).
-define(TIMEOUT, 300000).
@@ -81,6 +82,29 @@ upgrade(DistInfo, Args) ->
downgrade(DistInfo, Args) ->
install(DistInfo, Args).
+uninstall({_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 ->
+ ?INFO("Release ~s is already uninstalled.~n", [Version]);
+ old ->
+ ?INFO("Release ~s is marked old.~n", [Version]),
+ remove_release(TargetNode, Version);
+ unpacked ->
+ ?INFO("Release ~s is marked unpacked.~n", [Version]),
+ remove_release(TargetNode, Version);
+ current ->
+ ?INFO("Uninstall failed: Release ~s is marked current.~n", [Version]),
+ erlang:halt(2);
+ permanent ->
+ ?INFO("Uninstall failed: Release ~s is running.~n", [Version]),
+ erlang:halt(2)
+ end;
+uninstall(_, Args) ->
+ ?INFO("uninstall: unknown args ~p\n", [Args]).
+
versions({_RelName, NameTypeArg, NodeName, Cookie}, []) ->
TargetNode = start_distribution(NodeName, NameTypeArg, Cookie),
print_existing_versions(TargetNode).
@@ -210,6 +234,16 @@ permafy(TargetNode, RelName, Vsn) ->
?INFO("Made release permanent: ~p~n", [Vsn]),
ok.
+remove_release(TargetNode, Vsn) ->
+ case rpc:call(TargetNode, release_handler, remove_release, [Vsn], ?TIMEOUT) of
+ ok ->
+ ?INFO("Uninstalled Release: ~s~n", [Vsn]),
+ ok;
+ {error, Reason} ->
+ ?INFO("ERROR: release_handler:remove_release failed: ~p~n", [Reason]),
+ erlang:halt(3)
+ end.
+
which_releases(TargetNode) ->
R = rpc:call(TargetNode, release_handler, which_releases, [], ?TIMEOUT),
[ {V, S} || {_,V,_, S} <- R ].