openfire init

A working init script for Openfire, tested on Fedora 19.

One of the few things that broke in my recent upgrade to Fedora 19 was the init process for my test Openfire server. With a little tweaking I was able to get the openfired script found in $OPENFIRE_HOME/bin/extra to do the trick.

# openfired	stops and starts the openfire XMPP service
# chkconfig: 2345 99 1
# description: Used to start and stop the openfire XMPP server
# Script used to start openfire 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 $OPENFIRE_HOME/bin/openfire is
# executable by the user you want to run openfire as
# (chmod +x $OPENFIRE_HOME/bin/openfire)
# 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/openfired $90openfired
# Modified 2013/07/31 by P Lembo for Fedora 19

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

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

# -----------------------------------------------------------------
# If a openfire home variable has not been specified, try to determine it
if [ ! $OPENFIRE_HOME ]; then
	if [ -d "/opt/openfire" ]; then
	elif [ -d "/usr/local/openfire" ]; then
		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
execCommand() {
    cd $OPENFIRE_HOME/bin
    # Drop ".sh" extension
	CMD="./openfire $1"
    # Fix syntax of command to execute as app user
	su $OPENFIRE_USER -c "$CMD" &
	sleep 1 # allows prompt to return
	cd $OLD_PWD
start() {
	execCommand "start"
stop() {
	execCommand "stop"
case "$1" in
		sleep 10 # since stop is backgrounded
		retval=$(pgrep -u $OPENFIRE_USER -f $OPENFIRE_HOME/bin/openfire > /dev/null ; echo $?)
		if [ "$retval" = "0" ] ; then 
			echo "openfire is running"
			exit 0
			echo "openfire is not running"
			exit 0
		echo "Usage $0 {start|stop|restart|status}"
		exit 1
exit 0

Besides tightening up the spacing the only changes I made to the original openfired script were to change “” to “openfire” so that it actually matched reality, and fixed the syntax in the line that runs that script as application user.

To focus on those changes:

+   # Drop ".sh" extension
-   CMD="./ $1"
+	CMD="./openfire $1"
+   # Fix syntax of command to execute as app user
-   su -c "$CMD" $OPENFIRE_USER &
+	su $OPENFIRE_USER -c "$CMD" &

The lines highlighted were removed, those not highlighted were added.

This entry was posted in System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).