saidone.org -
the land of the free and the home of the brave
Main menu
Home
Latest visitors
About

Projects
AlfMark
Alfresco SQLServer

Tools
Crypto tools
Pastebin
new


Swamp
Links
ush.it
aghers.org
saidone@ush
gameknot
virtualmagister

Misc
Unless otherwise specified, all contents of this site are licensed under a Creative Commons Attribution-ShareAlike 3.0 Italy License.
JBoss 4.2.3 killer service script - CentOS 6.x version - posted by saidone on Fri, 03 Feb 2012 10:37:09 GMT
Please refer to the previous post:

http://saidone.org/kugelmass/posts/jboss-killer-service-script

for the installation of the service, as nothing have changed in that process.
This new version now works well on CentOS 6.x (the previous one had erratic behaviours when trying to stop the service), and furthermore you can now set the "niceness" (i.e. the priority) of the process to give more or less CPU time to your applications (well, the priorities are indeed assigned automatically, but niceness influence that assignment). You only need to change the niceness value at line 26, keeping in mind that positive values means that your process will be "nicer" with others, so its priority lowered and will use less CPU.
#process priority
NICE=/bin/nice
NICENESS="0"
The niceness level can vary between -19 (the highest priority will be assigned by the scheduler, according with the stability of the system) and 20 (lowest priority). You can see the niceness and the priority of the processes simply with "top" or with a "ps -l".
Here's the complete source of the service script:
#!/bin/bash
# chkconfig: - 65 36
# description: Jboss Start|Restart|Stop Application Server
# pidfile: /var/run/jboss.pid

#
# JBoss Control Script
#

# Either modify this script for your requirements or just ensure that
# the following variables are set correctly before calling the script.
#define where jboss is - this is the directory containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/opt/jboss"}

#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
JBOSS_USER=${JBOSS_USER:-"root"}

#make sure java is in your path
JAVAPTH=${JAVAPTH:-"/usr/bin/java"}

#configuration to use, usually one of 'minimal', 'default', 'all'
JBOSS_CONF=${JBOSS_CONF:-"default"}

#process priority
NICE=/bin/nice
NICENESS="0"

#address for binding
JBOSS_HOST=0.0.0.0

#time (in seconds) to wait after first SIGTERM signal sent
TIMEOUT=20

#if JBOSS_HOST specified, use -b to bind jboss services to that address
JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

#define the script to use to start jboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF $JBOSS_BIND_ADDR"}

if [ "$JBOSS_USER" = "RUNASIS" ]; then
  SUBIT=""
else
  SUBIT="su - $JBOSS_USER -c "
fi

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then
  # ensure the file exists
  touch $JBOSS_CONSOLE
  if [ ! -z "$SUBIT" ]; then
    chown $JBOSS_USER $JBOSS_CONSOLE
  fi 
fi

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then
  echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"
  echo "WARNING: ignoring it and using /dev/null"
  JBOSS_CONSOLE="/dev/null"
fi

#define what will be done with the console log
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}

JBOSS_CMD_START="cd $JBOSS_HOME/bin; $NICE -n $NICENESS $JBOSSSH"

if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then
  export PATH=$PATH:$JAVAPTH
fi

if [ ! -d "$JBOSS_HOME" ]; then
  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME
  exit 1
fi

echo JBOSS_CMD_START = $JBOSS_CMD_START

function procrunning() {
   procid=0
   JBOSSSCRIPT=$(echo $JBOSSSH | awk '{print $1}')
   for procid in `/sbin/pidof -x "$JBOSSSCRIPT"`; do
       ps -fp $procid | grep "${JBOSSSH% *}" > /dev/null && pid=$procid
   done
}

stop() {
    pid=0
    procrunning
    if [ $pid = '0' ]; then
        echo -n -e "\nNo JBossas is currently running\n"
        exit 1
    fi

    RETVAL=1

    # If process is still running

    # First, try to kill it nicely
    for id in `ps --ppid $pid | awk '{print $1}' | grep -v "^PID$"`; do
       if [ -z "$SUBIT" ]; then
           kill -15 $id
       else
           $SUBIT "kill -15 $id"
       fi
    done

    sleep=0
    while [ $sleep -lt $TIMEOUT -a $RETVAL -eq 1 ]; do
        echo -n -e "\nwaiting for processes to stop";
        sleep 1 
        sleep=`expr $sleep + 3`
        pid=0
        procrunning
        if [ $pid == '0' ]; then
            RETVAL=0
        fi
    done

    # Still not dead... kill it
    count=0
    pid=0
    procrunning

    if [ $RETVAL != 0 ] ; then
        echo -e "\nTimeout: Shutdown command was sent, but process is still running with PID $id"
	RETVAL=1
	while [ $RETVAL -eq 1 ]; do
	    echo -e "\nSending signal SIGKILL to PID $id"
	    kill -9 $id
	    sleep 5
	    pid=0
            procrunning
            if [ $pid == '0' ]; then
                RETVAL=0
            fi
	done
	echo -e "\nProcess with PID $id killed"
    fi

    echo
    exit 0
}

case "$1" in
start)
    cd $JBOSS_HOME/bin
    if [ -z "$SUBIT" ]; then
        eval $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &
    else
        $SUBIT "$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &" 
    fi
    ;;
stop)
    stop
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"
esac
You can download the current version from here: JBoss control script




No comments yet.



Post a new comment

<-- comment title (well, not really mandatory)
<-- your name
<-- your e-mail
<-- multiply 93 by 13

back to home
[[[[[[[ served by kugelmass ]]]]]]]
I don't have a drinking problem except when I can't get a drink. - Tom Waits