@@ -26,12 +26,19 @@ defmodule Mix.Releases.Runtime.Control do
26
26
transform: & String . to_atom / 1
27
27
)
28
28
29
+ defoption (
30
+ :id ,
31
+ :string ,
32
+ "The unique id to use when connecting to the remote node"
33
+ )
34
+
29
35
option ( :verbose , :boolean , "Turns on verbose output" , alias: :v )
30
36
31
37
# Basic management tasks
32
38
command :ping , "Pings the remote node" do
33
39
option ( :cookie , required: true )
34
40
option ( :name )
41
+ option ( :id )
35
42
end
36
43
37
44
# Stub for `describe`
@@ -40,16 +47,19 @@ defmodule Mix.Releases.Runtime.Control do
40
47
command :stop , "Stops the remote node" do
41
48
option ( :name )
42
49
option ( :cookie )
50
+ option ( :id )
43
51
end
44
52
45
53
command :restart , "Restarts the remote node. This will not restart the emulator" do
46
54
option ( :name )
47
55
option ( :cookie )
56
+ option ( :id )
48
57
end
49
58
50
59
command :reboot , "Reboots the remote node. This will restart the emulator" do
51
60
option ( :name )
52
61
option ( :cookie )
62
+ option ( :id )
53
63
end
54
64
55
65
# Stub for `describe`
@@ -65,6 +75,7 @@ defmodule Mix.Releases.Runtime.Control do
65
75
command :unpack , "Unpacks a release upgrade for installation" do
66
76
option ( :name )
67
77
option ( :cookie )
78
+ option ( :id )
68
79
option ( :release , :string , "The release name" , required: true , hidden: true )
69
80
70
81
argument ( :version , :string , "The release version to unpack" , required: true )
@@ -73,6 +84,7 @@ defmodule Mix.Releases.Runtime.Control do
73
84
command :install , "Installs a release upgrade" do
74
85
option ( :name )
75
86
option ( :cookie )
87
+ option ( :id )
76
88
option ( :release , :string , "The release name" , required: true , hidden: true )
77
89
78
90
argument ( :version , :string , "The release version to install" , required: true )
@@ -82,12 +94,14 @@ defmodule Mix.Releases.Runtime.Control do
82
94
command :reload_config , "Reloads the config of the remote node" do
83
95
option ( :name )
84
96
option ( :cookie )
97
+ option ( :id )
85
98
option ( :sysconfig , :string , "The path to a sys.config file" )
86
99
end
87
100
88
101
command :rpc , "Executes the provided expression on the remote node" do
89
102
option ( :name )
90
103
option ( :cookie )
104
+ option ( :id )
91
105
option ( :file , :string , "Evaluate a file instead of an expression" )
92
106
option ( :mfa , :string , "A module/function/arity string, e.g. IO.inspect/1" )
93
107
@@ -120,6 +134,7 @@ defmodule Mix.Releases.Runtime.Control do
120
134
command :info , "Prints information about the remote node to stdout" do
121
135
option ( :name )
122
136
option ( :cookie )
137
+ option ( :id )
123
138
124
139
command :processes , [ callback: :processes_info ] , "Show a table of running processes" do
125
140
option (
@@ -135,6 +150,7 @@ defmodule Mix.Releases.Runtime.Control do
135
150
command :describe , "Describes the currently installed release" do
136
151
option ( :name )
137
152
option ( :cookie )
153
+ option ( :id )
138
154
option ( :release , :string , "The name of the release" )
139
155
option ( :release_root_dir , :string , "The root directory for all releases" )
140
156
option ( :sysconfig , :string , "The path to the sys.config file used by the release" )
@@ -147,9 +163,17 @@ defmodule Mix.Releases.Runtime.Control do
147
163
This function executes before any commands are dispatched
148
164
"""
149
165
@ impl Artificery
150
- def pre_dispatch ( _cmd , _argv , % { name: name , cookie: cookie } = opts ) do
151
- # If required, it means we need to connect to the remote node
152
- { :ok , peer , name , type } = start_distribution! ( name , cookie )
166
+ def pre_dispatch ( _cmd , _argv , % { name: remote_name , cookie: cookie } = opts ) do
167
+ # Allow callers to provide a unique id for the node
168
+ # We don't want to generate random ids because it can fill the atom table
169
+ id =
170
+ case Map . get ( opts , :id ) do
171
+ nil -> nil
172
+ suffix -> suffix
173
+ end
174
+
175
+ # Connect to the given remote node
176
+ { :ok , peer , name , type } = start_distribution! ( remote_name , cookie , id )
153
177
154
178
new_opts =
155
179
opts
@@ -888,11 +912,15 @@ defmodule Mix.Releases.Runtime.Control do
888
912
end
889
913
890
914
@ doc false
891
- def start_distribution! ( name , cookie ) do
915
+ def start_distribution! ( name , cookie , suffix \\ nil ) do
892
916
{ peer , name , type } =
893
917
case name_components ( name ) do
918
+ % { name: name , full: full_name , host: host , type: type } when not is_nil ( suffix ) ->
919
+ { full_name , suffix_name_long ( name , host , suffix ) , type }
894
920
% { name: name , full: full_name , host: host , type: type } ->
895
- { full_name , suffix_name ( name , host ) , type }
921
+ { full_name , suffix_name_long ( name , host ) , type }
922
+ % { name: name , full: full_name , type: type } when not is_nil ( suffix ) ->
923
+ { full_name , suffix_name ( name , suffix ) , type }
896
924
% { name: name , full: full_name , type: type } ->
897
925
{ full_name , suffix_name ( name ) , type }
898
926
{ :error , reason } ->
@@ -938,8 +966,13 @@ defmodule Mix.Releases.Runtime.Control do
938
966
end
939
967
end
940
968
941
- defp suffix_name ( name ) , do: String . to_atom ( "#{ name } _maint_" )
942
- defp suffix_name ( name , host ) , do: String . to_atom ( "#{ name } _maint_@#{ host } " )
969
+ defp suffix_name ( name , suffix \\ nil )
970
+ defp suffix_name ( name , nil ) , do: String . to_atom ( "#{ name } _maint_" )
971
+ defp suffix_name ( name , suffix ) , do: String . to_atom ( "#{ name } _#{ suffix } " )
972
+
973
+ defp suffix_name_long ( name , host , suffix \\ nil )
974
+ defp suffix_name_long ( name , host , nil ) , do: String . to_atom ( "#{ name } _maint_@#{ host } " )
975
+ defp suffix_name_long ( name , host , suffix ) , do: String . to_atom ( "#{ name } _#{ suffix } @#{ host } " )
943
976
944
977
## Helpers
945
978
0 commit comments