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
Wednesday December 24, 2014 - 21:12 Blog, Development
Recent posts
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
Easy creation of a new Node + React project

Starting a new project is something everybody loves to do. However, some steps are always the same for every project. […]

Read More…

Continue reading
3 October, 2018
Learning SCRUM with LEGOS

In Kreitech, we know about Scrum, and we apply it in many of our projects, which gives us very positive […]

Read More…

Continue reading
19 September, 2018