Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am using JBoss 5.1.0 GA on Red Hat (Amazon ECS)...

Am trying to set it up so JBoss will run as a service / daemon (right now it only starts up when I manually SSH and invoke sh $JBOSS_HOME/bin/run.sh).

Here's what I did so far:

(1) Created the following jboss script in /etc/init.d/:

JBOSS_HOME=${JBOSS_HOME:-"/usr/jboss-5.1.0.GA"}

JBOSS_USER=${JBOSS_USER:-"jboss"}

JAVAPTH=${JAVAPTH:-"/usr/java/jdk/bin"}

JBOSS_CONF=${JBOSS_CONF:-"default"}

JBOSS_BIND_ADDR=${JBOSS_HOST:+"-b $JBOSS_HOST"}

JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

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

JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}

JBOSS_CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"
JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"}

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

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)
    if [ -z "$SUBIT" ]; then
        $JBOSS_CMD_STOP
    else
        $SUBIT "$JBOSS_CMD_STOP"
    fi 
    ;;
restart)
    $0 stop
    $0 start
    ;;
*)
    echo "usage: $0 (start|stop|restart|help)"
esac

(2) Made script executable and changed ownership by doing the following:

sudo chown root:root /etc/init.d/jboss
sudo chmod ug+x /etc/init.d/jboss

(3) When I tried to start it, I received the following output (and JBoss didn't start):

JBOSS_CMD_START = cd /usr/jboss-5.1.0.GA/bin; /usr/jboss-5.1.0.GA/bin/run.sh -c default

Questions:

(1) What am I possibly doing wrong?

(2) How do I set it up so it runs as root user? Do I have to add a JBoss group and a JBoss user?

I can manually run JBoss through $JBOSS_HOME/bin but would love to have it running all the time...

Any help is greatly appreciated...

share|improve this question

migrated from stackoverflow.com Jul 28 '09 at 8:43

This question came from our site for professional and enthusiast programmers.

    
socal, this is your second post here. Server administration related questions belong on serverfault. stackoverflow is for programming questions only –  hobodave Jul 28 '09 at 8:42

6 Answers 6

Any particular reason that you have an aversion to using the bin/jboss_init_redhat.sh SysV init script that comes already with the JBoss 5.1.0.GA release? I use it on several RHEL and CentOS systems and have absolutely no problem with JBoss starting up on reboot.

I only had to do a minor change to get it to handle chkconfig without any problems. This change consisted of the following near the top of the script:

--- bin/jboss_init_redhat.sh    2009-05-22 11:01:22.000000000 -0400
+++ /etc/rc.d/init.d/jboss  2009-06-07 22:05:17.000000000 -0400
@@ -4,6 +4,10 @@
 #
 # JBoss Control Script
 #
+# chkconfig: - 85 15
+# description: JBoss Application Server
+# processname: jboss
+
 # To use this script run it as root - it will switch to the specified user
 #
 # Here is a little (and extremely primitive) startup/shutdown script

I then simply copied it to /etc/rc.d/init.d as jboss and ran chkconfig --add jboss. You can verify it's active with chkconfig --list jboss and see that it's set to on for the runlevels you want, usually 2-5 which it activates .

share|improve this answer

The provided init script is pretty terrible, and not very reliable.

I've created an alternative init script that should be more robust: https://jira.jboss.org/jira/browse/JBPAPP-3194

All feedback is welcome!

share|improve this answer

For some reason, Red Hat's JBoss 5.1 EAP distribution is missing bin/jboss_init_redhat.sh, although the HPUX and Solaris versions are there, which is a bit confusing for a Red Hat distribution

I thoroughly documented the procedures for setting the daemon up here... http://www.forwardslashbin.com/?p=108

share|improve this answer

Remove the eval from the start line. Also, set JBOSS_CONSOLE so it doesn't redirect all errors to /dev/null.

share|improve this answer

You will need to add a jboss user for it to run properly. According to the script as given above, it would be named "jboss"(without quotes).

[root@destination-host ~]# /usr/sbin/useradd jboss

The only way to get the script to run as the root user is to be the root user when starting it, or via sudo. I would strongly advise against running JBoss per se as root.

share|improve this answer

In doing and working around same requirement I have come to following very brief changes

#!/bin/sh

# chkconfig: 345 90 10
# description: Runs the JBoss Application Server 5
# processname: jboss # pidfile: /var/run/jboss_m2i.pid

1 - The above points are made are made for chkconfig utility for service.

# $Id: jboss_init_redhat.sh 81068 2008-11-14 15:14:35Z dimitris@jboss.org $ # JBoss Control Script # To use this script run it as root - it will switch to the specified user # Here is a little (and extremely primitive) startup/shutdown script # for RedHat systems. It assumes that JBoss lives in /usr/local/jboss, # it's run by user 'jboss' and JDK binaries are in /usr/local/jdk/bin. # All this can be changed in the script itself. # # 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 2 - Here you have to give your jboss server home location. JBOSS_HOME=${JBOSS_HOME:-"/home/jboss_user/servers/jboss/jboss-5.1.0.GA"}

3- point three of modification

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

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

4 - Point 4 where server profile is specified #configuration to use, usually one of 'minimal', 'default', 'all' , 'test' JBOSS_CONF=${JBOSS_CONF:-"test"}

5 - point 5 where binding address is specified. This point is very important if you assign it 0.0.0.0 the rmi / jndi exception will be raised.

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

6 - Point 6 variables which should be defined to shutdown the server. here 1299 depends on your port off-set change into your binding configuration $JBOSS_HOME/server/server_def_profile/conf/bindingservice.beans/META-INF/bindings-jboss-beans.xml 6.0 this can be checked by -- netstat command

# porta do JNDI service do JBoss (usada para shutdown) JBOSS_JNP_PORT=${JBOSS_JNP_PORT:-"1299"} JBOSS_ADMIN_USER=${JMX_USER:-"admin"} JBOSS_ADMIN_PWD=${JMX_PWD:-"admin"}

#define the classpath for the shutdown class JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

7 . Point 7 of modification. in running script. This different from standard distribution.

#define the script to use to start jboss JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF -b $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; $JBOSSSH"

8 - Point 8 , one of the major modification to shutdown the server using service command.

JBOSS_CMD_STOP=${JBOSS_CMD_STOP:-"java -classpath $JBOSSCP org.jboss.Shutdown --shutdown \ -s jnp://$JBOSS_BIND_ADDR:$JBOSS_JNP_PORT \ -u $JBOSS_ADMIN_USER -p $JBOSS_ADMIN_PWD"} 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

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) if [ -z "$SUBIT" ]; then $JBOSS_CMD_STOP else $SUBIT "$JBOSS_CMD_STOP" fi ;; restart) $0 stop $0 start ;; *) echo "usage: $0 (start|stop|restart|help)" esac

Use following command to add this script to chkconfig service and test

chkconfig --add jboss - to add

chkconfig --list jboss - to list

Use following command to run and stop the services.

service jboss start

service jboss stop

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.