Hi, today I’m going to present a few simple steps to configure and run JBossAS 7 as a sevice.

This was tested with JBossAS 7 on Ubuntu 14.04, but it should work in other versions also.

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 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, 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.management="  
AS7_OPTS="$AS7_OPTS -Djboss.bind.address="  
case "$1" in  
        /bin/echo "Starting JBoss AS 7..."  
        su - root -c "sudo ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS > /dev/null & "  
        /bin/echo "Stopping JBoss AS 7..."  
        su - root -c "${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown"    
        /bin/echo "Usage: /etc/init.d/jbossas7 {start|stop}"; exit 1;  
exit 0  

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 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 start
sudo service jbossas7 stop