Configuring JBoss 7 to run as *nix service

Usually you run jboss using $JBOSS_HOME/bin/, but if you want to run JBoss in background, or when you installing it to remote server you can run it as daemon(service).

$JBOSS_HOME is folder where your jboss is unpacked. JBoss 7 comes with prepared daemon script located in $JBOSS_HOME/bin/init.d. Here is how it look like by default. Two important things here is:

  1. set JAVA_HOME variable. This java will be used by JBoss.
  2. set JBOSS_CONF variable. This variable should point to a file where other variables will be set. This is optional variable, and you can set all variables in, but it would be easier to read and configure if you use JBOSS_CONF. Add this variables after 9-th line, where first comment block ended:


Sample of jboss-as.conf is also located in $JBOSS_HOME/bin/init.d. This is sample jboss-as.conf.

# General configuration for the init.d scripts,
# not necessarily for JBoss AS itself.

# The username who should own the process.
# JBOSS_USER=jboss-as

# The amount of time to wait for startup

# The amount of time to wait for shutdown

# Location to keep the console log
# JBOSS_CONSOLE_LOG=/var/log/jboss-as/console.log

Important variables that you should set in jboss-as.conf:

  1. JBOSS_HOME=/home/c0rp/servers/jboss
  3. JBOSS_CONSOLE_LOG="$JBOSS_HOME"/standalone/log/console.log
  4. JBOSS_CONFIG="$JBOSS_HOME"/standalone/configuration/standalone.xml
  5. JBOSS_USER=jboss_user

Now copy $JBOSS_HOME/bin/init.d/ to /etc/init.d/jboss, make it executable and add using chkconfig:

cp $JBOSS_HOME/bin/init.d/ /etc/init.d/jboss
chmod +x /etc/init.d/jboss
chkconfig --add jboss

Now you should be able to run:

service jboss start
service jboss stop