在Linux上将JBoss 7作为服务启动 [英] Start JBoss 7 as a service on Linux
问题描述
JBoss的早期版本包含一个脚本(如jboss_init_redhat.sh
),可以将其复制到/etc/init.d以便将其添加为服务-因此它将在启动时启动.我似乎在JBoss 7中找不到任何类似的脚本.有没有人做过类似的事情?
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 start on boot up. I can't seem to find any similar scripts in JBoss 7. Has anyone already done something like this?
P.S. 我正在尝试在Ubuntu 10.04中实现这一目标
P.S. I'm trying to achieve this in Ubuntu 10.04
推荐答案
花了几个小时的侦探时间后,我最终创建了具有以下内容的/etc/init.d/jboss
After spending a couple of hours of snooping around I ended up creating /etc/init.d/jboss
with the following contents
#!/bin/sh
### 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
[ -r /etc/profile.d/java.sh ] && . /etc/profile.d/java.sh
[ -r /etc/profile.d/jboss.sh ] && . /etc/profile.d/jboss.sh
case "$1" in
start)
echo "Starting JBoss AS 7.0.0"
#original:
#sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh
#updated:
start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh
;;
stop)
echo "Stopping JBoss AS 7.0.0"
#original:
#sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown
#updated:
start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown
;;
*)
echo "Usage: /etc/init.d/jboss {start|stop}"
exit 1
;;
esac
exit 0
这是java.sh
的内容:
export JAVA_HOME=/usr/lib/jvm/java_current
export PATH=$JAVA_HOME/bin:$PATH
和jboss.sh
:
export JBOSS_HOME=/opt/jboss/as/jboss_current
export PATH=$JBOSS_HOME/bin:$PATH
很显然,您需要确保将JAVA_HOME和JBOSS_HOME设置为适合您的环境.
Obviously, you need to make sure, you set JAVA_HOME and JBOSS_HOME appropriate to your environment.
然后我运行sudo update-rc.d jboss defaults
,以便JBoss在系统启动时自动启动
then I ran sudo update-rc.d jboss defaults
so that JBoss automatically starts on system boot
我发现本文有助于创建上述启动脚本.同样,以上脚本适用于Ubuntu(在我的情况下为10.04版),因此在Fedora/RedHat或CentOS中使用它可能无法正常工作(注释中的设置与此不同).
I found this article to be helpful in creating the start-up script above. Again, the script above is for Ubuntu (version 10.04 in my case), so using it in Fedora/RedHat or CentOS will probably not work (the setup done in the comments is different for those).
这篇关于在Linux上将JBoss 7作为服务启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!