Run JBoss AS 7 as a service in Ubuntu
Posted: December 26, 2014 Filed under: JBoss | Tags: java, jboss, linux 2 CommentsHi, 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.
#!/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=/opt/jboss-as-7.1.1.Final/ AS7_OPTS="$AS7_OPTS -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true" AS7_OPTS="$AS7_OPTS -Djboss.bind.address.management=0.0.0.0" AS7_OPTS="$AS7_OPTS -Djboss.bind.address=0.0.0.0" 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 command=:shutdown" ;; *) /bin/echo "Usage: /etc/init.d/jbossas7 {start|stop}"; exit 1; ;; esac 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
Reblogged this on De Gaucho a Comecables.
LikeLike
Great job!!!!
But I needed to change some lines which give me some errors.
1- I’ve set the JBOSS_HOME path whithout the last “/”
JBOSS_HOME=/opt/jboss-as-7.1.1.Final
2- I’ve added a “sh” comand in the following lines….
su – root -c “sudo sh ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS > /dev/null & ”
su – root -c “sh ${JBOSS_HOME}/bin/jboss-cli.sh –connect command=:shutdown”
Hope this helps for someone else.
Thank you very much!!!
LikeLike