To make the Glassfish Server auto start with startup, we need to setting up an init script, which helps us to manage all Glassfish Server startup events easily. And also make Glassfish start up automatically whenever Ubuntu is rebooting.
This script file is glassfish to be created at /etc/init.d/. For managing all Glassfish Server startup events, it ships with the asadmin tool. Use this tool in the startup script as follows,
- Create or edit glassfish file
1sudo nano /etc/init.d/glassfish - Paste the following lines in the file
1234567891011121314151617181920212223242526#!/bin/sh#to prevent some possible problemsexport AS_JAVA=/usr/lib/jvm/jdk1.8.0GLASSFISHPATH=/home/glassfish/bincase "$1" instart)echo "starting glassfish from $GLASSFISHPATH"sudo -u glassfish $GLASSFISHPATH/asadmin start-domain domain1;;restart)$0 stop$0 start;;stop)echo "stopping glassfish from $GLASSFISHPATH"sudo -u glassfish $GLASSFISHPATH/asadmin stop-domain domain1;;*)echo $"usage: $0 {start|stop|restart}"exit 3;;esac:
Now, glassfish startup script is created. We need to add this file in startup to make Glassfish Server autostart during Ubuntu startup. Follow these steps,
- Make the startup script file executable
1sudo chmod a+x /etc/init.d/glassfish - Add this file to Ubuntu startup boot
1sudo update-rc.d glassfish defaults
That’s it. Now, restart Ubuntu and check if it really autostart the Glassfish Server.
You can also manage Glassfish Server startup events as follows,
- Start the server
1/etc/init.d/glassfish start - Stop the server
1/etc/init.d/glassfish stop - Restart the server
1/etc/init.d/glassfish restart