From 63926efd204c093b3125f789d5114e85ae4ff988 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Tue, 21 Apr 2015 13:32:14 +0200 Subject: [PATCH] Improve join/leave cluster scripts --- tools/joincluster | 56 +++++++++++++++++++++++----------------------- tools/leavecluster | 50 ++++++++++++++++++++++++----------------- 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 < $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 < $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."