[Linux] for post inatallation : "openfirectl" could not kill it's process in the CentOs or Redhat system

[ “openfirectl” could not kill it’s process in the CentOs or Redhat system. ]

**
**

Given “openfirectl” could not save pid to $OPENFIRE_PIDFILE or /var/run/openfire.pid file.

So. /etc/rc.d/init.d/openfirectl stop dose not kill process !!

If append this line it’s PID will saved in $OPENFIRE_PIDFILE .

ps -U $OPENFIRE_USER -C openfire --no-heading -o pid > $OPENFIRE_PIDFILE


by diif -urN openfirectl.old openfirectl.new

— …/Archive/openfire_src/target/openfire/bin/openfirectl 2013-04-05 16:09:02.936000394 +0900
+++ ./openfirectl.init 2013-04-05 16:17:14.786999497 +0900
@@ -134,8 +134,13 @@
fi

echo

  •    ###----------------------------------------------------------------###
    
  •    OPENFIRE_PID=`ps -U $OPENFIRE_USER  -o pid,cmd --no-heading | grep 'DopenfireHome' | grep -v "grep"  | cut -d' ' -f1 `
    
  •    echo "openfire start with $OPENFIRE_PID !"
    
  •    echo $OPENFIRE_PID >  $OPENFIRE_PIDFILE
    
  •    ###----------------------------------------------------------------###
    
  •   [ $RETVAL -eq 0 -a -d /var/lock/subsys ] && touch /var/lock/subsys/openfire
    
  •   [ $OPENFIRE_PID -gt 0 -a -d /var/lock/subsys ] && touch /var/lock/subsys/openfire
    

sleep 1 # allows prompt to return
cd $OLD_PWD
@@ -185,7 +190,12 @@

Handle how we were called.

case “$CMD” in
start)

  •           start
    
  •           if [ -f /var/lock/subsys/openfire ]
    
  •           then
    
  •                   restart
    
  •           else
    
  •                   start
    
  •           fi
              ;;
      stop)
              stop
    

cp -p openfirectl.init /usr/local/openfire/bin/openfirectl

cp -p openfirectl.init /etc/rc.d/init.d/openfirectl

cp -p openfire.sysconfig /etc/sysconfig/openfire

chmod 755 /usr/local/openfire/bin/openfirectl

chkconfig add openfirectl

chkconfig --level 435 openfirectl on

---- post install –

chkconfig add openfirectl

chkconfig --level 345 openfirectl on

cat /etc/sysconfig/openfire


Set this to the path where openfire lives.

If this is not set the script will look for /usr/local/openfire, then

/opt/openfire.

#OPENFIRE_HOME=""

If there is a different user you would like to run openfire as,

change the following line.

#OPENFIRE_USER="daemon"
OPENFIRE_USER=“iparkm”

If you wish to change the location of the openfire pid file,

change the following line.

export OPENFIRE_PIDFILE="/var/run/openfire.pid"

If you wish to explictly specific the location of the log directory,

you can set it here. Note that this applies to the logs generated outside

openfire itself. If you want to change the location of openfire’s own

logs, see the system property ‘log.directory’. If this is not set,

it will default to $OPENFIRE_HOME/logs.

#OPENFIRE_LOGDIR="/some/where/logs"

If you wish to set any specific options to pass to the JVM, you can

set them with the following variable.

#OPENFIRE_OPTS="-Xmx1024m"

If you wish to override the auto-detected JAVA_HOME variable, uncomment

and change the following line.

export JAVA_HOME="/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64"
export OPENFIRE_HOME="/usr/local/openfire"
OPENFIRE_LOGDIR=/usr/local/openfire/logs

cat /etc/rc.d/init.d/openfirectl


#!/bin/sh

openfirectl Stops and starts the Openfire XMPP service.

chkconfig: 2345 99 1

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

XML based communication, such as chat.

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

config: /etc/sysconfig/openfire

pidfile: /var/run/openfire.pid

This script manages the openfire daemon process. This script should

only be run as root and may double as an init script if desired. You

can symlink it into your rc directories manually, or if you have

chkconfig available, you can copy/symlink it into your init.d directory

and chkconfig --add it. It’s recommended to name it openfire instead of

openfirectl in the init.d directory.

Begin setup work

Initialization

CMD=$1
PATH="/sbin:/bin:/usr/bin:/usr/sbin"
RETVAL=0

Make sure we are running as root

set /usr/bin/id
if [ $1 != “uid=0(root)” ]; then
echo "$0: must be run as root"
exit 1
fi

Get config from sysconfig if on a system that supports it.

[ -f “/etc/sysconfig/openfire” ] && . /etc/sysconfig/openfire

If openfire user is not set elsewhere, set to daemon.

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

If pid file path is not set elsewhere, set to /var/run/openfire.pid.

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

-----------------------------------------------------------------

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

