#!/bin/sh
# chkconfig: 345 90 14
# description: starts the ColdFusion MX server
PATH=/usr/xpg4/bin:/bin:/sbin:/usr/bin:/usr/sbin:$PATH
CONNECTOR=""
RUNTIME_USER="QA"
JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home"
JAVA_EXECUTABLE="/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/bin/java"
DOCROOT="/opt/ColdFusion9/wwwroot"
CF_DIR="/opt/ColdFusion9"
JRUN_BIN="${CF_DIR}/runtime/bin"
IS_RUNNING="false"
IS_MAC="false"
ID=`id -u`
if [ "`uname`" = "Darwin" ]; then
# nothing, on OSX we don't care about the user name. We assume that the user running it has permission to do everything
IS_MAC="true"
elif [ ! $ID -eq 0 ]; then
echo "You must be root to start ColdFusion ."
exit 1
fi
cfrunning() {
IS_RUNNING="false"
if [ $OS = "Solaris" ]; then
# The comm output on Solaris includes the full path
ps -eo comm | xargs -n 1 basename | fgrep coldfusion9 > /dev/null 2>&1
else
# other platforms have only the executable name
# $PSCMD | fgrep coldfusion9 > /dev/null 2>&1
$PSCMD | grep -i $JRUN_BIN | grep -v 'grep' > /dev/null 2>&1
fi
if [ $? -eq 0 ]; then
IS_RUNNING="true"
fi
}
cfstart() {
[ -f $CF_DIR/bin/jvm.config ] || {
ln -s $CF_DIR/runtime/bin/jvm.config $CF_DIR/bin/jvm.config
}
cfrunning
if [ "$IS_RUNNING" = "true" ]; then
echo "ColdFusion 9 is already running"
echo exiting
exit 2
fi
echo "Starting ColdFusion 9..."
eval $CFSTART >> $CF_DIR/logs/cfserver.log 2>&1
echo "The ColdFusion 9 server is starting up and will be available shortly."
# Insert a sleep statement to give the server a few moments.
sleep 5
cfrunning
if [ "$IS_RUNNING" = "false" ]; then
echo "There has been an error starting ColdFusion 9, please check the logs."
exit 1
fi
[ -f "$CF_DIR/bin/cf-connectors.sh" ] && {
# give the server a few more seconds to come up
sleep 5
echo "======================================================================"
echo "Running the ColdFusion 9 connector wizard"
echo "======================================================================"
sh $CF_DIR/bin/cf-connectors.sh && {
mv -f $CF_DIR/bin/cf-connectors.sh $CF_DIR/bin/cf-connectors-run.sh
}
}
echo "======================================================================"
echo "ColdFusion 9 has been started."
echo "ColdFusion 9 will write logs to $CF_DIR/logs/cfserver.log"
echo "======================================================================"
}
cfstop() {
cfrunning
if [ "$IS_RUNNING" = "false" ]; then
echo "ColdFusion 9 does not seem to be currently running"
return
fi
echo "Stopping ColdFusion 9, please wait"
eval $CFSTOP
sleep 10
cfrunning
if [ "$IS_RUNNING" = "true" ]; then
echo "The ColdFusion 9 server seems to be hanging, will stop non-gracefully"
if [ $OS = "Solaris" ]; then
$PSCMD | fgrep runtime/bin/coldfusion9 | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1
else
# other platforms have only the executable name
# $PSCMD | fgrep coldfusion9 | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1
$PSCMD | grep -i $JRUN_BIN | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1
echo "DEBUG: $PSCMD | grep -i $JRUN_BIN | grep -v 'grep' | awk '{print $1}'"
fi
sleep 2
fi
cfrunning
if [ "$IS_RUNNING" = "true" ]; then
echo "There are some very stubborn ColdFusion 9 processes that will not die, please kill the following PIDs by hand: "
if [ $OS = "Solaris" ]; then
$PSCMD | fgrep runtime/bin/coldfusion9 | awk '{print $1}'
else
# other platforms have only the executable name
# $PSCMD | fgrep coldfusion9 | awk '{print $1}'
$PSCMD | grep -i $JRUN_BIN | awk '{print $1}'
echo "DEBUG: $PSCMD | grep -i $JRUN_BIN | grep -v 'grep' | awk '{print $1}'"
fi
echo exiting
exit 1
fi
echo "ColdFusion 9 has been stopped"
}
case `uname` in
SunOS)
OS=Solaris
PSCMD="ps -eo pid,comm"
LD_LIBRARY_PATH="$CF_DIR/lib:$CF_DIR/lib/_solaris/bin"
CFSTART='su $RUNTIME_USER -c "PATH=$PATH:$CF_DIR/runtime/bin; export PATH; LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd $CF_DIR/runtime/bin; nohup $CF_DIR/runtime/bin/coldfusion9 -jar jrun.jar -autorestart -start coldfusion &"'
CFSTOP='su $RUNTIME_USER -c "PATH=$PATH:$CF_DIR/runtime/bin; export PATH; cd $CF_DIR/runtime/bin; $CF_DIR/runtime/bin/coldfusion9 -jar jrun.jar stop coldfusion"'
;;
Darwin)
OS=Darwin
# PSCMD="ps -axc"
PSCMD="ps -ef"
LD_LIBRARY_PATH="$CF_DIR/lib"
CFSTART='export PATH=$PATH:$CF_DIR/runtime/bin; LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export LD_LIBRARY_PATH;cd $CF_DIR/runtime/bin; $CF_DIR/runtime/bin/coldfusion9 -jar jrun.jar -start coldfusion &'
CFSTOP='env -i; cd $CF_DIR/runtime/bin; $CF_DIR/runtime/bin/coldfusion9 -jar jrun.jar stop coldfusion'
;;
Linux)
OS=Linux
PSCMD="ps -eo pid,comm"
LD_LIBRARY_PATH="$CF_DIR/lib:$CF_DIR/lib/_ilnx21/bin"
SUCMDFILE=su
if [ -x /sbin/runuser ]; then
SUCMDFILE=/sbin/runuser
fi
CFSTART='$SUCMDFILE -s /bin/sh $RUNTIME_USER -c "export PATH=$PATH:$CF_DIR/runtime/bin; export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; cd $CF_DIR/runtime/bin; nohup $CF_DIR/runtime/bin/coldfusion9 -jar jrun.jar -autorestart -start coldfusion &"'
CFSTOP='$SUCMDFILE -s /bin/sh $RUNTIME_USER -c "env -i; cd $CF_DIR/runtime/bin; $CF_DIR/runtime/bin/coldfusion9 -jar jrun.jar stop coldfusion"'
# Some Java JVMs (both from Sun and IBM) don't work with the new floating stack
# feature of the i686 version of glibc. Force glibc to use the deprecated stack model.
# Check if the OS is SuSE8.1 or SuSE 9 - if it is, do not use the deprecated stack model.
#SUSEFLAG=`grep 'SuSE Linux 8.1\|UnitedLinux 1.0\|SuSE Linux 9\|SUSE LINUX Enterprise Server 9' /etc/SuSE-release /etc/UnitedLinux-release /etc/UnitedLinux-release 2> /dev/null`
#if [ ! "$SUSEFLAG" ]; then
#LD_ASSUME_KERNEL=2.2.9
#export LD_ASSUME_KERNEL
#fi
;;
*)
echo "Your OS: `uname` is unsupported"
echo "exiting"
exit 1
;;
esac
ARG=$1
[ -z "$ARG" ] && ARG=usage
case $ARG in
start)
cfstart
;;
stop)
cfstop
;;
restart)
echo "Restarting ColdFusion 9..."
cfstop
cfstart
;;
status)
if [ -x "$CF_DIR/bin/cfstat" ]; then
shift
$CF_DIR/bin/cfstat $@
else
echo "$0: $CF_DIR/bin/cfstat no such file"
fi
;;
wsconfig)
WSCONFIG_JAR=$CF_DIR/runtime/lib/wsconfig.jar
if [ $# -eq 0 ]; then
# no arguments so display built-in help from wsconfig.jar
$JAVA_EXECUTABLE -jar $WSCONFIG_JAR -help
break
else
# brief help
if [ "$2" = "help" ]; then
echo "To configure a webserver connector you must specify the -ws and -dir options."
echo "If configuring Apache it is recomended that you also specify the -bin and "
echo "-script options."
echo ""
echo "To list all configured webserver connectors use the -list option."
echo "To remove a configured webserver connector use the -r option with the "
echo "-ws and -dir options."
echo "To remove all webserver connectors use the -uninstall option."
echo "To upgrade all installed webserver connectors use the -upgrade option."
echo ""
echo "For more detailed help see $0 $1."
fi
break
fi
# pass on all args to wsconfig.jar
shift
$JAVA_EXECUTABLE -jar $WSCONFIG_JAR $@ -coldfusion
;;
*)
echo "Usage:$0 (start|stop|restart|status|wsconfig)"
;;
esac
exit 0