diff options
-rwxr-xr-x | priv/templates/extended_bin | 4 | ||||
-rw-r--r-- | priv/templates/install_upgrade_escript | 34 |
2 files changed, 36 insertions, 2 deletions
diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index d133570..5e15669 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|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 ]. |