Version 1

    Nowadays, we mainly, administrators environments, we have certain needs standardize our environments for easy understanding, knowing where things are, etc..

    One way to keep the "house in order" is to organize the applications by services. In this post I will show how to use JBoss 7.1.1 as a service.

     

    Environment Used:

    • CentOS release 5.7 (Final) 64 bits
    • JDK 1.7_11 64 bits – HotSpot

     

     

    First it is necessary to check if the "start-stop-daemon" is installed:

    # type start-stop-daemon
    start-stop-daemon is hashed (/usr/bin/start-stop-daemon)

     

    If so, skip the next step:

    Installing the start-stop-daemon

     

     

     

    • Unzip it in some directory and follow the steps for installation

     

      • tar -xzvf apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz
      • cd apps
      • cd sys-utils/start-stop-daemon-IR1_9_18-2/
      • cc start-stop-daemon.c -o start-stop-daemon
      • cp start-stop-daemon /usr/bin/

     

     

    • Verify that the package was installed:

     

      • start-stop-daemon --help

     

    Creating default user to run the jboss


    As we know, it is strictly not recommended to run any application server with root user. This avoids many problems. For this we will create the user to run the jboss server.

    • useradd jboss

     

    After that, change the owner of the directory on jboss is installed:

     

    • chown -R jboss. /jboss

     

    Creating the start/stop Script

     

    Inside of /etc/init.d create the following file:

     

    • vim /etc/init.d/jboss-as-7

     

     

    Paste the code bellow:

     

    ### BEGIN INIT INFO
    # Provides:          jboss
    # 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 v7.0.0
    ### END INIT INFO
    #
    #source some script files in order to set and export environmental variables
    #as well as add the appropriate executables to $PATH
    export JAVA_HOME=/usr/java/jdk1.7.0_11
    export PATH=$JAVA_HOME/bin:$PATH
    export JBOSS_HOME=/jboss/jboss-as-7.1.1.Final
    export PATH=$JBOSS_HOME/bin:$PATH

    JBOSS_HOST=”10.11.133.7″

    case “$1″ in
    start)
    echo “Starting JBoss AS 7.1.1 Brontes”


    start-stop-daemon –start –quiet –background –chuid jboss –exec ${JBOSS_HOME}/bin/standalone.sh — -b $JBOSS_HOST
    ;;
    stop)
    echo “Stopping JBoss AS 7.1.1 Brontes”


    start-stop-daemon –start –quiet –background –chuid jboss –exec ${JBOSS_HOME}/bin/jboss-cli.sh — –connect command=:shutdown
    ;;
    *)
    echo “Usage: /etc/init.d/jboss {start|stop}”
    exit 1
    ;;
    esac

     

     

    After that, we should give execute permissions to the script:

     

    • chmod +x /etc/init.d/jboss-as-7

     

    And now, we can runs the Jboss-as as a script:

     

     

    service jboss-as-7 start/stop

     

     

    Regrads!