dev@glassfish.java.net

Running glassfish with upstart

From: <john.lister_at_kickstone.com>
Date: Tue, 7 Feb 2012 14:31:56 +0000 (GMT)

Hi, not sure if this is the best place to post. I noticed that one of
the things to do is get glassfish to run under upstart (the daemon
management system with most flavours of linux). I've managed to achieve
this but with a couple of hacks that maybe could be resolved in the
glassfish code.

The main problem with upstart is that it relies on the unix fork
operation which of course isn't possible in java, therefore you can't
simply use the asadmin start-domain command to bring up glassfish as
this spawns a separate process which upstart can't track.

To get around this, I simply call the main glassfish bootloader
directly passing all the params into it as would be generated by
asadmin, but this isn't very clean or future proof. It would be nice if
there was an option to start-domain that could spit out the command
used to start glassfish based on the config files and other settings
rather than manually generating it.

Secondly glassfish waits for what looks like a password or other
security token to be entered via the console followed by a carriage
return. Again I've hacked a method to get around this by simply echoing
the information + carriage return to the java command and wrapped this
all up in a shell script. This isn't ideal and slightly complicates
things. I couldn't find any way of disabling this wait for input while
going through the code - the only promising option (-read-stdin)
doesn't seem to do anything when set to false.

Any hints or suggestions about how this could be further improved?

The scripts are below:

Thanks

John


/etc/init/glassfish.conf
=============================
start on (local-filesystems and net-device-up IFACE=eth0)
stop on [!2345]
respawn
respawn limit 10 30
pre-stop exec /opt/glassfishv3/bin/asadmin stop-domain
exec /opt/glassfishv3/bin/startup.sh
post-start exec /opt/glassfishv3/bin/asadmin version
=============================

/opt/glassfishv3/bin/startup.sh
=================================
#!/bin/sh
echo -e \n | java -cp
/opt/glassfishv3/glassfish/modules/glassfish.jar........
=================================