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

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorChristophe Romain <christophe.romain@process-one.net>2015-04-21 14:32:14 +0300
committerChristophe Romain <christophe.romain@process-one.net>2015-04-21 14:32:14 +0300
commit63926efd204c093b3125f789d5114e85ae4ff988 (patch)
tree3b860b5c73da9bc11477287a2ec3c120a4efa58d /tools
parent28090a39584ea42a9219a9f3058fc26d59513323 (diff)
Improve join/leave cluster scripts
Diffstat (limited to 'tools')
-rwxr-xr-xtools/joincluster56
-rwxr-xr-xtools/leavecluster50
2 files changed, 58 insertions, 48 deletions
diff --git a/tools/joincluster b/tools/joincluster
index e4351d799..de36e437c 100755
--- a/tools/joincluster
+++ b/tools/joincluster
@@ -1,18 +1,17 @@
-#!/bin/bash
+#!/bin/sh
# Add the current ejabberd node in a cluster
# copyright (c) 2010-2015 ProcessOne
-#
-# This script is proprietary software and cannot be published or redistribute.
# Return Code:
# 0 : groovy baby
+# 10 : ejabberdctl not found
# 11 : erl not found
# 12 : erlc not found
-# 20 : database dir doesn't exist
+# 20 : database dir can not be created
# 21 : database dir not writable
-# 21 : database dir variable not set
+# 22 : temporary dir can not be created
# 30 : network issue
# 31 : node names incompatibility
@@ -53,23 +52,28 @@ echo ""
REMOTE=$1
}
-cont=Y
-ping -q -c 1 ${REMOTE#*@} 2>/dev/null >/dev/null
-[ $? -eq 0 ] || {
- echo "Cannot ping ${REMOTE#*@}. Are you sure network setup is correct ?"
- echo -n "Should we continue anyway ? (Y/n) "
- read cont
+PA=/tmp/clustersetup_$$
+CTL=$(which ejabberdctl)
+[ "$CTL" == "" ] && {
+ HERE=`which "$0"`
+ BASE=`dirname $HERE`/..
+ ROOTDIR=`cd $BASE; pwd`
+ PATH=$ROOTDIR/bin:$PATH
+ PA=$ROOTDIR/clustersetup_$$
+ CTL=$(which ejabberdctl)
}
-cont=`echo $cont | tr a-z A-Z`
-[ "$cont" == "Y" ] || error "Check your network configuration (dns, firewall, etc...)" 30
+echo "Using commands:"
+[ -x $CTL ] && echo $CTL || error "can't find ejabberdctl" 10
+
+. $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 ""
-HERE=`which "$0"`
-BASE=`dirname $HERE`/..
-ROOTDIR=`cd $BASE; pwd`
-. $ROOTDIR/bin/ejabberdctl stop 2>/dev/null >/dev/null
NAME=-name
[ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] && NAME=-sname
-PA=/tmp/clustersetup_$$
CLUSTERSETUP=clustersetup
CLUSTERSETUP_ERL=$PA/$CLUSTERSETUP.erl
@@ -89,17 +93,11 @@ REMOTENAME=-name
set -o errexit
set -o nounset
-echo "Using commands:"
-which erl || error "can't find erl" 11
-which erlc || error "can't find erlc" 12
-echo ""
-
[ -d $SPOOL_DIR ] && rm -Rf $SPOOL_DIR
mkdir $SPOOL_DIR || error "$SPOOL_DIR cannot be created" 20
[ -w $SPOOL_DIR ] || error "$SPOOL_DIR directory is not writable" 21
-
-cd $ROOTDIR
-mkdir -p $PA
+mkdir -p $PA || error "$PA cannot be created" 22
+cd $PA
cat <<EOF > $CLUSTERSETUP_ERL
-module($CLUSTERSETUP).
@@ -144,8 +142,10 @@ start() ->
end,
halt(R).
EOF
-erlc -o $PA $CLUSTERSETUP_ERL
-sh -c "erl $NAME $ERLANG_NODE -pa $PA $KERNEL_OPTS -mnesia extra_db_nodes \"['$REMOTE']\" dir \"\\\"$SPOOL_DIR\\\"\" -s mnesia -s $CLUSTERSETUP start"
+
+$ERLC -o $PA $CLUSTERSETUP_ERL
+sh -c "$ERL $NAME $ERLANG_NODE -pa $PA $KERNEL_OPTS -mnesia extra_db_nodes \"['$REMOTE']\" dir \"\\\"$SPOOL_DIR\\\"\" -s mnesia -s $CLUSTERSETUP start"
+cd -
rm -Rf $PA
echo "End."
diff --git a/tools/leavecluster b/tools/leavecluster
index ec21621bc..cb4737adb 100755
--- a/tools/leavecluster
+++ b/tools/leavecluster
@@ -1,18 +1,15 @@
-#!/bin/bash
+#!/bin/sh
# Remove the current ejabberd node in a cluster
# copyright (c) 2010-2015 ProcessOne
-#
-# This script is proprietary software and cannot be published or redistribute.
# Return Code:
# 0 : groovy baby
+# 10 : ejabberdctl not found
# 11 : erl not found
# 12 : erlc not found
-# 20 : database dir doesn't exist
-# 21 : database dir not writable
-# 21 : database dir variable not set
+# 22 : temporary dir can not be created
function error
{
@@ -33,25 +30,36 @@ echo "Press any key to continue, or Ctrl+C to stop now"
read foo
echo ""
-HERE=`which "$0"`
-BASE=`dirname $HERE`/..
-ROOTDIR=`cd $BASE; pwd`
-. $ROOTDIR/bin/ejabberdctl stop 2>/dev/null >/dev/null
-$ROOTDIR/bin/ejabberdctl stopped
PA=/tmp/clustersetup_$$
+CTL=$(which ejabberdctl)
+[ "$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
+
+. $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
-echo "Using commands:"
-which erl || error "can't find erl" 11
-which erlc || error "can't find erlc" 12
-echo ""
-
-cd $ROOTDIR
-mkdir -p $PA
+mkdir -p $PA || error "$PA cannot be created" 22
+cd $PA
cat <<EOF > $CLUSTERSETUP_ERL
-module($CLUSTERSETUP).
@@ -89,8 +97,10 @@ start() ->
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"
+
+$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."