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 sudo nano /etc/init.d/glassfish
- Paste the following lines in the file #!/bin/sh #to prevent some possible problems export AS_JAVA=/usr/lib/jvm/jdk1.8.0 GLASSFISHPATH=/home/glassfish/bin case “$1” in start) 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 sudo chmod a+x /etc/init.d/glassfish
- Add this file to Ubuntu startup boot sudo 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 /etc/init.d/glassfish start
- Stop the server /etc/init.d/glassfish stop
- Restart the server /etc/init.d/glassfish restart