Here is how you run glassfish as a service on CentOS:
- Create a user glassfish (you can call it anything you want) under which Glassfish will run.
#useradd glassfish
- Install glassfish in /home/glassfish.
- Create the startup script /etc/init.d/glassfish for glassfish.
#!/bin/bash## glassfish: Startup script for Glassfish Application Server.## chkconfig: 3 80 05# description: Startup script for domain1 of Glassfish Application Server.GLASSFISH_HOME=/home/glassfish/glassfish;export GLASSFISH_HOMEGLASSFISH_OWNER=glassfish;export GLASSFISH_OWNERstart() {echo -n "Starting Glassfish: "echo "Starting Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.logsu $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.logsleep 2echo "done"}stop() {echo -n "Stopping Glassfish: "echo "Stopping Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.logsu $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.logecho "done"}# See how we were called.case "$1" instart)start;;stop)stop;;restart)stopstart;;*)echo $"Usage: glassfish {start|stop|restart}"exitesac - Install the service
#chmod +x /etc/init.d/glassfish #chkconfig --add glassfish #chkconfig --level 3 glassfish on
- Start glassfish.
#/etc/init.d/glassfish start
I think you’re missing a “-” in the line “#chkconfig -add glassfish” so that it is “#chkconfig –add glassfish”
@nairdaen
fixed
Thank you, I’ve modified this script for our own Glassfish installations.
Awesome! Thanks for the knowledge.
Hi, thank you for this script…
when i enter #/etc/init.d/glassfish start, system tell me:
CLI304 Can’t find domain.xml. It should be here: /usr/glassfishv3/glassfish/domains/domain1/config/domain.xml
Command start-domain failed.
If i call #asadmin start-domain domain1 from super user, glassfish run correctly
Can you help me?
@Maurizio
There might be a permission problem with domain.xml file. Try chmod.
Great help this script. Used it as a base. There is a little typo in the location of the startup.log it should be $GLASSFISH_HOME/glassfish/domains/domain1/logs/startup.log
a great tutorial, thank you very much.
muchas Gracias por el Post , Excelente.
Thank you Anand! This is a very useful post.
Ther is no domain.xml file at /usr/glassfishv3/glassfish/domains/domain1/config/
No permission problem, the file is not there !!!
Any sugestions ?
Thanks
Albert
I’m sorry !!!
The file was there…
It was actualy a permission problem.
Thanks and sorry again.
Albert