if [ -z “$OPENFIRE_HOME” -o ! -d “$OPENFIRE_HOME” ]; then
if [ -d “/usr/share/openfire” ]; then
OPENFIRE_HOME="/usr/share/openfire"
elif [ -d “/usr/local/openfire” ]; then
OPENFIRE_HOME="/usr/local/openfire"
elif [ -d “/opt/openfire” ]; then
OPENFIRE_HOME="/opt/openfire"
else
echo "Could not find Openfire installation under /opt, /usr/share, or /usr/local."
if [ -f “/etc/sysconfig” ]; then
echo "Please specify the Openfire installation location as variable OPENFIRE_HOME"
echo "in /etc/sysconfig/openfire."
fi
exit 1
fi
fi

If log path is not set already, set to $OPENFIRE_HOME/logs.

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

Attempt to locate java installation.

if [ -z “$JAVA_HOME” ]; then
if [ -d “${OPENFIRE_HOME}/jre” ]; then
JAVA_HOME="${OPENFIRE_HOME}/jre"
elif [ -d “/etc/alternatives/jre” ]; then
JAVA_HOME="/etc/alternatives/jre"
else
jdks=ls -r1d /usr/java/j*
for jdk in $jdks; do
if [ -f “${jdk}/bin/java” ]; then
JAVA_HOME="$jdk"
break
fi
done
if [ -z “$JAVA_HOME” ]; then
if [ -d “/usr/java” -a -d “/usr/java/bin” ]; then
JAVA_HOME="/usr/java"
fi
fi
fi
fi
JAVACMD="${JAVA_HOME}/bin/java"

if [ ! -d “$JAVA_HOME” -o ! -x “$JAVACMD” ]; then
echo "Error: JAVA_HOME is not defined correctly."
echo " Can not sure execute $JAVACMD."
exit 1
fi

Prepare location of openfire libraries

OPENFIRE_LIB="${OPENFIRE_HOME}/lib"

Prepare openfire command line

OPENFIRE_OPTS="${OPENFIRE_OPTS} -DopenfireHome=${OPENFIRE_HOME} -Dopenfire.lib.dir=${OPENFIRE_LIB}"

Prepare local java class path

if [ -z “$LOCALCLASSPATH” ]; then
LOCALCLASSPATH="${OPENFIRE_LIB}/startup.jar"
else
LOCALCLASSPATH="${OPENFIRE_LIB}/startup.jar:${LOCALCLASSPATH}"
fi

Export any necessary variables

export JAVA_HOME JAVACMD

Lastly, prepare the full command that we are going to run.

OPENFIRE_RUN_CMD="${JAVACMD} -server ${OPENFIRE_OPTS} -classpath “${LOCALCLASSPATH}” -jar “${OPENFIRE_LIB}/startup.jar”"

End setup work

start() {
OLD_PWD=pwd
cd $OPENFIRE_LOGDIR

Start daemons.

    echo "Starting openfire: \c"

PID=su - $OPENFIRE_USER -c "nohup $OPENFIRE_RUN_CMD > $OPENFIRE_LOGDIR/nohup.out 2>&1 &"
RETVAL=$?

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

echo
###----------------------------------------------------------------###
OPENFIRE_PID=ps -U $OPENFIRE_USER -o pid,cmd --no-heading | grep 'DopenfireHome' | grep -v "grep" | cut -d' ' -f1
echo "openfire start with $OPENFIRE_PID !"
echo $OPENFIRE_PID > $OPENFIRE_PIDFILE
###----------------------------------------------------------------###

[ $OPENFIRE_PID -gt 0 -a -d /var/lock/subsys ] && touch /var/lock/subsys/openfire

sleep 1 # allows prompt to return
cd $OLD_PWD
}

stop() {
# Stop daemons.
echo “Shutting down openfire: \c”

[ -f “$OPENFIRE_PIDFILE” ] && kill cat $OPENFIRE_PIDFILE
RETVAL=$?
echo

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

restart() {
stop
sleep 10 # give it a few moments to shut down
start
}

condrestart() {
[ -e “/var/lock/subsys/openfire” ] && restart
return 0
}

status() {
pid=cat $OPENFIRE_PIDFILE 2>&1
if [ “$?” = “1” ]; then
echo "openfire is not running"
RETVAL=3
else
ps -p $pid > /dev/null 2>&1
if [ “$?” = “0” ]; then
echo "openfire is running"
RETVAL=0
else
echo "openfire is not running"
RETVAL=1
fi
fi
}

Handle how we were called.

case “$CMD” in
start)
if [ -f /var/lock/subsys/openfire ]
then
restart
else
start
fi
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
condrestart
;;
reload)
restart
;;
status)
status
;;
*)
echo "Usage $0 {start|stop|restart|status|condrestart|reload}"
RETVAL=1
esac

exit $RETVAL