mirror of
https://github.com/processone/ejabberd.git
synced 2024-07-04 23:15:31 +02:00
Check node name is available before starting ejabberd (EJAB-1572)
This commit is contained in:
parent
9787416e88
commit
9442a583bc
|
@ -41,7 +41,9 @@ fi
|
||||||
if [ "$EJABBERDCTL_CONFIG_PATH" = "" ] ; then
|
if [ "$EJABBERDCTL_CONFIG_PATH" = "" ] ; then
|
||||||
EJABBERDCTL_CONFIG_PATH=$ETCDIR/ejabberdctl.cfg
|
EJABBERDCTL_CONFIG_PATH=$ETCDIR/ejabberdctl.cfg
|
||||||
fi
|
fi
|
||||||
[ -f "$EJABBERDCTL_CONFIG_PATH" ] && . "$EJABBERDCTL_CONFIG_PATH"
|
if [ -f "$EJABBERDCTL_CONFIG_PATH" ] ; then
|
||||||
|
. "$EJABBERDCTL_CONFIG_PATH"
|
||||||
|
fi
|
||||||
if [ "$LOGS_DIR" = "" ] ; then
|
if [ "$LOGS_DIR" = "" ] ; then
|
||||||
LOGS_DIR=@LOCALSTATEDIR@/log/ejabberd
|
LOGS_DIR=@LOCALSTATEDIR@/log/ejabberd
|
||||||
fi
|
fi
|
||||||
|
@ -63,19 +65,21 @@ EJID=`id -g $INSTALLUSER`
|
||||||
EXEC_CMD="false"
|
EXEC_CMD="false"
|
||||||
for GID in $GIDS; do
|
for GID in $GIDS; do
|
||||||
if [ $GID -eq 0 ] ; then
|
if [ $GID -eq 0 ] ; then
|
||||||
EXEC_CMD="su ${INSTALLUSER} -p -c"
|
EXEC_CMD="su ${INSTALLUSER} -p -c"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "$ID" -eq "$EJID" ] ; then
|
if [ "$ID" -eq "$EJID" ] ; then
|
||||||
EXEC_CMD="sh -c"
|
EXEC_CMD="sh -c"
|
||||||
fi
|
fi
|
||||||
if [ "$EXEC_CMD" = "false" ] ; then
|
if [ "$EXEC_CMD" = "false" ] ; then
|
||||||
echo "This command can only be run by root or the user $INSTALLUSER" >&2
|
echo "This command can only be run by root or the user $INSTALLUSER" >&2
|
||||||
exit 4
|
exit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NAME=-name
|
NAME=-name
|
||||||
[ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] && NAME=-sname
|
if [ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] ; then
|
||||||
|
NAME=-sname
|
||||||
|
fi
|
||||||
|
|
||||||
KERNEL_OPTS=""
|
KERNEL_OPTS=""
|
||||||
if [ "$FIREWALL_WINDOW" != "" ] ; then
|
if [ "$FIREWALL_WINDOW" != "" ] ; then
|
||||||
|
@ -88,22 +92,22 @@ fi
|
||||||
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES $ERL_OPTIONS"
|
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES $ERL_OPTIONS"
|
||||||
|
|
||||||
# define additional environment variables
|
# define additional environment variables
|
||||||
if [ "$EJABBERDDIR" = "" ]; then
|
if [ "$EJABBERDDIR" = "" ] ; then
|
||||||
EJABBERDDIR=@LIBDIR@/ejabberd
|
EJABBERDDIR=@LIBDIR@/ejabberd
|
||||||
fi
|
fi
|
||||||
if [ "$EJABBERD_EBIN_PATH" = "" ]; then
|
if [ "$EJABBERD_EBIN_PATH" = "" ] ; then
|
||||||
EJABBERD_EBIN_PATH=$EJABBERDDIR/ebin
|
EJABBERD_EBIN_PATH=$EJABBERDDIR/ebin
|
||||||
fi
|
fi
|
||||||
if [ "$EJABBERD_PRIV_PATH" = "" ]; then
|
if [ "$EJABBERD_PRIV_PATH" = "" ] ; then
|
||||||
EJABBERD_PRIV_PATH=$EJABBERDDIR/priv
|
EJABBERD_PRIV_PATH=$EJABBERDDIR/priv
|
||||||
fi
|
fi
|
||||||
if [ "$EJABBERD_BIN_PATH" = "" ]; then
|
if [ "$EJABBERD_BIN_PATH" = "" ] ; then
|
||||||
EJABBERD_BIN_PATH=$EJABBERD_PRIV_PATH/bin
|
EJABBERD_BIN_PATH=$EJABBERD_PRIV_PATH/bin
|
||||||
fi
|
fi
|
||||||
if [ "$EJABBERD_SO_PATH" = "" ]; then
|
if [ "$EJABBERD_SO_PATH" = "" ] ; then
|
||||||
EJABBERD_SO_PATH=$EJABBERD_PRIV_PATH/lib
|
EJABBERD_SO_PATH=$EJABBERD_PRIV_PATH/lib
|
||||||
fi
|
fi
|
||||||
if [ "$EJABBERD_MSGS_PATH" = "" ]; then
|
if [ "$EJABBERD_MSGS_PATH" = "" ] ; then
|
||||||
EJABBERD_MSGS_PATH=$EJABBERD_PRIV_PATH/msgs
|
EJABBERD_MSGS_PATH=$EJABBERD_PRIV_PATH/msgs
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -176,7 +180,7 @@ debug ()
|
||||||
echo " EJABBERD_BYPASS_WARNINGS=true"
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
||||||
echo "Press any key to continue"
|
echo "Press any key to continue"
|
||||||
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
||||||
read foo
|
read foo
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
TTY=`tty | sed -e 's/.*\///g'`
|
TTY=`tty | sed -e 's/.*\///g'`
|
||||||
|
@ -208,7 +212,7 @@ live ()
|
||||||
echo " EJABBERD_BYPASS_WARNINGS=true"
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
||||||
echo "Press any key to continue"
|
echo "Press any key to continue"
|
||||||
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
||||||
read foo
|
read foo
|
||||||
fi
|
fi
|
||||||
echo ""
|
echo ""
|
||||||
$EXEC_CMD "$ERL \
|
$EXEC_CMD "$ERL \
|
||||||
|
@ -257,66 +261,66 @@ ctl ()
|
||||||
CONNLOCKDIR=@LOCALSTATEDIR@/lock/ejabberdctl
|
CONNLOCKDIR=@LOCALSTATEDIR@/lock/ejabberdctl
|
||||||
FLOCK='/usr/bin/flock'
|
FLOCK='/usr/bin/flock'
|
||||||
if [ ! -x "$FLOCK" ] || [ ! -d "$CONNLOCKDIR" ] ; then
|
if [ ! -x "$FLOCK" ] || [ ! -d "$CONNLOCKDIR" ] ; then
|
||||||
JOT='/usr/bin/jot'
|
JOT='/usr/bin/jot'
|
||||||
if [ ! -x "$JOT" ] ; then
|
if [ ! -x "$JOT" ] ; then
|
||||||
# no flock or jot, simply invoke ctlexec()
|
# no flock or jot, simply invoke ctlexec()
|
||||||
CTL_CONN="ctl-${ERLANG_NODE}"
|
CTL_CONN="ctl-${ERLANG_NODE}"
|
||||||
ctlexec $CTL_CONN $COMMAND
|
ctlexec $CTL_CONN $COMMAND
|
||||||
result=$?
|
result=$?
|
||||||
else
|
else
|
||||||
# no flock, but at least there is jot
|
# no flock, but at least there is jot
|
||||||
RAND=`jot -r 1 0 $MAXCONNID`
|
RAND=`jot -r 1 0 $MAXCONNID`
|
||||||
CTL_CONN="ctl-${RAND}-${ERLANG_NODE}"
|
CTL_CONN="ctl-${RAND}-${ERLANG_NODE}"
|
||||||
ctlexec $CTL_CONN $COMMAND
|
ctlexec $CTL_CONN $COMMAND
|
||||||
result=$?
|
result=$?
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# we have flock so we get a lock
|
# we have flock so we get a lock
|
||||||
# on one of a limited number of
|
# on one of a limited number of
|
||||||
# conn names -- this allows
|
# conn names -- this allows
|
||||||
# concurrent invocations using a bound
|
# concurrent invocations using a bound
|
||||||
# number of atoms
|
# number of atoms
|
||||||
for N in $(seq 1 $MAXCONNID); do
|
for N in $(seq 1 $MAXCONNID); do
|
||||||
CTL_CONN="ejabberdctl-$N"
|
CTL_CONN="ejabberdctl-$N"
|
||||||
CTL_LOCKFILE="$CONNLOCKDIR/$CTL_CONN"
|
CTL_LOCKFILE="$CONNLOCKDIR/$CTL_CONN"
|
||||||
(
|
(
|
||||||
exec 8>"$CTL_LOCKFILE"
|
exec 8>"$CTL_LOCKFILE"
|
||||||
if flock --nb 8; then
|
if flock --nb 8; then
|
||||||
ctlexec $CTL_CONN $COMMAND
|
ctlexec $CTL_CONN $COMMAND
|
||||||
ssresult=$?
|
ssresult=$?
|
||||||
# segregate from possible flock exit(1)
|
# segregate from possible flock exit(1)
|
||||||
ssresult=$(expr $ssresult \* 10)
|
ssresult=$(expr $ssresult \* 10)
|
||||||
exit $ssresult
|
exit $ssresult
|
||||||
else
|
else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
result=$?
|
result=$?
|
||||||
if [ $result -eq 1 ]; then
|
if [ $result -eq 1 ] ; then
|
||||||
# means we errored out in flock
|
# means we errored out in flock
|
||||||
# rather than in the exec - stay in the loop
|
# rather than in the exec - stay in the loop
|
||||||
# trying other conn names...
|
# trying other conn names...
|
||||||
badlock=1
|
badlock=1
|
||||||
else
|
else
|
||||||
badlock=""
|
badlock=""
|
||||||
break;
|
break;
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
result=$(expr $result / 10)
|
result=$(expr $result / 10)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$badlock" ];then
|
if [ "$badlock" ] ;then
|
||||||
echo "Ran out of connections to try. Your ejabberd processes" >&2
|
echo "Ran out of connections to try. Your ejabberd processes" >&2
|
||||||
echo "may be stuck or this is a very busy server. For very" >&2
|
echo "may be stuck or this is a very busy server. For very" >&2
|
||||||
echo "busy servers, consider raising MAXCONNID in ejabberdctl">&2
|
echo "busy servers, consider raising MAXCONNID in ejabberdctl">&2
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case $result in
|
case $result in
|
||||||
0) :;;
|
0) :;;
|
||||||
1) :;;
|
1) :;;
|
||||||
2) help;;
|
2) help;;
|
||||||
3) help;;
|
3) help;;
|
||||||
esac
|
esac
|
||||||
return $result
|
return $result
|
||||||
}
|
}
|
||||||
|
@ -352,13 +356,13 @@ check_start()
|
||||||
{
|
{
|
||||||
epmd -names | grep -q $NODE && {
|
epmd -names | grep -q $NODE && {
|
||||||
ps ux | grep -v grep | grep -q $ERLANG_NODE && {
|
ps ux | grep -v grep | grep -q $ERLANG_NODE && {
|
||||||
echo "ejabberd is already running."
|
echo "ERROR: The ejabberd node '$ERLANG_NODE' is already running."
|
||||||
exit 4
|
exit 4
|
||||||
} || {
|
} || {
|
||||||
ps ux | grep beam | grep -v "grep beam" && {
|
ps ux | grep beam | grep -v "grep beam" && {
|
||||||
echo "ejabberd node is registered, but no ejabberd process has been found."
|
echo "ERROR: The ejabberd node '$ERLANG_NODE' is registered,"
|
||||||
echo "can not kill epmd as other erlang nodes are running."
|
echo " but no ejabberd process has been found."
|
||||||
echo "please stop all erlang nodes, and call 'epmd -kill'."
|
echo "Shutdown other erlang nodes, and call 'epmd -kill'."
|
||||||
exit 5
|
exit 5
|
||||||
} || {
|
} || {
|
||||||
epmd -kill
|
epmd -kill
|
||||||
|
@ -374,7 +378,7 @@ wait_for_status()
|
||||||
# return: 0 OK, 1 KO
|
# return: 0 OK, 1 KO
|
||||||
timeout=$2
|
timeout=$2
|
||||||
status=4
|
status=4
|
||||||
while [ $status -ne $1 ]; do
|
while [ $status -ne $1 ] ; do
|
||||||
sleep $3
|
sleep $3
|
||||||
timeout=$(($timeout - 1))
|
timeout=$(($timeout - 1))
|
||||||
[ $timeout -eq 0 ] && {
|
[ $timeout -eq 0 ] && {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user