Run JBoss AS 7 as a service in Ubuntu


Blog Development
24 December, 2014 0

Hi there, today, we’re going to present a few simple steps to configure and run JBossAS 7 as a service. In this case, we tested with JBossAS 7 on Ubuntu 14.04, but it should also work in other versions.

First of all, create a file in /etc/init.d/, which is the script for the service. This folder contains all the scripts that should run on the startup of a linux instance.

sudo nano /etc/init.d/jbossas7

After that, insert the following code, which defines the start and stop commands for the service. 

You should replace the variable JBOSS_HOME with your local jboss install folder. 

This will run the jboss as a service using the root user, and you can change the commands accordingly to run as a different user.

# Provides:          jbossas7 
# Required-Start:    $local_fs $remote_fs $network $syslog 
# Required-Stop:     $local_fs $remote_fs $network $syslog 
# Default-Start:     2 3 4 5 
# Default-Stop:      0 1 6 
# Short-Description: Start/Stop JBoss AS 7 
# chkconfig: 35 92 1 
AS7_OPTS="$AS7_OPTS -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true"  
AS7_OPTS="$AS7_OPTS -Djboss.bind.address=" 
case "$1" in 
/bin/echo "Starting JBoss AS 7..." 
su - root -c "sudo ${JBOSS_HOME}/bin/ $AS7_OPTS > /dev/null & " 
/bin/echo "Stopping JBoss AS 7..." 
su - root -c "${JBOSS_HOME}/bin/ --connect command=:shutdown"   
/bin/echo "Usage: /etc/init.d/jbossas7 {start|stop}"; exit 1; 

After this, the only thing remaining is to define when the service will start and shutdown.

Simply run the following two lines:

sudo chmod +x /etc/init.d/jbossas7
sudo update-rc.d jbossas7 defaults

The first line enables the execution of the created file. The second line creates the symbolic links in /etc/rcX using the options configured in the service script comments (Default-Start and Default-Stop).

In order to test the service before restarting, run:

sudo service jbossas7 startsudo service jbossas7 stop


Leave a Reply

Your email address will not be published. Required fields are marked *

Wednesday December 24, 2014 - 21:12 Blog, Development
Recent posts
Using Mockito to create Java Unit Test

Let’s start with the definition given by the official page. “Mockito is a mocking framework that tastes really good. It […]

Read More…

Continue reading
1 December, 2020
From idea to deploy

When the great idea and background just isn’t enough […]

Read More…

Continue reading
11 August, 2020
Reclaim your disk space from Xcode

Do you have problems with the space on your disk? You are in the right place! This post is for […]

Read More…

Continue reading
25 June, 2020
RoR – Get your exceptions notified via Slack

Have you ever wanted to be one step ahead, and be notified of any unwanted exception before your users have […]

Read More…

Continue reading
18 October, 2018