-
Notifications
You must be signed in to change notification settings - Fork 20
/
easy_cluster.erl
executable file
·34 lines (29 loc) · 1.14 KB
/
easy_cluster.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
-module(easy_cluster).
-export([test_node/1,join/1,join_as_master/1,sync_node/1]).
test_node(NodeName) ->
case net_adm:ping(NodeName) of 'pong' ->
io:format("server is reachable.~n");
_ ->
io:format("server could NOT be reached.~n")
end.
join(NodeName) ->
mnesia:stop(),
mnesia:delete_schema([node()]),
mnesia:start(),
mnesia:change_config(extra_db_nodes, [NodeName]),
mnesia:change_table_copy_type(schema, node(), disc_copies),
application:stop(ejabberd),
application:start(ejabberd).
join_as_master(NodeName) ->
application:stop(ejabberd),
mnesia:stop(),
mnesia:delete_schema([node()]),
mnesia:start(),
mnesia:change_config(extra_db_nodes, [NodeName]),
mnesia:change_table_copy_type(schema, node(), disc_copies),
easy_cluster:sync_node(NodeName),
application:start(ejabberd).
sync_node(NodeName) ->
[{Tb, mnesia:add_table_copy(Tb, node(), Type)}
|| {Tb, [{NodeName, Type}]} <- [{T, mnesia:table_info(T, where_to_commit)}
|| T <- mnesia:system_info(tables)]].