Linux下配置JBoss自動啟動__Linux

來源:互聯網
上載者:User
Linux下配置JBoss自動啟動

(JBoss V4.0)

#為root使用者的命令提示字元 $為jboss使用者的命令提示字元<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Ø         安裝J2SDK到/usr/local/j2sdk<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />1.4.2,編輯/etc/profile

# /etc/profile

JAVA_HOME=/usr/local/j2sdk

PATH=$PATH:$JAVA_HOME/bin

CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar

 

export JAVA_HOME PATH CLASSPATH

Ø         安裝JBoss4.0到/usr/local/jboss4x,編輯/etc/profile

# /etc/profile

JBOSS_HOME=/usr/local/jboss4x

PATH=$PATH:$JBOSS_HOME/bin

 

export JBOSS _HOME PATH

Ø         複製JBoss4內建的開機檔案到/etc/init.d下

# cp $JBOSS_HOME/bin/jboss_init_redhat.sh  /etc/init.d/

Ø         設定啟動腳步

# ln –s /etc/init.d/jboss_init_redhat.sh /etc/rc3.d/K20jboss_init_redhat

# ln –s /etc/init.d/jboss_init_redhat.sh /etc/rc3.d/S80jboss_init_redhat

# ln –s /etc/init.d/jboss_init_redhat.sh /etc/rc5.d/K20jboss_init_redhat

# ln –s /etc/init.d/jboss_init_redhat.sh /etc/rc5.d/S80jboss_init_redhat

此時會在/etc/rc3.d和/etc/rc5.d下建立一個S80jboss_init_redhat.sh的串連檔案,然後分配執行許可權(為了簡單使用了777的許可權)

# chmod –f 777 /etc/init.d/jboss_init_redhat.sh

# chmod –f 777 /etc/rc3.d/S80jboss_init_redhat.sh

# chmod –Rf 777 $JBOSS_HOME

Ø         編輯/etc/init.d/jboss_init_redhat.sh檔案(註:紅色為修改部分)

# vi /etc/init.d/jboss_init_redhat.sh

#!/bin/sh

#

# JBoss Control Script

#

# chkconfig: 3 80 20

# description: JBoss EJB Container

#

# To use this script

# run it as root - it will switch to the specified user

# It loses all console output - use the log.

#

# Here is a little (and extremely primitive)

# startup/shutdown script for RedHat systems. It assumes

# that JBoss lives in /usr/local/jboss, it's run by user

# 'jboss' and JDK binaries are in /usr/local/jdk/bin. All

# this can be changed in the script itself.

# Bojan

#

# Either amend this script for your requirements

# or just ensure that the following variables are set correctly

# before calling the script

 

# [ #420297 ] JBoss startup/shutdown for RedHat

 

#define where jboss is - this is the directory containing directories log, bin, conf etc

JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss4x"}

 

#make java is on your path

JAVAPTH=${JAVAPTH:-"/usr/local/j2sdk1.4.2/bin"}

 

#define the classpath for the shutdown class

JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}

 

#define the script to use to start jboss

JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh -c all"}

 

if [ -n "$JBOSS_CONSOLE" -a ! -d "$JBOSS_CONSOLE" ]; then

  # ensure the file exists

  touch $JBOSS_CONSOLE

fi

 

if [ -n "$JBOSS_CONSOLE" -a ! -f "$JBOSS_CONSOLE" ]; then

  echo "WARNING: location for saving console log invalid: $JBOSS_CONSOLE"

  echo "WARNING: ignoring it and using /dev/null"

  JBOSS_CONSOLE="/dev/null"

fi

 

#define what will be done with the console log

JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}

 

#define the user under which jboss will run, or use RUNASIS to run as the current user

JBOSSUS=${JBOSSUS:-"jboss"}

 

CMD_START="cd $JBOSS_HOME/bin; $JBOSSSH"

CMD_STOP="java -classpath $JBOSSCP org.jboss.Shutdown --shutdown"

 

if [ "$JBOSSUS" = "RUNASIS" ]; then

  SUBIT=""

else

  SUBIT="su - $JBOSSUS -c "

fi

 

if [ -z "`echo $PATH | grep $JAVAPTH`" ]; then

  export PATH=$PATH:$JAVAPTH

fi

 

if [ ! -d "$JBOSS_HOME" ]; then

  echo JBOSS_HOME does not exist as a valid directory : $JBOSS_HOME

  exit 1

fi

 

echo CMD_START = $CMD_START

 

case "$1" in

start)

    cd $JBOSS_HOME/bin

    if [ -z "$SUBIT" ]; then

        eval $CMD_START >${JBOSS_CONSOLE} 2>&1 &

    else

        $SUBIT "$CMD_START >${JBOSS_CONSOLE} 2>&1 &"

    fi

    ;;

stop)

    if [ -z "$SUBIT" ]; then

        $CMD_STOP

    else

        $SUBIT "$CMD_STOP"

    fi

    ;;

restart)

    $0 stop

    $0 start

    ;;

*)

    echo "usage: $0 (start|stop|restart|help)"

esac

Ø         添加jboss使用者並分配組

# useradd jboss

# usermod -G jboss,root jboss

Ø         配置完成,重新啟動Linux伺服器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.