Jboss 7 setup on debian linux

This is a short step by step explanation of the setup of JBoss 7.0.2 on your Linux (e.g. debian). Nowadays there is still no official Debian package for JBoss 7 out there, so we have to do a couple of steps manually. 

1. download and prepare

Start by download  currently available version (7.0.2) of the JBoss 7.

#Web Profile version download.
wget http://download.jboss.org/jbossas/7.0/jboss-as-7.0.2.Final/jboss-as-web-7.0.2.Final.tar.gz  

Extracting files to the final location using tar.

tar zxvf jboss-as-web-7.0.2.Final.tar.gz -C /usr/local/  

Now your JBoss 7 is placed inside /usr/local/jboss-as-web-7.0.2.Final/. I dont't like that name. It's just cosmetics, but i prefer to rename the last part ot the path.

cd /usr/local/  
mv jboss-as-web-7.0.2.Final/ jboss-7.0.2  

Now important things. Some basic security and right management. I suppose  you don't want to start your JBoss with root rights.
Therefore we need to create new user and new group named  jboss. Make them owner of your JBoss stuff.

addgroup jboss  
useradd -g jboss jboss  
chown -R jboss:jboss /usr/local/jboss-7.0.2/  

Your jboss 7 is almost installed now.

2. Configuration and first test

Start your brand new  Jboss 7 server with:

sudo -u jboss sh /usr/local/jboss-7.0.2/bin/standalone.sh &  

Now it is testable on your local machine with http://localhost:8080.
But! maybe you trying to install that jboss on remote machine and want to access this installation remotely. I that case you need to enable remote interface of your JBoss. I assume we start by standalone configuration, so  you have to edit /usr/local/jboss-7.0.2/standalone/configuration/standalone.xml file. The easiest way is to  find `<interfaces> section and replace the address with <any-address/>

  <interface name="management">
  <interface name="public">

Beware with this configuration you expose also the management console to the public. The console is bounded to interface named="management" by default. In production environments you have to put more attention to this. but now you can access your jboss from anywhere.

3. Jboss as Service

Now we have a basic configured JBoss, but i want to maintain it as a service. Unfortunately Jboss archive has no predefined init.d scripts, so i have to to it on my own. But this is not a big problem, just straightforward following some Debian conventions and useful scripts.

Ok, let's create jboss maintenance script.

touch /etc/init.d/jboss  
chmod 755 /etc/init.d/jboss  

Ready! Now put following inside.

Provides: jboss  
Required-Start: $localfs $remotefs $network $syslog  
Required-Stop: $localfs $remotefs $network $syslog  
Default-Start: 2 3 4 5  
Default-Stop: 0 1 6  
Short-Description: Management of JBoss AS v7.x  
Defining JBOSS_HOME  

case "$1" in  
echo "Starting JBoss AS7..."  
sudo -u jboss sh ${JBOSSHOME}/bin/standalone.sh &  
;; stop) 
echo "Stopping JBoss AS7..."  
sudo -u jboss sh ${JBOSSHOME}/bin/jboss-admin.sh --connect command=:shutdown  
;; log) 
echo "Showing server.log..."  
tail -1000f ${JBOSS_HOME}/standalone/log/server.log  
;; *) echo "Usage: /etc/init.d/jboss {start|stop|log}" 
exit 1  
;; esac exit 0 

This file is ready to use. You can use it self for manual start and stop of your jboss, you also can follow the server.log by using "log" parameter.
But let's make it to the end, as an automatic starting service. It's easy with update-rc.d script:

update-rc.d jboss defaults  

Now your ready and your JBoss will be shutdown on machine shutdown and it should start on machine start-up.

Of course this is not the only way to start using JBoss 7. Your ideas are welcome!