Few errors in openfired script in v.3.3.0 for Linux

First of all thaks for the very good software.

Nevertheless, there are few errors in scripts for Linux:


  1. I found nothing when looking for $OPENFIRE_HOME/bin/openfire.sh

  2. Line 92 - [ -f “$OPENFILE_PIDFILE” ] && kill…

  3. Line 75. Incorrect method to get the PID of process. This cause to error in line 91 ([ -f “$OPENFILE_PIDFILE” ] && kill cat $OPENFIRE_PIDFILE) with message “No process”.

  4. Incorrect file name for /var/lock/subsys. In /etc/init.d/ you may find “killall” service. This script looking for files in /var/lock/subsys/ and call “/etc/init.d/$subsys stop” for them, when linux box shutting down. So, file in /var/lock/subsys MUST have the same name as script in /etc/init.d/. In your version of the script this may cause to data loss during box shutting down, cause script in init.d is a “openfired”, file in /var/lock/subsys is a “openfire”

  5. status() always return false (see 3)

So, my changes:


  1. I don’'t know what should be in openfire.sh, so i propose:

Line 62: OPENFIRE_CMD="$OPENFIRE_HOME/bin/openfire.sh" change to

OPENFIRE_CMD="$OPENFIRE_HOME/bin/openfire"

Line 72: su -s /bin/sh -c “$OPENFIRE_CMD” $OPENFIRE_USER > nohup.out 2>&1 & change to

su -s /bin/sh -c “$OPENFIRE_CMD start” $OPENFIRE_USER > nohup.out 2>&1 &

  1. OPENFILE change to OPENFIRE

  2. Lets change “stop” function to avoid PID file using

Line 91: [ -f “$OPENFILE_PIDFILE” ] && kill cat $OPENFIRE_PIDFILE change to

su -s /bin/sh -c “$OPENFIRE_CMD stop” $OPENFIRE_USER > nohup.out 2>&1 &

  1. So, if we have init script with constant name, let change few lines to avoid incorrect $PROG using:

Line 82: && touch /var/lock/subsys/$PROG change to

&& touch /var/lock/subsys/openfired

Line 96: [ $RETVAL -eq 0 -a -f “/var/lock/subsys/$PROG” ] && rm -f /var/lock/subsys/$PROG change to

[ $RETVAL -eq 0 -a -f “/var/lock/subsys/openfired” ] && rm -f /var/lock/subsys/openfired

  1. Sorry, but why you are using PID file? You already have much more usable tool, ./openfire status, is’'nt it?

My status() function:

status() {

echo -n "Status of $PROG: "

su -s /bin/sh -c “$OPENFIRE_CMD status” $OPENFIRE_USER 2>&1

}

That’'s all

So, this is IMHO more correct script:


#!/bin/sh

  1. openfired Stops and starts the Openfire XMPP service.

  1. chkconfig: 2345 99 1

  2. description: Openfire is an XMPP server, which is a server that facilitates \

  3. XML based communication, such as chat.

  4. config: /opt/openfire/conf/openfire.xml

  5. config: /etc/sysconfig/openfire

  6. pidfile: /var/run/openfire.pid

  1. This script has currently been tested on Redhat and CentOS based systems,

  2. but should theoretically work on most UNIX like systems

  1. Before running this script make sure $OPENFIRE_HOME/bin/openfire.sh is

  2. executable by the user you want to run openfire as

  3. (chmod +x $OPENFIRE_HOME/bin/openfire.sh)

  1. This script should be copied into /etc/init.d and linked into

  2. your default runlevel directory.

  3. You can find your default runlevel directory by typing:

  4. grep default /etc/inittab

  1. Link to the directory like follows

  2. cd /etc/rc.d

  3. ln -s …/init.d/openfired S99openfired

PATH=/sbin:/bin:/usr/bin:/usr/sbin

RETVAL=0

PROG=“openfire”

  1. Check that we are root … so non-root users stop here

[ “id -u” = 0 ] || exit 1

  1. Get config.

[ -f “/etc/sysconfig/$PROG” ] && . /etc/sysconfig/$PROG

  1. If openfire user is not set in sysconfig, set to jive.

[ -z “$OPENFIRE_USER” ] && OPENFIRE_USER=jive

  1. If pid file path is not set in sysconfig, set to /var/run/openfired.pid.

[ -z “$OPENFIRE_PIDFILE” ] && OPENFIRE_PIDFILE=/var/run/$PROG.pid


  1. If a openfire home variable has not been specified, try to determine it

if [ -z “$OPENFIRE_HOME” ]; then

if [ -d “/opt/openfire” ]; then

OPENFIRE_HOME="/opt/openfire"

elif [ -d “/usr/local/openfire” ]; then

OPENFIRE_HOME="/usr/local/openfire"

else

echo “Could not find Openfire installation under /opt or /usr/local”

echo “Please specify the Openfire installation location in environment variable OPENFIRE_HOME”

exit 1

fi

fi

[ -z “$OPENFIRE_LOGDIR” ] && OPENFIRE_LOGDIR=$OPENFIRE_HOME/logs

OPENFIRE_CMD="$OPENFIRE_HOME/bin/openfire"

[ -f “$OPENFIRE_CMD” ] || exit 1

start() {

OLD_PWD=pwd

cd $OPENFIRE_LOGDIR

  1. Start daemons.

echo -n "Starting $PROG: "

su -s /bin/sh -c “$OPENFIRE_CMD start” $OPENFIRE_USER > nohup.out 2>&1 &

RETVAL=$?

if [ $RETVAL -eq 0 -a ! -z “$OPENFIRE_PIDFILE” ]; then

echo $! > $OPENFIRE_PIDFILE

fi

echo

&& touch /var/lock/subsys/openfired

sleep 1 # allows prompt to return

cd $OLD_PWD

}

stop() {

  1. Stop daemons.

echo -n "Shutting down $PROG: "

su -s /bin/sh -c “$OPENFIRE_CMD stop” $OPENFIRE_USER > nohup.out 2>&1 &

echo

[ $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

}

restart() {

stop

sleep 10 # give it a few moments to shut down

start

}

condrestart() {

[ -e “/var/lock/subsys/$PROG” ] && restart

return 0

}

status() {

echo -n "Status of $PROG: "

su -s /bin/sh -c “$OPENFIRE_CMD status” $OPENFIRE_USER 2>&1

}

  1. Handle how we were called.

case “$1” in

start)

start

;;

stop)

stop

;;

restart)

restart

;;

condrestart)

condrestart

;;

status)

status

;;

*)

echo “Usage $0 {start|stop|restart|status|condrestart}”

RETVAL=1

esac

exit $RETVAL