Version 9

    See also: Start JBoss AS On Linux Boot - applies to JBoss AS 4, 5 and 6

     

     

    This assumes you have JBoss AS 7 unzipped under /sw/AS7 .

    The following operations are supposed to be done as the root user.

    (Any improvements welcome.)

     

    1) Create a script /etc/rc.d/init.d/jbossas7

     

    Use $JBOSS_HOME/bin/init.d/jboss-as-standalone.sh (recommended).

     

    cp $JBOSS_HOME/bin/init.d/jboss-as-standalone.sh /etc/rc.d/init.d/jbossas7
    

     

    Or, if you're into something simpler, you can use this script:

     

    #!/bin/bash
    ### BEGIN INIT INFO
    # Provides:          jbossas7
    # Required-Start:    $local_fs $remote_fs $network $syslog
    # Required-Stop:     $local_fs $remote_fs $network $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start/Stop JBoss AS 7
    ### END INIT INFO
    # chkconfig: 35 92 1
    
    ## Include some script files in order to set and export environmental variables
    ## as well as add the appropriate executables to $PATH.
    [ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
    [ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh
    
    JBOSS_HOME=/sw/AS7
    
    AS7_OPTS="$AS7_OPTS -Dorg.apache.tomcat.util.http.ServerCookie.ALLOW_HTTP_SEPARATORS_IN_V0=true"   ## See AS7-1625
    AS7_OPTS="$AS7_OPTS -Djboss.bind.address.management=0.0.0.0"
    AS7_OPTS="$AS7_OPTS -Djboss.bind.address=0.0.0.0"
    
    case "$1" in
        start)
            echo "Starting JBoss AS 7..."
            #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS           ##  If running as user "jboss"
            #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh -- $AS7_OPTS   ## Ubuntu
            ${JBOSS_HOME}/bin/standalone.sh $AS7_OPTS &
        ;;
        stop)
            echo "Stopping JBoss AS 7..."
            #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown            ##  If running as user "jboss"
            #start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown     ## Ubuntu
            ${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown
        ;;
        *)
            echo "Usage: /etc/init.d/jbossas7 {start|stop}"; exit 1;
        ;;
    esac
    
    exit 0
    

     

    There are 3 variants of start/stop comand under "echo "Starting JBoss AS 7..."

    • If you want to run JBoss AS 7 under different user, use the first line.
    • On Ubuntu, use the second line.
    • If you are okay with running it under root, use the script as is.

     

    Then make the script executable:
    chmod +x /etc/rc.d/init.d/jbossas7
    

     

    2) Create links to it from respective runlevel dirs:

    chkconfig --add jbossas7
    

     

    ...or the same, but manually:

     

    ## Start when entering to multi-user mode.
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc3.d/S84jbossas7
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc5.d/S84jbossas7
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc4.d/S84jbossas7
    
    ## Kill on shutdown or when switching to single-user mode.
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc6.d/K15jbossas7
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc0.d/K15jbossas7
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc1.d/K15jbossas7
    ln -s /etc/rc.d/init.d/jbossas7 /etc/rc2.d/K15jbossas7
    

     

    For further info, see Wikipedia on Init or Red Hat docs on SysV.

    3) Test

    Try:

    service jbossas7 start
    service jbossas7 stop
    

    You should see the server startup and shutdown log messages.