Commit a23de6ea authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-872] Modifications for improvements towards more thorough init scripts

and such.  Still work to be done.



git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@7980 b35dd754-fafc-0310-a699-88a17e54d16e
parent 83a7680b
#!/bin/bash #!/bin/sh
# #
# openfired Stops and starts the Openfire XMPP service. # openfired Stops and starts the Openfire XMPP service.
# #
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
# description: Openfire is an XMPP server, which is a server that facilitates \ # description: Openfire is an XMPP server, which is a server that facilitates \
# XML based communication, such as chat. # XML based communication, such as chat.
# config: /opt/openfire/conf/openfire.xml # config: /opt/openfire/conf/openfire.xml
# pidfile: /var/run/openfired.pid # config: /etc/sysconfig/openfire
# pidfile: /var/run/openfire.pid
# #
# This script has currently been tested on Redhat and CentOS based systems, # This script has currently been tested on Redhat and CentOS based systems,
# but should theoretically work on most UNIX like systems # but should theoretically work on most UNIX like systems
...@@ -25,19 +26,26 @@ ...@@ -25,19 +26,26 @@
# ln -s ../init.d/openfired S99openfired # ln -s ../init.d/openfired S99openfired
# #
PATH=/sbin:/bin:/usr/bin:/usr/sbin
RETVAL=0
PROG="openfire"
# Check that we are root ... so non-root users stop here
[ "`id -u`" = 0 ] || exit 1
# Get config. # Get config.
[ -f /etc/sysconfig/openfire ] && . /etc/sysconfig/openfire [ -f "/etc/sysconfig/$PROG" ] && . /etc/sysconfig/$PROG
# If openfire user is not set in sysconfig, set to jive. # If openfire user is not set in sysconfig, set to jive.
[ -z "$OPENFIRE_USER" ] && OPENFIRE_USER=jive [ -z "$OPENFIRE_USER" ] && OPENFIRE_USER=jive
# If pid file path is not set in sysconfig, set to /var/run/openfired.pid. # If pid file path is not set in sysconfig, set to /var/run/openfired.pid.
[ -z "$OPENFIRE_PIDFILE" ] && OPENFIRE_PIDFILE=/var/run/openfired.pid [ -z "$OPENFIRE_PIDFILE" ] && OPENFIRE_PIDFILE=/var/run/$PROG.pid
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# If a openfire home variable has not been specified, try to determine it # If a openfire home variable has not been specified, try to determine it
if [ ! $OPENFIRE_HOME ]; then if [ -z "$OPENFIRE_HOME" ]; then
if [ -d "/opt/openfire" ]; then if [ -d "/opt/openfire" ]; then
OPENFIRE_HOME="/opt/openfire" OPENFIRE_HOME="/opt/openfire"
elif [ -d "/usr/local/openfire" ]; then elif [ -d "/usr/local/openfire" ]; then
...@@ -49,18 +57,19 @@ if [ ! $OPENFIRE_HOME ]; then ...@@ -49,18 +57,19 @@ if [ ! $OPENFIRE_HOME ]; then
fi fi
fi fi
RETVAL=0 [ -z "$OPENFIRE_LOGDIR" ] && OPENFIRE_LOGDIR=$OPENFIRE_HOME/logs
prog="openfired"
OPENFIRE_CMD="$OPENFIRE_HOME/bin/openfire.sh"
[ -f "$OPENFIRE_CMD" ] || exit 1
start() { start() {
OLD_PWD=`pwd` OLD_PWD=`pwd`
cd $OPENFIRE_HOME/bin cd $OPENFIRE_LOGDIR
# Start daemons. # Start daemons.
echo -n $"Starting $prog: " echo -n "Starting $PROG: "
CMD=./openfire.sh su -s /bin/sh -c "$OPENFIRE_CMD" $OPENFIRE_USER > nohup.out 2>&1 &
su -s /bin/bash -c "$CMD" $OPENFIRE_USER &
RETVAL=$? RETVAL=$?
if [ $RETVAL -eq 0 -a ! -z "$OPENFIRE_PIDFILE" ]; then if [ $RETVAL -eq 0 -a ! -z "$OPENFIRE_PIDFILE" ]; then
...@@ -69,7 +78,7 @@ start() { ...@@ -69,7 +78,7 @@ start() {
echo echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/openfired [ $RETVAL -eq 0 -a -d /var/lock/subsys ] && touch /var/lock/subsys/$PROG
sleep 1 # allows prompt to return sleep 1 # allows prompt to return
cd $OLD_PWD cd $OLD_PWD
...@@ -77,17 +86,46 @@ start() { ...@@ -77,17 +86,46 @@ start() {
stop() { stop() {
# Stop daemons. # Stop daemons.
echo -n $"Shutting down $prog: " echo -n "Shutting down $PROG: "
[ -f $OPENFILE_PIDFILE ] && kill `cat $OPENFIRE_PIDFILE` [ -f "$OPENFILE_PIDFILE" ] && kill `cat $OPENFIRE_PIDFILE`
RETVAL=$? RETVAL=$?
echo echo
[ $RETVAL -eq 0 -a -f $OPENFIRE_PIDFILE ] && rm -f $OPENFIRE_PIDFILE [ $RETVAL -eq 0 -a -f "$OPENFIRE_PIDFILE" ] && rm -f $OPENFIRE_PIDFILE
[ $RETVAL -eq 0 -a -f /var/lock/subsys/openfired ] && rm -f /var/lock/subsys/openfired [ $RETVAL -eq 0 -a -f "/var/lock/subsys/$PROG" ] && rm -f /var/lock/subsys/$PROG
}
restart() {
stop
sleep 10 # give it a few moments to shut down
start
}
condrestart() {
[ -e "/var/lock/subsys/$PROG" ] && restart
return 0
}
status() {
pid=`cat $OPENFIRE_PIDFILE 2>&1`
if [ "$?" = "1" ]; then
echo "openfire is not running"
RETVAL=0
else
ps -p $pid > /dev/null 2>&1
if [ "$?" = "0" ]; then
echo "openfire is running"
RETVAL=0
else
echo "openfire is not running"
RETVAL=0
fi
fi
} }
# Handle how we were called.
case "$1" in case "$1" in
start) start)
start start
...@@ -96,23 +134,17 @@ case "$1" in ...@@ -96,23 +134,17 @@ case "$1" in
stop stop
;; ;;
restart) restart)
stop restart
sleep 10 # since stop is backgrounded ;;
start condrestart)
condrestart
;; ;;
status) status)
retval=$(pgrep -u $OPENFIRE_USER -f $OPENFIRE_HOME/bin/openfire.sh > /dev/null ; echo $?) status
if [ "$retval" = "0" ] ; then
echo "openfire is running"
exit 0
else
echo "openfire is not running"
exit 0
fi
;; ;;
*) *)
echo "Usage $0 {start|stop|restart|status}" echo "Usage $0 {start|stop|restart|status|condrestart}"
exit 1 RETVAL=1
esac esac
exit 0 exit $RETVAL
#!/bin/sh #!/bin/sh
# #
# $RCSfile$ # $RCSfile$
# $Revision: 1194 $ # $Revision: 1194 $
# $Date: 2005-03-30 13:39:54 -0300 (Wed, 30 Mar 2005) $ # $Date: 2005-03-30 13:39:54 -0300 (Wed, 30 Mar 2005) $
# #
# tries to determine arguments to launch openfire # tries to determine arguments to launch openfire
# OS specific support. $var _must_ be set to either true or false. # OS specific support. $var _must_ be set to either true or false.
cygwin=false; cygwin=false;
darwin=false; darwin=false;
linux=false; linux=false;
case "`uname`" in case "`uname`" in
CYGWIN*) cygwin=true ;; CYGWIN*) cygwin=true ;;
Darwin*) darwin=true Darwin*) darwin=true
if [ -z "$JAVA_HOME" ] ; then if [ -z "$JAVA_HOME" ] ; then
JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
fi fi
;; ;;
Linux*) linux=true Linux*) linux=true
jdks=`ls -r1d /usr/java/j*` jdks=`ls -r1d /usr/java/j*`
for jdk in $jdks; do for jdk in $jdks; do
if [ -f "$jdk/bin/java" ]; then if [ -f "$jdk/bin/java" ]; then
JAVA_HOME="$jdk" JAVA_HOME="$jdk"
break break
fi fi
done done
;; ;;
esac esac
#if openfire home is not set or is not a directory #if openfire home is not set or is not a directory
if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then if [ -z "$OPENFIRE_HOME" -o ! -d "$OPENFIRE_HOME" ]; then
if [ -d /opt/openfire ] ; then if [ -d /opt/openfire ] ; then
OPENFIRE_HOME="/opt/openfire" OPENFIRE_HOME="/opt/openfire"
fi fi
if [ -d /usr/local/openfire ] ; then if [ -d /usr/local/openfire ] ; then
OPENFIRE_HOME="/usr/local/openfire" OPENFIRE_HOME="/usr/local/openfire"
fi fi
if [ -d ${HOME}/opt/openfire ] ; then if [ -d ${HOME}/opt/openfire ] ; then
OPENFIRE_HOME="${HOME}/opt/openfire" OPENFIRE_HOME="${HOME}/opt/openfire"
fi fi
#resolve links - $0 may be a link in openfire's home #resolve links - $0 may be a link in openfire's home
PRG="$0" PRG="$0"
progname=`basename "$0$"` progname=`basename "$0$"`
# need this for relative symlinks # need this for relative symlinks
# need this for relative symlinks # need this for relative symlinks
while [ -h "$PRG" ] ; do while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"` ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'` link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then if expr "$link" : '/.*' > /dev/null; then
PRG="$link" PRG="$link"
else else
PRG=`dirname "$PRG"`"/$link" PRG=`dirname "$PRG"`"/$link"
fi fi
done done
#assumes we are in the bin directory #assumes we are in the bin directory
OPENFIRE_HOME=`dirname "$PRG"`/.. OPENFIRE_HOME=`dirname "$PRG"`/..
#make it fully qualified #make it fully qualified
OPENFIRE_HOME=`cd "$OPENFIRE_HOME" && pwd` OPENFIRE_HOME=`cd "$OPENFIRE_HOME" && pwd`
fi fi
OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=${OPENFIRE_HOME}" OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=${OPENFIRE_HOME}"
# For Cygwin, ensure paths are in UNIX format before anything is touched # For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then if $cygwin ; then
[ -n "$OPENFIRE_HOME" ] && [ -n "$OPENFIRE_HOME" ] &&
OPENFIRE_HOME=`cygpath --unix "$OPENFIRE_HOME"` OPENFIRE_HOME=`cygpath --unix "$OPENFIRE_HOME"`
[ -n "$JAVA_HOME" ] && [ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"` JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
fi fi
#set the OPENFIRE_LIB location #set the OPENFIRE_LIB location
OPENFIRE_LIB="${OPENFIRE_HOME}/lib" OPENFIRE_LIB="${OPENFIRE_HOME}/lib"
OPENFIRE_OPTS="${OPENFIRE_OPTS} -Dopenfire.lib.dir=${OPENFIRE_LIB}" OPENFIRE_OPTS="${OPENFIRE_OPTS} -Dopenfire.lib.dir=${OPENFIRE_LIB}"
# Override with bundled jre if it exists.
if [ -z "$JAVACMD" ] ; then if [ -f "$OPENFIRE_HOME/jre/bin/java" ]; then
if [ -n "$JAVA_HOME" ] ; then JAVA_HOME="$OPENFIRE_HOME/jre"
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then JAVACMD="$OPENFIRE_HOME/jre/bin/java"
# IBM's JDK on AIX uses strange locations for the executables fi
JAVACMD="$JAVA_HOME/jre/sh/java"
else if [ -z "$JAVACMD" ] ; then
JAVACMD="$JAVA_HOME/bin/java" if [ -n "$JAVA_HOME" ] ; then
fi if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
else # IBM's JDK on AIX uses strange locations for the executables
JAVACMD=`which java 2> /dev/null ` JAVACMD="$JAVA_HOME/jre/sh/java"
if [ -z "$JAVACMD" ] ; then else
JAVACMD=java JAVACMD="$JAVA_HOME/bin/java"
fi fi
fi else
fi JAVACMD=`which java 2> /dev/null `
if [ -z "$JAVACMD" ] ; then
if [ ! -x "$JAVACMD" ] ; then JAVACMD=java
echo "Error: JAVA_HOME is not defined correctly." fi
echo " We cannot execute $JAVACMD" fi
exit 1 fi
fi
if [ ! -x "$JAVACMD" ] ; then
if [ -z "$LOCALCLASSPATH" ] ; then echo "Error: JAVA_HOME is not defined correctly."
LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar echo " We cannot execute $JAVACMD"
else exit 1
LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar:$LOCALCLASSPATH fi
fi
if [ -z "$LOCALCLASSPATH" ] ; then
# For Cygwin, switch paths to appropriate format before running java LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar
if $cygwin; then else
if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then LOCALCLASSPATH=$OPENFIRE_LIB/startup.jar:$LOCALCLASSPATH
format=mixed fi
else
format=windows # For Cygwin, switch paths to appropriate format before running java
fi if $cygwin; then
OPENFIRE_HOME=`cygpath --$format "$OPENFIRE_HOME"` if [ "$OS" = "Windows_NT" ] && cygpath -m .>/dev/null 2>/dev/null ; then
OPENFIRE_LIB=`cygpath --$format "$OPENFIRE_LIB"` format=mixed
JAVA_HOME=`cygpath --$format "$JAVA_HOME"` else
LOCALCLASSPATH=`cygpath --path --$format "$LOCALCLASSPATH"` format=windows
if [ -n "$CLASSPATH" ] ; then fi
CLASSPATH=`cygpath --path --$format "$CLASSPATH"` OPENFIRE_HOME=`cygpath --$format "$OPENFIRE_HOME"`
fi OPENFIRE_LIB=`cygpath --$format "$OPENFIRE_LIB"`
CYGHOME=`cygpath --$format "$HOME"` JAVA_HOME=`cygpath --$format "$JAVA_HOME"`
fi LOCALCLASSPATH=`cygpath --path --$format "$LOCALCLASSPATH"`
if [ -n "$CLASSPATH" ] ; then
# add a second backslash to variables terminated by a backslash under cygwin CLASSPATH=`cygpath --path --$format "$CLASSPATH"`
if $cygwin; then fi
case "$OPENFIRE_HOME" in CYGHOME=`cygpath --$format "$HOME"`
*\\ ) fi
OPENFIRE_HOME="$OPENFIRE_HOME\\"
;; # add a second backslash to variables terminated by a backslash under cygwin
esac if $cygwin; then
case "$CYGHOME" in case "$OPENFIRE_HOME" in
*\\ ) *\\ )
CYGHOME="$CYGHOME\\" OPENFIRE_HOME="$OPENFIRE_HOME\\"
;; ;;
esac esac
case "$LOCALCLASSPATH" in case "$CYGHOME" in
*\\ ) *\\ )
LOCALCLASSPATH="$LOCALCLASSPATH\\" CYGHOME="$CYGHOME\\"
;; ;;
esac esac
case "$CLASSPATH" in case "$LOCALCLASSPATH" in
*\\ ) *\\ )
CLASSPATH="$CLASSPATH\\" LOCALCLASSPATH="$LOCALCLASSPATH\\"
;; ;;
esac esac
fi case "$CLASSPATH" in
*\\ )
openfire_exec_command="exec \"$JAVACMD\" -server $OPENFIRE_OPTS -classpath \"$LOCALCLASSPATH\" -jar \"$OPENFIRE_LIB\"/startup.jar" CLASSPATH="$CLASSPATH\\"
eval $openfire_exec_command ;;
esac
fi
openfire_exec_command="exec $JAVACMD -server $OPENFIRE_OPTS -classpath \"$LOCALCLASSPATH\" -jar \"$OPENFIRE_LIB/startup.jar\""
eval $openfire_exec_command
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment