Start JBoss 7 as a service on Linux

后端 未结 12 1988
闹比i
闹比i 2020-12-12 11:54

Previous versions of JBoss included a scripts (like jboss_init_redhat.sh) that could be copied to /etc/init.d in order to add it as a service - so it would star

12条回答
  •  攒了一身酷
    2020-12-12 12:50

    Recently I wrote installer for JBoss AS 7 that downloads tar.gz file from RedHat's server, extract it, add jboss-as as service and makes some very basic configuration. With it I get ready for use JBoss AS 7 in several seconds.

    Installation script:

    #!/bin/bash
    #title           :jboss-install.sh
    #description     :The script to install JBoss AS 7.x
    #author          :Dmitriy Sukharev
    #date            :20130106
    #usage           :/bin/bash jboss-install.sh
    
    JBOSS_AS_FILENAME=jboss-as-7.1.1.Final
    JBOSS_AS_ARCHIVE_NAME=$JBOSS_AS_FILENAME.tar.gz 
    JBOSS_AS_DOWNLOAD_ADDRESS=http://download.jboss.org/jbossas/7.1/$JBOSS_AS_FILENAME/$JBOSS_AS_ARCHIVE_NAME
    
    INSTALL_DIR=/opt
    JBOSS_AS_FULL_DIR=$INSTALL_DIR/$JBOSS_AS_FILENAME
    JBOSS_AS_DIR=$INSTALL_DIR/jboss-as
    
    JBOSS_AS_USER="jboss-as"
    JBOSS_AS_SERVICE="jboss-as"
    
    JBOSS_AS_STARTUP_TIMEOUT=240
    
    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    
    echo "Cleaning up..."
    rm "$JBOSS_AS_ARCHIVE_NAME"
    rm "$JBOSS_AS_DIR"
    rm -r "$JBOSS_AS_FULL_DIR"
    rm -r "/var/run/$JBOSS_AS_SERVICE/"
    rm /etc/init.d/$JBOSS_AS_SERVICE
    
    echo "Installation..."
    wget $JBOSS_AS_DOWNLOAD_ADDRESS
    mkdir $JBOSS_AS_FULL_DIR
    tar -xzf $JBOSS_AS_ARCHIVE_NAME -C $INSTALL_DIR
    ln -s $JBOSS_AS_FULL_DIR/ $JBOSS_AS_DIR
    useradd -s /sbin/nologin $JBOSS_AS_USER
    chown -R $JBOSS_AS_USER:$JBOSS_AS_USER $JBOSS_AS_DIR
    chown -R $JBOSS_AS_USER:$JBOSS_AS_USER $JBOSS_AS_DIR/
    rm $JBOSS_AS_ARCHIVE_NAME
    
    echo "Registrating JBoss as service..."
    sed -e 's,${JBOSS_AS_USER},'$JBOSS_AS_USER',g; s,${JBOSS_AS_FILENAME},'$JBOSS_AS_FILENAME',g; s,${JBOSS_AS_SERVICE},'$JBOSS_AS_SERVICE',g; s,${JBOSS_AS_DIR},'$JBOSS_AS_DIR',g' $SCRIPT_DIR/jboss-as.template > /etc/init.d/$JBOSS_AS_SERVICE
    chmod 755 /etc/init.d/$JBOSS_AS_SERVICE
    
    echo "Configurating..."
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    sed -i -e 's,,,g' $JBOSS_AS_DIR/standalone/configuration/standalone.xml
    
    echo "Done."
    

    Init script:

    #!/bin/sh
    ### BEGIN INIT INFO
    # Provides:          ${JBOSS_AS_SERVICE}
    # 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_FILENAME}
    ### END INIT INFO
    
    JBOSS_USER=${JBOSS_AS_USER}
    JBOSS_DIR=${JBOSS_AS_DIR}
    
    case "$1" in
    start)
    echo "Starting ${JBOSS_AS_FILENAME}..."
    start-stop-daemon --start --background --chuid $JBOSS_USER --exec $JBOSS_DIR/bin/standalone.sh
    exit $?
    ;;
    stop)
    echo "Stopping ${JBOSS_AS_FILENAME}..."
    
    start-stop-daemon --start --quiet --background --chuid $JBOSS_USER --exec $JBOSS_DIR/bin/jboss-cli.sh -- --connect command=:shutdown
    exit $?
    ;;
    log)
    echo "Showing server.log..."
    tail -500f $JBOSS_DIR/standalone/log/server.log
    ;;
    *)
    echo "Usage: /etc/init.d/jboss-as {start|stop}"
    exit 1
    ;;
    esac
    exit 0
    

    I described the script steps in my blog post. It also has the link to download this script files as archive.

提交回复
热议问题