How to auto start glassfish server

1. Create file name 'glassfish' and edit file
    sudo nano /etc/init.d/glassfish 
2. Write the lines below into the file and save it
#! /bin/sh

#to prevent some possible problems
export AS_JAVA=jdk path

GLASSFISHPATH= glashfish bin path

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
:
Example
#! /bin/sh

#to prevent some possible problems
export AS_JAVA=/home/sdsl/jdk1.7.0_07

GLASSFISHPATH=/home/sdsl/glassfish3/bin

case "$1" in
start)
echo "starting glassfish from $GLASSFISHPATH"
sudo $GLASSFISHPATH/asadmin start-domain domain1
;;
restart)
$0 stop
$0 start
;;
stop)
echo "stopping glassfish from $GLASSFISHPATH"
sudo $GLASSFISHPATH/asadmin stop-domain domain1
;;
*)
echo $"usage: $0 {start|stop|restart}"
exit 3
;;
esac
:
3. Make the init script file executable
sudo chmod a+x /etc/init.d/glassfish 
4. Configure Glassfish for autostart on ubuntu boot
sudo update-rc.d glassfish defaults 
6. Start, stop or restart Glassfish server
Start
service glassfish start 
Stop
service glassfish stop
Restart
service glassfish restart 

5 comments:

  1. thanks a lot i really appreciate that

    ReplyDelete
  2. why don't you have an export statement before your GLASSFISH environment variable?

    ReplyDelete
    Replies
    1. I guess it's a bit late for an answer to this question, but the variable is only needed for the script itself. In contrast, the AS_JAVA variable is needed by child processes as well.

      @Hiro: Thanks, still a very helpful post!

      Delete