Skip to content

Running Glassfish as a service on CentOS

Here is how you run glassfish as a service on CentOS:

  1. Create a user glassfish (you can call it anything you want) under which Glassfish will run.
    #useradd glassfish
  2. Install glassfish in /home/glassfish.
  3. Create the startup script /etc/init.d/glassifsh for glassfish.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    
    #!/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_HOME
     
    GLASSFISH_OWNER=glassfish;
    export GLASSFISH_OWNER
     
    start() {
            echo -n "Starting Glassfish: "
            echo "Starting Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            su $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin start-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            sleep 2
            echo "done"
    }
     
    stop() {
            echo -n "Stopping Glassfish: "
            echo "Stopping Glassfish at `date`" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            su $GLASSFISH_OWNER -c "$GLASSFISH_HOME/bin/asadmin stop-domain domain1" >> $GLASSFISH_HOME/domains/domain1/logs/startup.log
            echo "done"
    }
     
    # See how we were called.
    case "$1" in
            start)
                    start
                    ;;
            stop)
                    stop
                    ;;
            restart)
                    stop
                    start
                    ;;
            *)
                    echo $"Usage: glassfish {start|stop|restart}"
                    exit
    esac
  4. Install the service
    #chmod +x /etc/init.d/glassfish
    #chkconfig --add glassfish
    #chkconfig --level 3 glassfish on
  5. Start glassfish.
    #/etc/init.d/glassfish start

{ 5 } Comments

  1. Diego | April 22, 2009 at 8:51 pm | Permalink

    GREAT! Justo lo que estaba buscando

  2. JPill | September 11, 2009 at 10:59 am | Permalink

    Thanks for that post, the only one

  3. nairdaen | September 26, 2009 at 2:48 am | Permalink

    I think you’re missing a “-” in the line “#chkconfig -add glassfish” so that it is “#chkconfig –add glassfish”

  4. anand | October 30, 2009 at 4:01 pm | Permalink

    @nairdaen
    fixed

  5. Adam Vollrath | December 31, 2009 at 6:57 am | Permalink

    Thank you, I’ve modified this script for our own Glassfish installations.

Post a Comment

Your email is never published nor shared. Required fields are marked *