Configure JBoss service

From OpenKM Documentation
Revision as of 10:31, 24 June 2011 by Jllort (talk | contribs)

Jump to: navigation, search

These instructions are related to install and run JBoss 4.2.3 as a service, which means that will be launched at system boot and will closed properly on system shutdown.

Running as a Linux Service

For security reasons you shouldn't run JBoss as root. It is better to create an user named openkm and run JBoss from him:

$ sudo adduser openkm

Create a file with the script:

$ sudo vim /etc/init.d/jboss

# Provides:          jboss
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop JBoss AS
# Description:       Enable JBoss AS service provided by daemon.
start() {
    $ECHO -n "Starting JBoss"
    su - $JBOSS_USER -c "$JBOSS_START_SCRIPT -b $JBOSS_IP > /dev/null 2> /dev/null &"
    $ECHO "."
stop() {
    $ECHO -n "Stopping JBoss"
    su - $JBOSS_USER -c "$JBOSS_STOP_SCRIPT -s $JBOSS_IP > /dev/null &"
    while [ "$(ps -fu $JBOSS_USER | grep java | grep jboss | wc -l)" -gt "0" ]; do
        sleep 5; $ECHO -n "."
    $ECHO "."
case "$1" in
        sleep 30
        $ECHO "Usage: jboss {start|stop|restart}"
        exit 1
exit 0

And make it executable:

$ sudo chmod 755 /etc/init.d/jboss

Now update the run-levels:

$ sudo update-rc.d jboss defaults
 Adding system startup for /etc/init.d/jboss ...
   /etc/rc0.d/K20jboss -> ../init.d/jboss
   /etc/rc1.d/K20jboss -> ../init.d/jboss
   /etc/rc6.d/K20jboss -> ../init.d/jboss
   /etc/rc2.d/S20jboss -> ../init.d/jboss
   /etc/rc3.d/S20jboss -> ../init.d/jboss
   /etc/rc4.d/S20jboss -> ../init.d/jboss
   /etc/rc5.d/S20jboss -> ../init.d/jboss

start jboss service:

$ sudo service jboss start

stop jboss service:

$ sudo service jboss stop

Nota clasica.png If you are a Red Hat user use:
 $ chkconfig --add jboss
Take a look at update-rc.d like command on Redhat Enterprise / CentOS Linux.

Also is a good idea to configure JBoss memory utilization. Edit the file $JBOSS_HOME/bin/ and add a new parameter JAVA_OPTS where you can increase the system memory managed by the JVM (Java Virtual Machine):

DIRNAME=`dirname $0`
PROGNAME=`basename $0`
JAVA_OPTS="-Xmx1744m -XX:MaxPermSize=256m"

This example is for a system with 2 GB of RAM.

For more info, read

Configure on a Redhat / Centos

Copy the located into $JBOSS_HOME/bin to /etc/init.d/jboss

cp /etc/init.d/jboss 

Make jboss script executable

chmod +x /etc/init.d/jboss 

Add jboss script as service

chkconfig --add jboss

Change service level

chkconfig jboss --level 3 on

Modify default jboss script

# chkconfig: - 64 36
# description: Jboss Start|Restart|Stop Application Server
# pidfile: /var/run/


#define the user under which jboss will run, or use 'RUNASIS' to run as the current user
#make sure java is in your path
#configuration to use, usually one of 'minimal', 'default', 'all'
#if JBOSS_HOST specified, use -b to bind jboss services to that address

Running as a Windows Service

You can install JBoss as a service in Windows platform by several ways:

First method

JBoss recomended is using jboss native windows take a look here Must be downloaded jboss native in concordance with your architecture 32 bits or 64 bits ( jboss native ).

  • Uncompress files into your %JBOSS_HOME%
  • If you want you can edit the service name editing the file %JBOSS_HOME%\bin\service.bat
set SVCDISP=JBoss Application Server 5.0
set SVCDESC=JBoss Application Server 5.0.0 GA/Platform: Windows x86
  • Then you must go to your windows console into %JBOSS_HOME%\bin\ folder and execute
service.bat install
  • Now in your service control panel there's installed JBoss as a service. We tested it on several Windows and runs well.

Nota advertencia.png If you're executing service.bat on Windows Vista / Windows 7 maybe you obtain Access Denied error. The command shell works slightly differently in Vista. By default when you run cmd.exe, it does not give administrator rights. To get around it, create a shortcut to cmd.exe on desktop, open Properties, Compatibility tab and check box for Administrator rights. Or simply execute the shortcut as administrator ( popup menu with right click ). Then you can execute service.bat install.

Nota clasica.png Other windows service installation methods explained below we've not been tested directly by us.

Second method

  • Download from
  • Extract to C:\JavaService-2.0.10
  • copy InstallJBoss.bat,UninstallJBoss.bat, JavaService.exe (JavaService.exe must be renames as JBossService.exe ) to jboss bin directory. In our case C:\jboss-4.2.3.GA\
  • Make sure JBOSS_HOME and JAVA_HOME are set. In our case: C:\jboss-4.2.3.GA and D:\jdk1.6.0 respectively
  • Create a batch file install.bat in %JBOSS_HOME%/bin directory. Its contents should be as follows:
Rem Start Here

set JAVA_HOME=d:/jdk1.6.0
set javadll=%JAVA_HOME%\jre\bin\client\jvm.dll
set javatool=%JAVA_HOME%\lib\tools.jar
set javarun=%JBOSS_HOME%\bin\run.jar
set outlog=%JBOSS_HOME%\bin\stdout.log
set errlog=%JBOSS_HOME%\bin\stderr.log

JBossService.exe -install JBoss "%javadll%" -Djava.class.path="%javatool%";"%javarun%" -Xms1024M -Xmx1024M -XX:PermSize=64m -XX:MaxPermSize=128m -start org.jboss.Main -params -b -stop org.jboss.Main -method systemExit -out "%outlog%" -err "%errlog%" -current "%JBOSS_HOME%\bin" -manual

Rem End Here
  • Make sure to set word wrap off in the file and do not forget the quotes. This will allow the Program

Files path to work correctly. You can change the location of stderr.log and stdout.log to other path if you prefer.

  • Start a cmd window and cd to %JBOSS_HOME%\bin. run install.bat by typing install. This will install JBoss as a service.

To start the service type:

net start JBoss.
  • JBoss should now be running as a service.
  • To uninstall the JBoss service:
javaservice -uninstall jboss

Third method

Start a cmd window,To start the service type:

set JAVA_HOME=d:/jdk1.6.0
set JBOSS_HOME=C:/jboss-4.2.3.GA/
installJboss MSSQLSERVER -auto

MSSQLSERVER is a service that must be running before JBoss starts.

Fourth method

Is using Microsoft Resource KIT, you can get more information here:

Microsoft resource kit are several programs that covers specific functionalities, not present by default in Windows OS (really it could be a good question why it don't comes by default - other Microsoft policy? the question is that in these utilities are present service registration utility).