Linux下配置JBoss自动启动
1.操作系统:openSUSE10.2
2. JBOSS 4.2.2.GA二. 实验步骤
CODE:#/etc/profile
JAVA_HOME=/usr/local/j2sdk
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar
export JAVA_HOME PATH CLASSPATHjboss安装目录:/usr/local/jboss
1. 添加jboss环境变量:
#vi /etc/profile
JBOSS_HOME=/usr/local/jboss #根据你所安装的jboss的目录
PATH=$PATH:$JBOSS_HOME/bin
export JBOSS _HOME PATH
2. 复制JBoss4自带的启动文件到/etc/init.d下:
# cp /usr/local/jboss/bin/jboss_init_redhat.sh /etc/init.d/jboss
3. 设置启动脚步
ln-s/etc/init.d/jboss/etc/rc3.d/K20jboss
ln-s/etc/init.d/jboss/etc/rc3.d/S80jboss
ln-s/etc/init.d/jboss/etc/rc5.d/K20jboss
ln -s /etc/init.d/jboss /etc/rc5.d/S80jboss此时会在/etc/rc3.d和/etc/rc5.d下创建一个S80jboss的连接文件. 4. 分配执行权限(为了简单使用了777的权限)
chmod -f 777 /etc/init.d/jboss
chmod -f 777 /etc/rc3.d/S80jboss
chmod -Rf 777 $JBOSS_HOME #根据你所安装的jboss的目录
5. 编辑/etc/init.d/jboss文件,修改如下:
#!/bin/sh
#
#JBossControlScript
#
#chkconfig:38020
#description:JBossEJBContainer
#
#Tousethisscript
#runitasroot-itwillswitchtothespecifieduser
#Itlosesallconsoleoutput-usethelog.
#
#Hereisalittle(andextremelyprimitive)
#startup/shutdownscriptforRedHatsystems.Itassumes
#thatJBosslivesin/usr/local/jboss,it'srunbyuser
#'jboss'andJDKbinariesarein/usr/local/jdk/bin.All
#thiscanbechangedinthescriptitself.
#Bojan
#
#Eitheramendthisscriptforyourrequirements
#orjustensurethatthefollowingvariablesaresetcorrectly
#beforecallingthescript
#[#420297]JBossstartup/shutdownforRedHat
#definewherejbossis-thisisthedirectorycontainingdirectorieslog,bin,confetc
JBOSS_HOME=${JBOSS_HOME:-"/usr/local/jboss4x"}
#makejavaisonyourpath
JAVAPTH=${JAVAPTH:-"/usr/local/j2sdk1.4.2/bin"}
#definetheclasspathfortheshutdownclass
JBOSSCP=${JBOSSCP:-"$JBOSS_HOME/bin/shutdown.jar:$JBOSS_HOME/client/jnet.jar"}
#definethescripttousetostartjboss
JBOSSSH=${JBOSSSH:-"$JBOSS_HOME/bin/run.sh-call"}
if[-n"$JBOSS_CONSOLE"-a!-d"$JBOSS_CONSOLE"];then
#ensurethefileexists
touch$JBOSS_CONSOLE
fi
if[-n"$JBOSS_CONSOLE"-a!-f"$JBOSS_CONSOLE"];then
echo"WARNING:locationforsavingconsoleloginvalid:$JBOSS_CONSOLE"
echo"WARNING:ignoringitandusing/dev/null"
JBOSS_CONSOLE="/dev/null"
fi
#definewhatwillbedonewiththeconsolelog
JBOSS_CONSOLE=${JBOSS_CONSOLE:-"/dev/null"}
#definetheuserunderwhichjbosswillrun,oruseRUNASIStorunasthecurrentuser
JBOSSUS=${JBOSSUS:-"jboss"}
CMD_START="cd$JBOSS_HOME/bin;$JBOSSSH"
CMD_STOP="java-classpath$JBOSSCPorg.jboss.Shutdown--shutdown"
if["$JBOSSUS"="RUNASIS"];then
SUBIT=""
else
SUBIT="su-$JBOSSUS-c"
fi
if[-z"`echo$PATH|grep$JAVAPTH`"];then
exportPATH=$PATH:$JAVAPTH
fi
if[!-d"$JBOSS_HOME"];then
echoJBOSS_HOMEdoesnotexistasavaliddirectory:$JBOSS_HOME
exit1
fi
echoCMD_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)
$0stop
$0start
;;
*)
echo"usage:$0(start|stop|restart|help)"
esac6. 添加jboss用户并分配组:
useraddjboss
usermod -G jboss,root jboss7.配置完成,重新启动Linux服务器