We already support running GlassFish V3 as a service on Solaris 10 and Windows platforms (see my blog). I have been investigating how to provide support for automatically starting GlassFish V3 as a service on Linux. Of course before I can hope to do that — I must be able to set it up manually. In this blog I will take you through the manual steps needed to run GlassFish V3 as a service on Linux.
This procedure was worked out on my Linux system which happens to be Ubuntu. Other flavors of Linux may have slightly different procedures.
One decision you need to make right up front is what Linux user should “own” GlassFish V3. Typically root is used as the owner. If you choose root as the user you get the advantage that you can use ports < 1024 without complex configuration changes to the system. For this blog I used root.
Here are the steps — the file named “glassfish” in step 4 is the simple init script which appears at the end of this blog.
1. Install JDK 6 if needed
2 . Have root install GlassFish like so:
——- a. cd /opt
——- b. wget http://download.java.net/glassfish/v3/release/glassfish-v3.zip
——- c . unzip glassfish-v3.zip
——- d. rm glassfish-v3.zip
3. cd /etc/init.d
4. cp glassfish .
5. update-rc.d glassfish defaults
6. OPTIONAL /etc/init.d/glassfish start
7. OPTIONAL Make sure GlassFish is running OK
8. reboot — you are done!
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
# glassfish init script for Linux
# Simplest possible case — no password file, one default domain
# it would be simple to add such options
case “$1” in
$GLASSFISH_HOME/bin/asadmin start-domain >/dev/null
$GLASSFISH_HOME/bin/asadmin stop-domain >/dev/null
$GLASSFISH_HOME/bin/asadmin restart-domain >/dev/null
echo “usage: $0 (start|stop|restart|help)”