Sonntag, 13. November 2011

Run Glassfish V3 as a Service on Ubuntu

I have used the this article as a basis, and adopted it for my needs. I had the following requirements:

  • run as a standalone service
  • start on startup

For the blog, I used also root for the user. So start a new terminal and write:

sudo -s

We have to install a jdk

sudo apt-get install openjdk-7-jdk

or

sudo apt-get install openjdk-6-jdk

You can also search for other jdk packages

apt-cache search jdk

Install Glassfish

cd /opt
wget  http://download.java.net/glassfish/v3/release/glassfish-v3.zip
unzip glassfish-v3.zip
rm glassfish-v3.zip

Now glassfish is installed at /opt/glassfishv3! To start automatically at startup, we have to create the following file /etc/init.d/glassfish.

#!/bin/sh
#
# glassfish init script for Linux 
# Simplest possible case -- no password file, one default domain
# it would be simple to add such options

GLASSFISH_HOME=${GLASSFISH_HOME:-"/opt/glassfish3/glassfish"}

case "$1" in
start)
    $GLASSFISH_HOME/bin/asadmin start-domain
    $GLASSFISH_HOME/bin/asadmin start-database
    ;;
stop)
    $GLASSFISH_HOME/bin/asadmin stop-domain
    $GLASSFISH_HOME/bin/asadmin stop-database
    ;;
restart)
    $GLASSFISH_HOME/bin/asadmin restart-domain
    $GLASSFISH_HOME/bin/asadmin stop-database
    $GLASSFISH_HOME/bin/asadmin start-database
    ;;
\*)
    echo "usage: $0 (start|stop|restart|help)"
esac

This starts not only the glassfish server but also the integrated javadb.

To start, stop, restart Glassfish simply run these commands:

sudo /etc/init.d/glassfish start
sudo /etc/init.d/glassfish stop
sudo /etc/init.d/glassfish restart

But for a simpler test you can just reboot your system:

sudo reboot

Check http://localhost:8080 if it is running.

1 Kommentare: