Welcome to mirror list, hosted at ThFree Co, Russian Federation.

leavecluster « tools - github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3e42c700f0c48a8495f07808efecfa97ff914a0c (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/sh

# Remove the current ejabberd node in a cluster

# copyright (c) 2010-2015 ProcessOne

# Return Code:
#  0 : groovy baby
# 10 : ejabberdctl not found
# 11 : erl not found
# 12 : erlc not found
# 22 : temporary dir can not be created

error()
{
    echo "Error: $1" >&2
    exit $2
}

[ -z $NO_WARNINGS ] && {
    echo "--------------------------------------------------------------------"
    echo ""
    echo "ejabberd cluster configuration"
    echo ""
    echo "This ejabberd node will be removed from the cluster."
    echo "IMPORTANT: this node will be stopped. At least one other clustered"
    echo "node must be running."
    echo ""
    echo "--------------------------------------------------------------------"
    echo "Press any key to continue, or Ctrl+C to stop now"
    read foo
    echo ""
}

PA=/tmp/clustersetup_$$
CTL=$(which ejabberdctl)
[ -x "$CTL" ] || {
  HERE=`which "$0"`
  BASE=`dirname $HERE`/..
  ROOTDIR=`cd $BASE; pwd`
  PATH=$ROOTDIR/bin:$PATH
  PA=$ROOTDIR/clustersetup_$$
  CTL=$(which ejabberdctl)
}
echo "Using commands:"
[ -x "$CTL" ] && echo $CTL || error "can't find ejabberdctl" 10

exec $CTL stop 2>/dev/null >/dev/null
ERLC=${ERL}c

[ -x $ERL ] && echo $ERL || error "can't find erl"  11
[ -x $ERLC ] && echo $ERLC || error "can't find erlc" 12
echo ""

$CTL stopped

CLUSTERSETUP=clustersetup
CLUSTERSETUP_ERL=$PA/$CLUSTERSETUP.erl

set -o errexit
set -o nounset

mkdir -p $PA || error "$PA cannot be created" 22
cd $PA
cat <<EOF > $CLUSTERSETUP_ERL
-module($CLUSTERSETUP).

-export([start/0]).

del_table_copy(Table, Node) ->
    case mnesia:del_table_copy(Table, Node) of
    {aborted, Reason} -> io:format("Error: can not remove ~p table: ~p~n", [Table, Reason]);
    _ -> io:format("table ~p removed from cluster~n", [Table])
    end.

del_tables([],_) ->
    ok;
del_tables([schema | Tables], Node) ->
    del_tables(Tables, Node);
del_tables([Table | Tables], Node) ->
    del_table_copy(Table, Node),
    del_tables(Tables, Node).

start() ->
    io:format("~n",[]),
    Removed = node(),
    case mnesia:system_info(running_db_nodes)--[Removed] of
    [] -> io:format("Error: no other node running in the cluster~n");
    Nodes ->
        del_tables(mnesia:system_info(local_tables), Removed),
        mnesia:stop(),
        case rpc:call(hd(Nodes), mnesia, del_table_copy, [schema, Removed]) of
        {badrpc,Reason} -> io:format("Error: can not unregister node ~p from cluster: ~p~n", [Removed, Reason]);
        {aborted,Reason} -> io:format("Error: can not unregister node ~p from cluster: ~p~n", [Removed, Reason]);
        {atomic, ok} ->
            mnesia:delete_schema([Removed]),
            io:format("node ~p removed from cluster~n", [Removed])
        end
    end,
    halt(0).
EOF

$ERLC -o $PA $CLUSTERSETUP_ERL
sh -c "$ERL $NAME $ERLANG_NODE -pa $PA $KERNEL_OPTS -mnesia dir \"\\\"$SPOOL_DIR\\\"\" -s mnesia -s $CLUSTERSETUP start"
cd -
rm -Rf $PA

echo "End."
echo "Check that there is no error in the above messages."