#!/bin/bash # Start/stop/restart the ejabberd xmpp server bin=/usr/sbin/ejabberdctl start_ejabberd() { echo "Starting ejabberd... " $bin start $bin started } stop_ejabberd() { echo "Stopping ejabberd... " $bin stop $bin stopped } restart_ejabberd() { stop_ejabberd sleep 1 start_ejabberd } status_ejabberd() { $bin status } force-stop_ejabberd() { echo "Killing ejabberd... " port=$(/usr/bin/epmd -names | awk -v name=ejabberd '$2==name {print $5}') if [ -z "$port" ]; then echo "ejabberd not found" else kill $(lsof -i TCP:$port -s TCP:LISTEN | tail -n +2 | awk '{print $2}') fi } reload-config_ejabberd() { $bin reload_config } case "$1" in start) start_ejabberd ;; stop) stop_ejabberd ;; restart|reload) restart_ejabberd ;; status) status_ejabberd ;; force-stop) force-stop_ejabberd ;; reload-config) reload-config_ejabberd ;; *) echo "usage $0 start|stop|restart|status|force-stop|reload-config" ;; esac