Installing GlassFish on Debian Etch or Ubuntu
I had to install GlassFish on an Debian Etch machine and here is how I did it (the purpose of these instructions is as a reminder to myself so I know what I did in case I have to do it again).
Install Java 5
First thing needed is Java 5. To be able to get Java 5 and other stuff, add contrib and non-free to each repository in /etc/apt/sources.list .
It should look something like this:
deb http://security.debian.org/ etch/updates main contrib non-free deb http://ftp.debian.org/debian etch main contrib non-free deb-src http://ftp.debian.org/debian etch main contrib non-free
Then simply run:
apt-get install sun-java5-jdk
Download GlassFish
Check the GlassFish website for the latest version and download it (URL may be different depending on version):
wget http://java.net/download/javaee5/v2ur2/promoted/Linux/glassfish-installer-v2ur2-b04-linux.jar
Install GlassFish
Install GlassFish by running:
java -jar -mx256M glassfish-installer-v2-b09.jar
For convenience it might be nice to move GlassFish to a version independent directory name and make symlink (will make future upgrades easier as well):
mv glassfish /opt/glassfish-v2ur2-b09
ln -s /opt/glassfish-v2ur2-b09 /opt/glassfish
Now setup GlassFish:
cd /opt/glassfish
/opt/glassfish/lib/ant/bin/ant -f setup.xml
If you get an permission error, make sure ANT is executable (note that this is just a standard ANT, if you already have ANT you may use that one instead):
chmod u+x /opt/glassfish/lib/ant/bin/ant
Start the application server by running:
/opt/glassfish/bin/asadmin start-domain
Verify that you may reach http://localhost:8080 and http://localhost:4848 (replace localhost if server is somewhere else).
Finally it might be a good idea to change the default admin password:
/opt/glassfish/bin/asadmin change-admin-password --user admin
Create init script
Based on the /etc/init.d/skeleton I created the following init-script:
#! /bin/sh
### BEGIN INIT INFO
# Provides: glassfish
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: glassfish initscript
# Description: Simple initscript for GlassFish App server
### END INIT INFO
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/opt/glassfish/bin
DESC="GlassFish Java EE5 App server"
NAME=glassfish
ASADMIN=asadmin
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
$ASADMIN start-domain \
|| return 1
}
#
# Function that stops the daemon/service
#
do_stop()
{
$ASADMIN stop-domain \
|| return 1
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
sleep 10
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
Save it as glassfish, then run:
cd /etc/init.d
update-rc.d glassfish defaults
Set executable permission on init script with chmod a+x glassfish .
That’s it!
These instructions are very much based on similar posts by Jasper Kalkers Installing Glassfish 2 on ubuntu 7.10 and Cay Horstmann Installing GlassFish and PostgreSQL on Ubuntu Server Edition.
Worked like a charm and saved me a lot of time. Thx for that.
bright, clear, 5 minutes to properly installation,
thanks,
only detail I need explanations on what for le “:” on line 89 of your script
thanks , it was very usefull
Thanks a lot it was very useful.
Thanks very usefull tutorial
Very useful tutorial, and I think that with the new release of glassfish server v3 prelude the installation shoul be a lot easier
Hi, thanks for your tutorial but I have an error :
/etc/init.d/glassfish: 87: ¦¦: not found
thx for the post! it’s was really helpfull
Hi there.
Nice tut. How do you run it as non-root user? If I start the server as non-root I can find a warning in the logs after an otherwise successful start. During domain creation for the non-root there is a “jks” permission error.
Any ideas?
Kind regards – Benjamin.
(i read the glassfish faq on this, but it was no use)
I have tweaked the above init file to add a “runas” user. This way you can create a user (i.e. glassfish) and have your glassfish instance running as that user.
You can find the modified file here: http://entwash.org/glassfish
I had the next problem (Solution at end):
glassfish@localhost:~$asadmin start-domain
Starting Domain domain1, please wait.
Default Log location is /opt/glassfish/domains/domain1/logs/server.log.
Redirecting output to /opt/glassfish/domains/domain1/logs/server.log
Timeout waiting for domain domain1 to go to starting state.
CLI156 Could not start the domain domain1.
Error detail:
java.rmi.server.ExportException: Listen failed on port: 0; nested exception is: java.net.SocketException: Invalid argument
..
Exception :
java.lang.RuntimeException: Admin Server Channel is not initialized
Information:
debian Squeeze AMD64 2.6.32
sun-java6-jdk 6.20-dlj-1
export JAVA_HOME=”/usr/lib/jvm/java-6-sun”
export PATH=”$PATH:/opt/glassfish/bin:/opt/glassfish/lib/ant/bin”
SOLUTION:
The problem was IPv4 and IPv6 Socket listeners, so an change the values:
Edit /etc/sysctl.d/bindv6only.conf
Change net.ipv6.bindv6only = 1 to net.ipv6.bindv6only = 0
Restart service
/etc/init.d/procps restart
Run: asadmin start-domain domain1
And VOILA!!
A found it here http://forums.debian.net/viewtopic.php?f=5&t=47502