Create JBoss 4.0.5 as service on Ubuntu 16.04 version

JBoss is the open source, cross platform Java application server. If the application server can be set as a service then it is very easy to start and stop. On Ubuntu 16.04 the service can be very easily created under /etc/systemd/system directory: Usually once JBoss 4.0.5 in installed on a Ubuntu machine it should be installed under a separate user (i.e jboss). The bin directory of a completed JBoss application server look like following:

-rwxrwxr-x 1 jboss jboss  3535 Oct 23  2006 classpath.sh
-rw-rw-r-- 1 jboss jboss  1507 Oct 23  2006 index.html
-rwxrwxr-x 1 jboss jboss  8808 Oct 23  2006 jboss_init_hpux.sh
-rwxrwxr-x 1 jboss jboss  2741 Oct 23  2006 jboss_init_redhat.sh
-rwxrwxr-x 1 jboss jboss  3750 Oct 23  2006 jboss_init_suse.sh
-rw-rw-r-- 1 jboss jboss   850 Mar  7 12:07 polopoly-ds.xml
-rwxrwxr-x 1 jboss jboss   535 Oct 23  2006 probe.bat
-rwxrwxr-x 1 jboss jboss   918 Oct 23  2006 probe.sh
-rwxrwxr-x 1 jboss jboss  3459 Oct 23  2006 run.bat
-rwxrwxr-x 1 jboss jboss  1749 Nov 28 12:32 run.conf
-rwxrwxr-x 1 jboss jboss 38125 Oct 23  2006 run.jar
-rwxrwxr-x 1 jboss jboss  6316 Apr  9 09:52 run.sh
-rwxrwxr-x 1 jboss jboss  1809 Oct 23  2006 shutdown.bat
-rwxrwxr-x 1 jboss jboss 16981 Oct 23  2006 shutdown.jar
-rwxrwxr-x 1 jboss jboss  2052 Apr  9 09:53 shutdown.sh
-rwxrwxr-x 1 jboss jboss  2074 Oct 23  2006 twiddle.bat
-rwxrwxr-x 1 jboss jboss 47105 Oct 23  2006 twiddle.jar
-rwxrwxr-x 1 jboss jboss  2348 Oct 23  2006 twiddle.sh
-rwxrwxr-x 1 jboss jboss  2159 Sep 29  2006 wstools.bat
-rwxrwxr-x 1 jboss jboss  2900 Sep 29  2006 wstools.sh
 
From the above directory structure it is easy to say that if we want to start the JBoss we need to execute run.sh and if we want to stop JBoss we need to execute shutdown.sh. By using those to clues it will be very easy to create a service in Ubuntu 16.04. Go to /etc/systemd/system directory and create a file called: jboss.service. Now paste the following content in that file:

[Unit]
Description=Jboss Application Server
After=network.target

[Service]

Environment=JAVA_HOME=/opt/jdk/jdk1.8.0_151

ExecStart=/opt/server/jboss/jboss-4.0.5.GA/bin/run.sh
ExecStop=/opt/server/jboss/jboss-4.0.5.GA/bin/shutdown.sh

User=jboss
Group=jboss
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target 
 
In the above service we have specified JAVA_HOME as it is required. In Ubuntu 16.04 services need ExecStart and ExecStop scripts with the fully qualified path. It is also easy to limit the service execution within a user/group.

In this case we have used jboss as a user and group both. Every service has a type. The default type of a service called simple. This means if the service type is not specified then the 'simple' type will be used.

Type=simple 
In simple type mode systemd does not wait for the processes to finish starting up as it has no way of know when this has happened so continues executing and dependant services straight away.

To start the service we could type:  
sudo service jboss start

To stop the service we could type:
sudo service jboss stop

 

Comments