Showing posts with label Glassfish. Show all posts
Showing posts with label Glassfish. Show all posts

Tuesday, August 26, 2008

Setting up Glassfish to run as a service on Ubuntu

In order to do this a script needs be created and put into the /etc/init.d folder of the server. I copied this script from Cay Horstmann's Blog and made one or two changes. The main one being that I can spcify the domain to startup.

My script looks like this:

#!/bin/sh -e
### BEGIN INIT INFO
# Provides: glassfish
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: glassfish initscript
# Description: A simple initscript for the glassfish app server
### END INIT INFO
#
# Author: Cay S. Horstmann (http://horstmann.com)
#

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/glassfish/bin
DESC="Glassfish Java EE5 App Server"
NAME=glassfish
ASADMIN=asadmin
DOMAIN=dev
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

# Read config file if it is present.
#if [ -r /etc/default/$NAME ]
#then
# . /etc/default/$NAME
#fi

#
# Function that starts the daemon/service.
#
d_start() {
$ASADMIN start-domain $DOMAIN \
|| echo -n " already running"
}

#
# Function that stops the daemon/service.
#
d_stop() {
$ASADMIN stop-domain $DOMAIN \
|| echo -n " not running"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME [$DOMAIN]"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME [$DOMAIN]"
d_stop
echo "."
;;
reload|restart|force-reload)
echo -n "Restarting $DESC: $NAME [$DOMAIN]"
d_stop
sleep 10
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac

exit 0

You will need to decide on a service name (e.g. myglassfishservice) and then create a file with that name in the /etc/init.d folder.

cd /etc/init.d
sudo vi myglassfishservice


Paste the above script into the file. Check that the PATH variable points to the correct glassfish home folder and that the DOMAIN variable is the correct glassfish domain name. Then save the file.

Now setup the run groups by running the following command

sudo update-rc.d myglassfishservice defaults

This adds the symbolic links to your service in the folders /etc/rc0.d, /etc/rc1.d, ...

Now reboot the server and your specified domain on glassfish shold start

Installing Glassfish on Ubuntu

Following my article on setting up Glassfish on Solaris, I found the instructions for setting it up on Ubuntu at the Ubuntu forums. Here is the link Glassfish Server on Ubuntu Server

Monday, August 11, 2008

Tool Reference Cards

I came across this very useful website at DZone called refcardz that has a list of reference cards for a wide variety of technologies and tools. Some of these are AJAX, GlassFish, Netbeans, Groovy, Flex, Rails, Design Patterns, RSS, Atom, IntelliJ and even C#. I find reference cards useful, so if you do this site is worth a look.

Monday, July 21, 2008

Installing Glassfish onto Solaris 10

Check the correct version of java is running


* Open a terminal window
* Use bash
type: bash
* Get the version of java
type: java -version
* Check the version is java 1.6 or above

Upgrading java version


* ftp the install package of the JDK to /opt/dropzone
* Give the install execution access
type: chmod a+x jdk-6u10-beta-bin-b24-solaris-i586-14_may_2008.sh
* Install the JDK by running the install script
type: ./jdk-6u10-beta-bin-b24-solaris-i586-14_may_2008.sh
* Check that the installation work by doing a directory listing
type: ls -l
* Move the installation to /usr/jdk/instances
type: mv ./jdk1.6.0_10 /usr/jdk/instances
* Check that in moved successfully
type: ls -l /usr/jdk/instances
* Move the latest symbolic link to point to the new installation
type: rm /usr/jdk/latest; ln -s instances/jdk1.6.0_10 /usr/jdk/latest;
* Check that the latest symbolic link points to the new installation
type: ls -l /usr/jdk/latest
* Move the java symbolic link to point to the new installation
type: rm /usr/java; ln -s jdk/latest /usr/java;
* Check the new java version is being picked up
type: java -version

Copy the relevant deployment of Glassfish to the server


* ftp the install package of Glassfish to /opt/fundamo/dropzone
* Install Glassfish by running the install jar
type: java -Xmx256m -jar glassfish-installer-v2ur2-b04-sunos_x86.jar
* Check that the installation work by doing a directory listing
type: ls -l
* Move the installation to /opt
type: mv ./glassfish /opt
* Change directory to /opt/glassfish
type: cd /opt/glassfish
* Make the ant binaries executable
type: chmod -R +x lib/ant/bin
* Setup the installation for a non-clustered install
type: lib/ant/bin/ant -f setup.xml
o Clustered installations are not covered here, but you should run lib/ant/bin/ant -f setup-cluster.xml
* Move the symbolic link to asadmin to point to the new Glassfish installation
type: rm /usr/sbin/asadmin; ln -s /opt/glassfish/bin/asadmin /usr/sbin/asadmin;

Create the domain


* Go to the glassfish installation directory
type: cd /opt/glassfish
* Create the domain called mydomain that listens on port 80 for HTTP and port 443 for HTTPS. The admin port is port 4848
type: asadmin create-domain --adminport 4848 --domaindir ./domains --profile developer --instanceport 80 --domainproperties http.ssl.port=443 mydomain
* To start and stop the domain use
type: asadmin start-domain mydomain
type: asadmin stop-domain mydomain
* Test the server is running
type: http://<ip address of the server>
type: https://<ip address of the server>
* Configure you application via the administrator console
type: http://<ip address of the server>:4848

Set the domain to run as a service


* Go to the domains glassfish installation directory
type: cd /opt/glassfish/domains/mydomain
* Create a password file called .passwordfile that contain the following lines
AS_ADMIN_USER=<admin username>
AS_ADMIN_PASSWORD=<admin password>
AS_ADMIN_MASTERPASSWORD=changeit
* Create the service
type: asadmin create-service --passwordfile ./domains/mydomain/.passwordfile ./domains/mydomain
* Check the service was created
type: svcs -a | grep mydomain
o You should see output like this
disabled 16:24:09 svc:/application/SUNWappserver/mydomain:default
* Remove the AS_ADMIN_MASTERPASSWORD line from the password file by editing /opt/glassfish/domains/mydomain/.passwordfile (I don't know why, but the service does not start unless you do)
* Enable the service
type: svcadm enable svc:/application/SUNWappserver/mydomain:default
* Check that it is online
type: svcs -a | grep mydomain
o You should see output like this
online* 16:24:09 svc:/application/SUNWappserver/mydomain:default
o If not check the log at
/var/svc/log/application-SUNWappserver-mydomain:default.log