Set up Jboss 5.1 as a service

Run JBoss not as root

First off, you’ll need to add a user named jboss to your system. Do this so you wont have to run jboss as root. Running anything as root is usually dangerous and is usually never recommended. Its very easy to break stuff if you don’t know what you’re doing. To add jboss to the sudoers file, open it by doing the following:

[root@bedrock ~]# vi /etc/sudoers

Scroll down some then add this entry somewhere near where the root user is listed:

## Services
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
...
...
...
## Allow root to run any commands anywhere
root    ALL=(ALL) ALL
jboss   ALL = NOPASSWD: SERVICES

This essentially allows the jboss user to run any command listed as the SERVICE command alias (as shown above).

Make changes to the red had startup script “jboss_init_red_hat.sh” found in the jboss/bin directory.

You’ll want to edit some relevant variables like JBOSS_HOME and JBOSS_BIND to fit your actual setup. by default jboss will bind to 127.0.0.1 (localhost), if you’re setting up a server that you want to listen to every possible url, you want it to bind to 0.0.0.0, otherwise, bind it to the url you want:

-b some.domain.com
-b 0.0.0.0
-b 127.0.0.1

Lets start off with the red hat script and start making some changes:

[root@bedrock ~]# vi jboss_install_directory/bin/jboss_init_red_hat.sh

#define where jboss is - this is the directory
#containing directories log, bin, conf etc
JBOSS_HOME=${JBOSS_HOME:-"/server/jboss"}

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

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

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

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

I also made some changes so the server.log file is renamed with a time stamp so when jboss fires up its free to create a new server.log file:

case "$1" in
start)

    echo JBOSS_CMD_START = $JBOSS_CMD_START

    echo "moving old log file to server.log.$(date +%Y-%m-%d-%H%M%S)"
    mv "$JBOSS_LOG_DIR/server.log"
    	"$JBOSS_LOG_DIR/server.log.$(date +%Y-%m-%d-%H%M%S)"

    cd $JBOSS_HOME/bin

...

Once you’re done, you’ll probably want to set this up s a service daemon so it will always be running. add the chkconfig metadata at the top of jboss_init_red_hat.sh in comments

# chkconfig: - 64 36
# description: Starts and stops the jboss backend daemon that handles \
#              all database requests.
# processname: jboss

Then you’ll want to save the file as /etc/init.d/jboss and fix permissions and ownership. you’ll want it to be owned by root, and give it 0755 permissions to make it look like everyone else in that init.d folder. then run chckconfig to add it to the service list. The full script I’m using right now is linked at the end of this article.

[root@bedrock ~]# chkconfig -add jboss

run the jboss service.

[root@bedrock ~]# service jboss start

finally, make sure its listening off the right bind address.

[root@bedrock ~]# netstat -ntalp | grep java

...
tcp      0      0 0.0.0.0:8080        0.0.0.0:*       LISTEN      1894/java
...

JBoss will add other entries, not just this one but this particular line means some java proc (must be jboss) is bound to the 8080 port, which is means our jboss is up and running.

if you’ve set up the iptable firewall rules to listen in on port 8080, you should be good to go.

Resources:
The complete service script can be found here

 
    Twitter
  • del.icio.us
  • Reddit
  • Technorati
  • Google Bookmarks
  • Blogplay
  • Yahoo! Buzz
  • LinkedIn
  • Facebook
  • Digg

Related posts:

  1. Virtual hosting with Jboss 5.1
  2. Set up multiple IPs on a single NIC
  3. Set up postgres
Posted on January 2, 2010 at 3:27 pm by Ant · Permalink
In: Jboss · Tagged with: , ,

Leave a Reply