Skip to content

Instantly share code, notes, and snippets.

@pstadler
Created October 19, 2012 13:03
Show Gist options
  • Save pstadler/3918130 to your computer and use it in GitHub Desktop.
Save pstadler/3918130 to your computer and use it in GitHub Desktop.
ejabberd control script
function ej {
EJABBERD_HOME=/usr/local/ejabberd-commercial
EJABBERD_CTL=$EJABBERD_HOME/sbin/ejabberdctl
case "$1" in
restart)
$EJABBERD_CTL stop && $EJABBERD_CTL stopped; $EJABBERD_CTL start
;;
reload)
$EJABBERD_CTL update $2
;;
kill)
shift
out=""
for proc in "beam" "epmd"; do
pids=$(ps -ef | grep "erlang" | grep "${proc}" | grep -v "grep" | awk '{print $2}')
for pid in $(echo $pids | tr '\n' ' '); do
if [[ -n $pid ]]; then
kill $@ $pid
out="${out}${proc} killed ($pid)\n"
fi
done
done
if [ "$out" ]; then
echo -n $out
else
echo 'no process killed'
fi
;;
log|tail)
shift
tail -f -n1000 $@ $EJABBERD_HOME/var/log/ejabberd/ejabberd.log
;;
home)
cd $EJABBERD_HOME
;;
config|cfg|conf)
cd $EJABBERD_HOME/etc/ejabberd
;;
build)
if [ -f "./build.sh" ]; then
./build.sh && cp -v ebin/*.(beam|app) $EJABBERD_HOME/lib/ejabberd/ebin
else
echo "Needs to be executed in a directory containing a build.sh script."
fi
;;
--help|-h)
echo "Ejabberd helper script"
echo
echo "Executes commands on ejabberd-commercial."
echo
echo "Usage $0 [commands] [arguments]"
echo
echo "Commands:"
echo " restart: Restart ejabberd"
echo " reload [name|all]: Reload a specific module or all changed modules"
echo " kill: Kill ejabberd (epmd and beam processes)"
echo " log|tail: tail -f ejabberd.log file"
echo " home: cd to ejabberd home directory"
echo " config|cfg|conf: cd to ejabberd config directory"
echo " build: Call build.sh in current directory"
echo " and copy built ebin|app files to the ejabberd ebin directory"
echo " --help|-h: Display this help"
echo
echo "If a command not listed in the previous list is used, it will be directed to $EJABBERD_CTL."
echo
;;
*)
$EJABBERD_CTL $@
;;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment