Quick post – when installing GlassFish 18.104.22.168 on Mac OS X (10.8.3 in my case) a GlassFish service won’t be created by the GlassFish installer (whereas Windows and Solaris platforms do get the ability to manage GlassFish as a service).
I came across a handy blog post by a former Sun Microsystems staffer which takes us most of the way there:
The original blog entry was pertaining to Mac OS 10.4 but applies to 10.8 with one exception (in my case). When attempting to load the service the GlassFish process would immediately be killed by launchd. This is alluded to in the blog comments above.
The solution can be found at https://discussions.apple.com/thread/1744853?start=0&tstart=0 and consists of adding the following entry to your GlassFish plist file:
My quick procedure for creating a GlassFish service based on the above information follows. Note that I am not covering the details of how services are created and managed for Mac OS, so this is basically to get up and running quickly.
1) Create a plist file
Simlar to Solaris SMF, the plist file is an XML service descriptor file. These are the contents of my file:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>com.sun.glassfish</string> <key>Disabled</key> <false/> <key>UserName</key> <string>davek</string> <key>GroupName</key> <string>staff</string> <key>ProgramArguments</key> <array> <string>/Users/davek/glassfish3/bin/asadmin</string> <string>start-domain</string> <string>domain1</string> </array> <key>RunAtLoad</key> <true/> <key>AbandonProcessGroup</key> <true/> </dict> </plist>
Replace the UserName and GroupName values with the user and group you wish to launch GlassFish as. Also, GlassFish in my case has been installed to /Users/davek/glassfish3 – alter this path in your plist file accordingly.
Save the file for example as GlassFish.plist and copy it to /Library/LaunchDaemons.
2) Set ownership on the GlassFish domain
We are running the GlassFish service as davek:staff so be sure to change ownership on the relevant GlassFish domain (domain1 in this example) to match.
3) Import the service
Run the following command:
sudo launchctl load /Library/LaunchDaemons/GlassFish.plist
The service starts automatically after importing, so you should be able to browse to the administrative interface for the domain. If you reboot the system, the domain should also start on boot automatically.