4 simple steps to run JBoss server on startup in Ubuntu

Follow these simple steps to configure and run JBoss AS 7 as a sevice in Ubuntu. I have verified this on Ubuntu 14.04. It should also work in other versions also. Follow the following configurations steps, you can directly copy the code and use it in your environment.

Step 1: 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

Step 2: 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. You should replace the variable SERVER_IP with your server's IP address in proper format x.x.x.x. This will run the JBoss as a service using the root user, you can change the commands accordingly to run as a different user.

### BEGIN INIT INFO  
# 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  
### END INIT INFO  
# chkconfig: 35 92 1  

#!/bin/sh  
### BEGIN INIT INFO  
# 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  
### END INIT INFO  
# chkconfig: 35 92 1  
  
JBOSS_HOME=/usr/local/share/jboss/
   
AS7_OPTS="$AS7_OPTS -Djboss.bind.address.management=SERVER_IP"
AS7_OPTS="$AS7_OPTS -Djboss.bind.address=SERVER_IP"

case "$1" in
    start)
        /bin/echo "Starting JBoss AS 7..."
        su - root -c "sudo ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS > /dev/null & "
    ;;
    stop)
        /bin/echo "Stopping JBoss AS 7..."
        su - root -c "${JBOSS_HOME}/bin/jboss-cli.sh --connect --controller=SERVER_IP:9999 command=:shutdown"
    ;;
    *)
        /bin/echo "Usage: /etc/init.d/jbossas7 {start|stop}"; exit 1;
    ;;
esac

exit 0

Step 3: Now 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).

Step 4: In order to test the service before restarting, run:

sudo service jbossas7 start
sudo service jbossas7 stop

 

Blog Category: 
Company

Credits



Comments (1)

  • anon

    test1

    Jul 16, 2015

Leave a comment

Tags

Comparative Analysis (1)    Competitive Exams (1)    Enterprise (1)    fresher (1)    full stack (1)    iOS (1)    Java (1)    JBoss (1)    LAMP (1)    Methods (1)   

Pages

About Us

Atulsia is primarily focused on building enterprise web and mobile applications. With innovative ideas and right set of skills, Atulsia's aim is to deliver products based on customers needs. From ideas to execution, we deliver.

Latest tweets