By harcey on Apr 03, 2009
Windows Service ExampleOnce Glassfish is installed, you can create a Windows Services using the following utility (it can also be created directly with sc.exe): As described here: How do I run GlassFish as a Windows service?, obtain the Glassfish utility to create a Windows Service. Download GlassfishSvc.jar This will allow you to create a Windows Service to start and stop Glassfish.
INSTALL Windows Service
> cd C:\\glassfish > java -jar glassfishsvc.jar -i -n "Glassfish OpenSSO Domain" -d "C:\\\\glassfish" -m opensso -a adminNow the Glassfish instance can be controlled as a Windows Service. There is one more step. When OpenSSO starts up it looks for a file in the users home directory that installed it (in the home directory, see the .openssocfg/AMConfig_machinename_glassfish_domains_domainname_applications_j2ee-modules_opensso_ file). This file is used to allow OpenSSO to find it's configuration directory in the file system. For more information on this configuration file, see: OpenSSO Install Doc This will not be found by default once the Windows service is created because the Glassfish service will not be running as the user who installed it.
Solution for Windows service for Glassfish with OpenSSO:For the OpenSSO glassfish instance, goto the Services and login as Administrator to ensure that the OpenSSO bootstrap file is found during startup. If this step is not done, when the service is started, Glassfish will not find the configuration directory, and the Configuration page will be displayed when you goto the /opensso URL. To resolve this issue, open the Windows Services, select the new Glassfish service created, right click and select properties. Select the Logon tab, select This account, enter the account and password of the user used when OpenSSO was configured (see example below).
> sc.exe create glassfish-dmgr binPath="C:\\glassfish\\lib\\appservService.exe \\"C:\\glassfish\\bin\\asadmin.bat start-domain domain1\\" \\"C:\\glassfish\\bin\\asadmin.bat stop-domain domain1\\"" start=manual DisplayName="Glassfish Deployment Manager"
UNINSTALL Windows ServiceIf you need to remove the Glassfish service, here is an example:
java -jar glassfishsvc.jar -u -n "Glassfish OpenSSO Domain"
If the uninstall does not work, another option is:
> sc delete "Glassfish OpenSSO Domain"
If you get an error, like:
[SC] DeleteService FAILED 1072: The specified service has been marked for deletion.
The next time machine is restarted, the service will be deleted.
Solaris Manifest ExampleFor reference Here is an example Solaris manifest for starting Glassfish I use (on both Solaris and OpenSolaris): Note: The following assumes Glassfishv2 is installed in /var/opt and the domain which is installed for OpenSSO is called opensso and is configured to use port80.
<?xml version='1.0'?> <!DOCTYPE service_bundle SYSTEM '/usr/share/lib/xml/dtd/service_bundle.dtd.1'> <service_bundle type='manifest' name='export'> <service name='opensso/glassfishv2/port80' type='service' version='0'> <create_default_instance enabled='false'/> <single_instance/> <dependency name='filesystem' grouping='require_all' restart_on='restart' type='service'> <service_fmri value='svc:/system/filesystem/local'/> </dependency> <exec_method name='start' type='method' exec='/var/opt/glassfish/bin/asadmin start-domain opensso' timeout_seconds='600'> <method_context/> </exec_method> <exec_method name='stop' type='method' exec='/var/opt/glassfish/bin/asadmin stop-domain opensso' timeout_seconds='300'> <method_context/> </exec_method> <stability value='Unstable'/> <template> <common_name> <loctext xml:lang='C'>glassfishv2port80</loctext> </common_name> </template> </service> </service_bundle>
The above xml example can be copied to a file (example glassfish-smf-port80.xml and The following commands can be used to manage the service on Solaris:
# svccfg validate glassfish-smf-port80.xml # svccfg import glassfish-smf-port80.xml # svcs port80 # svcadm enable -s port80 # svcadm disable -s port80