Newer
Older
Openfire-connectionmanager / src / bin / extra / cmanagerd
@Gaston Dombiak Gaston Dombiak on 21 Aug 2008 2 KB
#!/bin/sh

# cmanagerd
#
# chkconfig: 2345 20 80
# description: Used to start and stop the Connection Manager service
# 
# Script used to start Connection Manager as daemon
# The script has currently been tested on Redhat Fedora Core 3,
# but should theoretically work on most UNIX like systems
#
# before running this script make sure $CMANAGER_HOME/bin/cmanager is
# executable by the user you want to run Connection Manager as
# (chmod +x $CMANAGER_HOME/bin/cmanager)
#
# This script should be copied into /etc/init.d and linked into
# your default runlevel directory.
# You can find your default runlevel directory by typing: 
# grep default /etc/inittab
#
# Link to the directory like follows
# cd /etc/rc<num>.d
# ln -s ../init.d/cmanagerd $90cmanagerd
#

# Set this to tell this script where Connection Manager lives
# If this is not set the script will look for /opt/connection_manager, then /usr/local/connection_manager
#export CMANAGER_HOME=

# If there is a different user you would like to run this script as,
# change the following line
export CMANAGER_USER=jive

# -----------------------------------------------------------------

# If a Connection Manager home variable has not been specified, try to determine it
if [ ! $CMANAGER_HOME ]; then
	if [ -d "/opt/connection_manager" ]; then
		CMANAGER_HOME="/opt/connection_manager"
	elif [ -d "/usr/local/connection_manager" ]; then
		CMANAGER_HOME="/usr/local/connection_manager"
	else
		echo "Could not find Connection Manager installation under /opt or /usr/local"
		echo "Please specify the Connection Manager installation location in environment variable CMANAGER_HOME"
		exit 1
	fi
fi


function execCommand() {
  if [ "$1" == "start" ]; then
	if [ -e /var/run/cmanager.pid ]; then
		echo "cmanager already running" 2>&1
		exit 1
	fi
	OLD_PWD=`pwd`
	cd $CMANAGER_HOME/bin
	CMD="./cmanager.sh $1"
	su -c "$CMD" $CMANAGER_USER &
	echo "$!" > /var/run/cmanager.pid
	cd $OLD_PWD
  elif [ "$1" == "stop" ]; then
    if [ -e /var/run/cmanager.pid ]; then
	if ps -p `cat /var/run/cmanager.pid` 2>/dev/null 1>&2; then
		kill `cat /var/run/cmanager.pid`
		if [ "$?" == 0 ]; then
			rm -f /var/run/cmanager.pid
		else
			echo "kill failed. try again or kill manually" 1>&2
		fi
	fi
	rm -f /var/run/cmanager.pid
    else
	echo "not running"
    fi
  fi
}


start() {
	execCommand "start"
}

stop() {
	execCommand "stop"
}
status() {
  if [ -e /var/run/cmanager.pid ]; then
    PID=`cat /var/run/cmanager.pid`
    echo "running pid is $PID"
  else
    echo "not running"
  fi
}


case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status
		;;
	*)
		echo "Usage $0 {start|stop|status}"
		exit 1
esac

exit 0