163 lines
4.3 KiB
Plaintext
163 lines
4.3 KiB
Plaintext
$OpenBSD: patch-src_ejabberdctl_template,v 1.2 2009/02/12 09:58:11 sthen Exp $
|
|
--- src/ejabberdctl.template.orig Sun Oct 19 22:00:39 2008
|
|
+++ src/ejabberdctl.template Sun Oct 19 22:05:49 2008
|
|
@@ -1,7 +1,7 @@
|
|
#!/bin/sh
|
|
|
|
# define default configuration
|
|
-POLL=true
|
|
+POLL=false
|
|
SMP=auto
|
|
ERL_MAX_PORTS=32000
|
|
ERL_PROCESSES=250000
|
|
@@ -9,16 +9,18 @@ ERL_MAX_ETS_TABLES=1400
|
|
|
|
# define default environment variables
|
|
NODE=ejabberd
|
|
-HOST=localhost
|
|
+HOST=`hostname -s`
|
|
ERLANG_NODE=$NODE@$HOST
|
|
ERL=@erl@
|
|
ROOTDIR=@rootdir@
|
|
-EJABBERD_CONFIG_PATH=$ROOTDIR/etc/ejabberd/ejabberd.cfg
|
|
-LOGS_DIR=$ROOTDIR/var/log/ejabberd/
|
|
-EJABBERD_DB=$ROOTDIR/var/lib/ejabberd/db/$NODE
|
|
+EJABBERD_CONFIG_PATH=${SYSCONFDIR}/ejabberd/ejabberd.cfg
|
|
+LOGS_DIR=${EJLOGDIR}
|
|
+EJABBERD_DB=${EJDBDIR}/${NODE}
|
|
+ID=`id -g`
|
|
+EJID=`id -g ${JABBERDUSER}`
|
|
|
|
# read custom configuration
|
|
-CONFIG=$ROOTDIR/etc/ejabberd/ejabberdctl.cfg
|
|
+CONFIG=${SYSCONFDIR}/ejabberd/ejabberdctl.cfg
|
|
[ -f "$CONFIG" ] && . "$CONFIG"
|
|
|
|
# parse command line parameters
|
|
@@ -37,23 +39,33 @@ while [ $# -ne 0 ] ; do
|
|
esac
|
|
done
|
|
|
|
+NODE="${ERLANG_NODE%@*}"
|
|
+EJABBERD_DB=${EJDBDIR}/$NODE
|
|
+
|
|
NAME=-name
|
|
[ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] && NAME=-sname
|
|
|
|
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES"
|
|
|
|
# define additional environment variables
|
|
-EJABBERD_EBIN=$ROOTDIR/var/lib/ejabberd/ebin
|
|
-EJABBERD_MSGS_PATH=$ROOTDIR/var/lib/ejabberd/priv/msgs
|
|
-EJABBERD_SO_PATH=$ROOTDIR/var/lib/ejabberd/priv/lib
|
|
-EJABBERD_BIN_PATH=$ROOTDIR/var/lib/ejabberd/priv/bin
|
|
-EJABBERD_LOG_PATH=$LOGS_DIR/ejabberd.log
|
|
-SASL_LOG_PATH=$LOGS_DIR/sasl.log
|
|
+EJABBERD_EBIN=${LOCALBASE}/lib/ejabberd/ebin
|
|
+EJABBERD_MSGS_PATH=${LOCALBASE}/lib/ejabberd/priv/msgs
|
|
+EJABBERD_SO_PATH=${LOCALBASE}/lib/ejabberd/priv/lib
|
|
+EJABBERD_BIN_PATH=${LOCALBASE}/lib/ejabberd/priv/bin
|
|
+EJABBERD_LOG_PATH=${LOGS_DIR}/${NODE}.log
|
|
+SASL_LOG_PATH=${LOGS_DIR}/${NODE}_sasl.log
|
|
DATETIME=`date "+%Y%m%d-%H%M%S"`
|
|
-ERL_CRASH_DUMP=$LOGS_DIR/erl_crash_$DATETIME.dump
|
|
-ERL_INETRC=$ROOTDIR/etc/ejabberd/inetrc
|
|
-HOME=$ROOTDIR/var/lib/ejabberd
|
|
+ERL_CRASH_DUMP=${LOGS_DIR}/erl_crash_${DATETIME}.dump
|
|
+ERL_INETRC=${SYSCONFDIR}/ejabberd/inetrc
|
|
+HOME=${EJDBDIR}
|
|
|
|
+# make sure we execute commands as proper user
|
|
+if [ $ID -eq 0 ]; then
|
|
+ EXEC_CMD='sudo -c - -u ${JABBERDUSER}'
|
|
+else
|
|
+ EXEC_CMD=''
|
|
+fi
|
|
+
|
|
# export global variables
|
|
export EJABBERD_CONFIG_PATH
|
|
export EJABBERD_MSGS_PATH
|
|
@@ -64,23 +76,24 @@ export ERL_CRASH_DUMP
|
|
export ERL_INETRC
|
|
export ERL_MAX_PORTS
|
|
export ERL_MAX_ETS_TABLES
|
|
+export EXEC_CMD
|
|
export HOME
|
|
|
|
-[ -d $EJABBERD_DB ] || mkdir -p $EJABBERD_DB
|
|
-[ -d $LOGS_DIR ] || mkdir -p $LOGS_DIR
|
|
-
|
|
# Compatibility in ZSH
|
|
#setopt shwordsplit 2>/dev/null
|
|
|
|
# start server
|
|
start ()
|
|
{
|
|
- $ERL \
|
|
+ ${EXEC_CMD} $ERL \
|
|
$NAME $ERLANG_NODE \
|
|
-noinput -detached \
|
|
-pa $EJABBERD_EBIN \
|
|
+ -kernel inetrc \"${ERL_INETRC}\" \
|
|
-mnesia dir "\"$EJABBERD_DB\"" \
|
|
-s ejabberd \
|
|
+ -ejabberd config \"${EJABBERD_CONFIG_PATH}\" \
|
|
+ log_path \"${EJABBERD_LOG_PATH}\" \
|
|
-sasl sasl_error_logger \{file,\"$SASL_LOG_PATH\"\} \
|
|
$ERLANG_OPTS $ARGS "$@"
|
|
}
|
|
@@ -104,7 +117,7 @@ debug ()
|
|
echo "Press any key to continue"
|
|
read foo
|
|
echo ""
|
|
- $ERL \
|
|
+ ${EXEC_CMD} $ERL \
|
|
$NAME ${NODE}debug \
|
|
-remsh $ERLANG_NODE \
|
|
$ERLANG_OPTS $ARGS "$@"
|
|
@@ -128,18 +141,21 @@ live ()
|
|
echo "Press any key to continue"
|
|
read foo
|
|
echo ""
|
|
- $ERL \
|
|
+ ${EXEC_CMD} $ERL \
|
|
$NAME $ERLANG_NODE \
|
|
-pa $EJABBERD_EBIN \
|
|
+ -kernel inetrc \"${ERL_INETRC}\" \
|
|
-mnesia dir "\"$EJABBERD_DB\"" \
|
|
-s ejabberd \
|
|
+ -ejabberd config \"${EJABBERD_CONFIG_PATH}\" \
|
|
+ log_path \"${EJABBERD_LOG_PATH}\" \
|
|
$ERLANG_OPTS $ARGS "$@"
|
|
}
|
|
|
|
# common control function
|
|
ctl ()
|
|
{
|
|
- $ERL \
|
|
+ ${EXEC_CMD} $ERL \
|
|
$NAME ejabberdctl \
|
|
-noinput \
|
|
-pa $EJABBERD_EBIN \
|
|
@@ -171,6 +187,20 @@ usage ()
|
|
ctl
|
|
exit
|
|
}
|
|
+
|
|
+# check if we're a user that can execute commands
|
|
+if [ "$ID" -ne 0 -a "$ID" -ne "$EJID" ]; then
|
|
+ echo "this command can only be run by root or the _ejabberd user" >&2
|
|
+ EXEC_CMD='false'
|
|
+ usage
|
|
+fi
|
|
+
|
|
+if [ ! -d $EJABBERD_DB -o ! -w $EJABBERD_DB ] ; then
|
|
+ if [ ! -d ${EJABBERD_DB%/*} -o ! -w ${EJABBERD_DB%/*} ] ; then
|
|
+ echo "${EJABBERD_DB} does not exist and I can't create it!"
|
|
+ exit 1
|
|
+ fi
|
|
+fi
|
|
|
|
case $ARGS in
|
|
' start') start;;
|