24
24
25
25
-include_lib (" kernel/include/inet.hrl" ).
26
26
27
- -define (EPMD_TIMEOUT , 30000 ).
28
- -define (TCP_DIAGNOSTIC_TIMEOUT , 5000 ).
29
- -define (ERROR_LOGGER_HANDLER , rabbit_error_logger_handler ).
30
-
31
27
% %----------------------------------------------------------------------------
32
28
% % Specs
33
29
% %----------------------------------------------------------------------------
45
41
% %----------------------------------------------------------------------------
46
42
47
43
names (Hostname ) ->
48
- Self = self (),
49
- Ref = make_ref (),
50
- {Pid , MRef } = spawn_monitor (
51
- fun () -> Self ! {Ref , net_adm :names (Hostname )} end ),
52
- timer :exit_after (? EPMD_TIMEOUT , Pid , timeout ),
53
- receive
54
- {Ref , Names } -> erlang :demonitor (MRef , [flush ]),
55
- Names ;
56
- {'DOWN' , MRef , process , Pid , Reason } -> {error , Reason }
57
- end .
44
+ rabbit_nodes_common :names (Hostname ).
58
45
59
46
diagnostics (Nodes ) ->
60
- verbose_erlang_distribution (true ),
61
- NodeDiags = [{" ~n DIAGNOSTICS~n ===========~n~n "
62
- " attempted to contact: ~p~n " , [Nodes ]}] ++
63
- [diagnostics_node (Node ) || Node <- Nodes ] ++
64
- current_node_details (),
65
- verbose_erlang_distribution (false ),
66
- rabbit_misc :format_many (lists :flatten (NodeDiags )).
67
-
68
- verbose_erlang_distribution (true ) ->
69
- net_kernel :verbose (1 ),
70
- error_logger :add_report_handler (? ERROR_LOGGER_HANDLER );
71
- verbose_erlang_distribution (false ) ->
72
- net_kernel :verbose (0 ),
73
- error_logger :delete_report_handler (? ERROR_LOGGER_HANDLER ).
74
-
75
- current_node_details () ->
76
- [{" ~n current node details:~n - node name: ~w " , [node ()]},
77
- case init :get_argument (home ) of
78
- {ok , [[Home ]]} -> {" - home dir: ~s " , [Home ]};
79
- Other -> {" - no home dir: ~p " , [Other ]}
80
- end ,
81
- {" - cookie hash: ~s " , [cookie_hash ()]}].
82
-
83
- diagnostics_node (Node ) ->
84
- {Name , Host } = parts (Node ),
85
- [{" ~s :" , [Node ]} |
86
- case names (Host ) of
87
- {error , Reason } ->
88
- [{" * unable to connect to epmd (port ~s ) on ~s : ~s~n " ,
89
- [epmd_port (), Host , rabbit_misc :format_inet_error (Reason )]}];
90
- {ok , NamePorts } ->
91
- [{" * connected to epmd (port ~s ) on ~s " ,
92
- [epmd_port (), Host ]}] ++
93
- case net_adm :ping (Node ) of
94
- pong -> dist_working_diagnostics (Node );
95
- pang -> dist_broken_diagnostics (Name , Host , NamePorts )
96
- end
97
- end ].
98
-
99
- epmd_port () ->
100
- case init :get_argument (epmd_port ) of
101
- {ok , [[Port | _ ] | _ ]} when is_list (Port ) -> Port ;
102
- error -> " 4369"
103
- end .
104
-
105
- dist_working_diagnostics (Node ) ->
106
- case is_process_running (Node , rabbit ) of
107
- true -> [{" * node ~s up, 'rabbit' application running" , [Node ]}];
108
- false -> [{" * node ~s up, 'rabbit' application not running~n "
109
- " * running applications on ~s : ~p~n "
110
- " * suggestion: start_app on ~s " ,
111
- [Node , Node , remote_apps (Node ), Node ]}]
112
- end .
113
-
114
- remote_apps (Node ) ->
115
- % % We want a timeout here because really, we don't trust the node,
116
- % % the last thing we want to do is hang.
117
- case rpc :call (Node , application , which_applications , [5000 ]) of
118
- {badrpc , _ } = E -> E ;
119
- Apps -> [App || {App , _ , _ } <- Apps ]
120
- end .
121
-
122
- dist_broken_diagnostics (Name , Host , NamePorts ) ->
123
- case [{N , P } || {N , P } <- NamePorts , N =:= Name ] of
124
- [] ->
125
- {SelfName , SelfHost } = parts (node ()),
126
- Others = [list_to_atom (N ) || {N , _ } <- NamePorts ,
127
- N =/= case SelfHost of
128
- Host -> SelfName ;
129
- _ -> never_matches
130
- end ],
131
- OthersDiag = case Others of
132
- [] -> [{" no other nodes on ~s " ,
133
- [Host ]}];
134
- _ -> [{" other nodes on ~s : ~p " ,
135
- [Host , Others ]}]
136
- end ,
137
- [{" * epmd reports: node '~s ' not running at all" , [Name ]},
138
- OthersDiag , {" * suggestion: start the node" , []}];
139
- [{Name , Port }] ->
140
- [{" * epmd reports node '~s ' running on port ~b " , [Name , Port ]} |
141
- case diagnose_connect (Host , Port ) of
142
- ok ->
143
- connection_succeeded_diagnostics ();
144
- {error , Reason } ->
145
- [{" * can't establish TCP connection, reason: ~s~n "
146
- " * suggestion: blocked by firewall?" ,
147
- [rabbit_misc :format_inet_error (Reason )]}]
148
- end ]
149
- end .
150
-
151
- connection_succeeded_diagnostics () ->
152
- case gen_event :call (error_logger , ? ERROR_LOGGER_HANDLER , get_connection_report ) of
153
- [] ->
154
- [{" * TCP connection succeeded but Erlang distribution "
155
- " failed~n "
156
- " * suggestion: hostname mismatch?~n "
157
- " * suggestion: is the cookie set correctly?~n "
158
- " * suggestion: is the Erlang distribution using TLS?" , []}];
159
- Report ->
160
- [{" * TCP connection succeeded but Erlang distribution "
161
- " failed~n " , []}]
162
- ++ Report
163
- end .
164
-
165
- diagnose_connect (Host , Port ) ->
166
- case inet :gethostbyname (Host ) of
167
- {ok , # hostent {h_addrtype = Family }} ->
168
- case gen_tcp :connect (Host , Port , [Family ],
169
- ? TCP_DIAGNOSTIC_TIMEOUT ) of
170
- {ok , Socket } -> gen_tcp :close (Socket ),
171
- ok ;
172
- {error , _ } = E -> E
173
- end ;
174
- {error , _ } = E ->
175
- E
176
- end .
47
+ rabbit_nodes_common :diagnostics (Nodes ).
177
48
178
49
make (NodeStr ) ->
179
50
rabbit_nodes_common :make (NodeStr ).
@@ -182,30 +53,23 @@ parts(NodeStr) ->
182
53
rabbit_nodes_common :parts (NodeStr ).
183
54
184
55
cookie_hash () ->
185
- base64 : encode_to_string ( erlang : md5 ( atom_to_list ( erlang : get_cookie ())) ).
56
+ rabbit_nodes_common : cookie_hash ( ).
186
57
187
58
is_running (Node , Application ) ->
188
- case rpc :call (Node , rabbit_misc , which_applications , []) of
189
- {badrpc , _ } -> false ;
190
- Apps -> proplists :is_defined (Application , Apps )
191
- end .
59
+ rabbit_nodes_common :is_running (Node , Application ).
192
60
193
61
is_process_running (Node , Process ) ->
194
- case rpc :call (Node , erlang , whereis , [Process ]) of
195
- {badrpc , _ } -> false ;
196
- undefined -> false ;
197
- P when is_pid (P ) -> true
198
- end .
62
+ rabbit_nodes_common :is_process_running (Node , Process ).
199
63
200
64
cluster_name () ->
201
65
rabbit_runtime_parameters :value_global (
202
66
cluster_name , cluster_name_default ()).
203
67
204
68
cluster_name_default () ->
205
- {ID , _ } = rabbit_nodes : parts (node ()),
69
+ {ID , _ } = parts (node ()),
206
70
{ok , Host } = inet :gethostname (),
207
71
{ok , # hostent {h_name = FQDN }} = inet :gethostbyname (Host ),
208
- list_to_binary (atom_to_list (rabbit_nodes : make ({ID , FQDN }))).
72
+ list_to_binary (atom_to_list (make ({ID , FQDN }))).
209
73
210
74
set_cluster_name (Name , Username ) ->
211
75
% % Cluster name should be binary
0 commit comments