在Linux上启动JBoss 7作为服务(Start JBoss 7 as a service on Linux)
以前的JBoss版本包含一个脚本(如jboss_init_redhat.sh ),可以将它复制到/etc/init.d中,以便将其作为服务添加 - 因此它将在启动时启动。 我似乎无法在JBoss 7中找到任何类似的脚本。有没有人已经做过类似的事情?
PS我试图在Ubuntu 10.04中实现这一点
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. I'm trying to achieve this in Ubuntu 10.04
原文:https://stackoverflow.com/questions/6880902
更新时间:2019-10-27 17:33
最满意答案
花了几个小时的探听后,我最终创建了具有以下内容的/etc/init.d/jboss
#!/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。
然后我运行sudo update-rc.d jboss defaults以便JBoss在系统启动时自动启动
我发现这篇文章有助于创建上面的启动脚本。 同样,上面的脚本适用于Ubuntu(在我的情况下为10.04版本),因此在Fedora / RedHat或CentOS中使用它可能不起作用(注释中完成的设置与此不同)。
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
Here's the content of java.sh:
export JAVA_HOME=/usr/lib/jvm/java_current
export PATH=$JAVA_HOME/bin:$PATH
And jboss.sh:
export JBOSS_HOME=/opt/jboss/as/jboss_current
export PATH=$JBOSS_HOME/bin:$PATH
Obviously, you need to make sure, you set JAVA_HOME and JBOSS_HOME appropriate to your environment.
then I ran sudo update-rc.d jboss defaults so that JBoss automatically starts on system boot
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).
2012-02-22
相关问答
花了几个小时的探听后,我最终创建了具有以下内容的/etc/init.d/jboss #!/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
# Def
...
问题解决了 我找到了解决我的问题的方法。 我重写了方法start(),stop(),destroy()和create(); 不过,由于我扩展了抽象类ServiceMBeanSupport,因此我应该重写startService(),stopService()等方法。 我只是将我的代码从start()方法移动到startService()方法,现在一切都按照我的需要运行:一旦它的依赖关系满足,我的服务就会启动并执行startService()方法。 我认为结论是:虽然MBean的生命周期涉及调用cr
...
你想要一个简单的 pkill java
从手册页: pkill会将指定的信号(默认为SIGTERM)发送给每个进程 SIGTERM将向该过程发送终止信号。 如果过程写得很好,它将捕获此信号并执行有序关闭。 如果失败,那就是当你可以使用SIGKILL (-9)时,这是一个强制终止,进程没有机会捕获并执行清理。 You want a simple pkill java
From the man page: pkill will send the specified signal (by defau
...
如果静态块无法正常工作,则可以通过调用web.xml中引用第二个服务实例的侦听器类来初始化第二个服务。
Initializes the Second Service
Second Service Loader
my.package.path.SecondServiceListener
...
使用以下standalone.xml ,这将解决您的问题。