Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start JBoss 7 as a service on Linux

Previous versions of JBoss included a scripts (like jboss_init_redhat.sh) that could be copied to /etc/init.d in order to add it as a service - so it would start on boot up. I can't seem to find any similar scripts in JBoss 7. Has anyone already done something like this?

P.S. I'm trying to achieve this in Ubuntu 10.04

like image 571
Andrey Avatar asked Jul 30 '11 03:07

Andrey


People also ask

How do I start JBoss in standalone mode in Linux?

To start up a JBoss AS 7 managed domain you need to execute the $JBOSS_HOME/bin/domain.sh script, and to start up a standalone server use $JBOSS_HOME/bin/standalone.sh. This will start it up using the default configuration.

How do I turn off JBoss EAP 7?

To stop JBoss EAP by pressing CTRL+C: Navigate to the terminal where JBoss EAP is running. Press Ctrl+C to stop JBoss Enterprise Application Platform.


1 Answers

After spending a couple of hours of snooping around I ended up creating /etc/init.d/jboss with the following contents

#!/bin/sh ### BEGIN INIT INFO # Provides:          jboss # 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 v7.0.0 ### END INIT INFO # #source some script files in order to set and export environmental variables #as well as add the appropriate executables to $PATH [ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh [ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh  case "$1" in     start)         echo "Starting JBoss AS 7.0.0"         #original:         #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh          #updated:         start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh     ;;     stop)         echo "Stopping JBoss AS 7.0.0"         #original:         #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown          #updated:         start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown     ;;     *)         echo "Usage: /etc/init.d/jboss {start|stop}"         exit 1     ;; esac  exit 0 

Here's the content of java.sh:

export JAVA_HOME=/usr/lib/jvm/java_current export PATH=$JAVA_HOME/bin:$PATH 

And jboss.sh:

export JBOSS_HOME=/opt/jboss/as/jboss_current export PATH=$JBOSS_HOME/bin:$PATH 

Obviously, you need to make sure, you set JAVA_HOME and JBOSS_HOME appropriate to your environment.

then I ran sudo update-rc.d jboss defaults so that JBoss automatically starts on system boot

I found this article to be helpful in creating the start-up script above. Again, the script above is for Ubuntu (version 10.04 in my case), so using it in Fedora/RedHat or CentOS will probably not work (the setup done in the comments is different for those).

like image 186
Andrey Avatar answered Sep 29 '22 06:09

Andrey