简体   繁体   English

Jboss 7.1.1 启动/停止脚本

[英]Jboss 7.1.1 start/stop script

Could someone tell how to start/stop the Jboss-7.1.1 server in MAC using Shell Script .有人可以告诉如何使用Shell Script在 MAC 中启动/停止 Jboss-7.1.1 服务器。

stop_viewer(){
echo "********* Stopping JBoss Server by killing the process **********";
ps | grep domain.sh | grep -v grep | awk '{print $1}' | xargs kill
ps | grep java | grep -v grep | awk '{print $1}' | xargs kill
ps -ef | grep superuser | grep java | grep -v grep | awk '{print $2}'| xargs kill
echo "********* Stopped JBoss Server by killing the process **********";

}

The above script is working fine in Jboss-7.0.2 to stop the server.上面的脚本在 Jboss-7.0.2 中运行良好,可以停止服务器。 But in Jboss-7.1.1, it doesn't stop the server.但是在 Jboss-7.1.1 中,它不会停止服务器。 Please someone help to solve this.请有人帮忙解决这个问题。

1) First you need to have JBoss downloaded. 1) 首先你需要下载 JBoss。 (I assume you already have valid Java version installed). (我假设您已经安装了有效的 Java 版本)。

2) Once it is downloaded, unzip the folder: 2) 下载后,解压文件夹:

 cd /Users/eugene/Downloads

 mkdir JBOSS-7

 cp /Users/eugene/Downloads/jboss-as-7.1.1.Final.zip /Users/eugene/Downloads/JBOSS-7

 cd /Users/eugene/Downloads/JBOSS-7

 unzip /Users/eugene/Downloads/jboss-as-7.1.1.Final.zip 

3) 3)

 cd Users/eugene/Downloads/JBOSS-7/jboss-as-7.1.1.Final/bin

 ./standalone.sh

If you want to stop it:如果你想阻止它:

 ctrl + c

of course your path may be different.当然你的路径可能不同。 If you want to run it in background, then just do:如果你想在后台运行它,那么只需执行以下操作:

 ./standalone.sh &

Stopping it :停止它:

 ps -ef | grep jboss

You will get an output close to this one:你会得到一个接近这个的输出:

 eugene@eugenes-MacBook-Pro ~/D/J/j/bin> ps -ef | grep jboss
 501  1471  1446   0  1:32AM ttys000    0:03.31 /usr/....

And then issue:然后发出:

 kill -9 1471

Finally with JBoss CLI you can execute:最后使用 JBoss CLI,您可以执行:

 ./jboss-cli.sh --connect ":shutdown"

EDIT编辑

The Script seems to do it's job, all you have to do is edit it a bit:脚本似乎完成了它的工作,您所要做的就是对其进行一些编辑:

 #!/bin/sh

 echo "********* Stopping JBoss Server by killing the process **********";
 ps -e | grep jboss | grep -v grep | awk '{print $1}' | xargs kill
 echo "********* Stopped JBoss Server by killing the process **********";

Notice that I removed a few lines and changed java with jboss请注意,我删除了几行并使用jboss更改了java

Put this in a file called stopJboss.sh把它放在一个名为 stopJboss.sh 的文件中

Then :然后 :

 sudo chmod +x stopJBoss.sh

Then invoke it when needed:然后在需要时调用它:

 ./stopJBoss.sh

This will work only if you have a single instance of JBoss running, for more you will need a different script.这仅在您运行单个 JBoss 实例时才有效,更多情况下您将需要不同的脚本。

PS I am not a guru in scripting but here is what this line does: PS我不是脚本专家,但这是这一行的作用:

 ps -e | grep jboss | grep -v grep | awk '{print $1}' | xargs kill

It is going to look for every process that contains the jboss keyword.它将查找包含jboss关键字的每个进程。 But it also going to output the grep command itself, thus you will get an output of two commands, but you need only the first one.但它也会输出 grep 命令本身,因此您将获得两个命令的输出,但您只需要第一个。

You could run ps -e |你可以运行 ps -e | grep jboss and see that the output contains two lines and not one. grep jboss 并看到输出包含两行而不是一行。

That is why you invoke grep -v grep - which means : in those two lines found grep for "grep" but invert the result, in this way you omit the second unneeded result.这就是为什么你调用 grep -v grep - 这意味着:在这两行中找到 grep 为“grep”但反转结果,这样你就省略了第二个不需要的结果。

Then awk '{print $1}' splits the string into tokens and takes the first one, which is the PID that you need and then you pass this PID to the kill command using the xargs command.然后 awk '{print $1}' 将字符串拆分为标记并获取第一个标记,即您需要的 PID,然后您使用 xargs 命令将此 PID 传递给 kill 命令。

To shutdown the server via command line通过命令行关闭服务器

sh ./bin/jboss-cli.sh --connect command=:shutdown 

assuming you are running on localhost and using the default native management port ie 9999假设您在本地主机上运行并使用默认的本机管理端口,即 9999

if not you need to specify the IP (jboss.bind.address) and the native management port(jboss.management.native.port) configured in standalone.xml如果不是你需要指定在standalone.xml中配置的IP(jboss.bind.address)和本地管理端口(jboss.management.native.port)

sh ./bin/jboss-cli.sh --connect controller=<IP>:<native-mgmt-port> command=:shutdown

This is how I do it:这就是我的做法:

ps -ef | grep jboss | grep -v grep | awk '{print $2}' | xargs kill -9

I have this in a bash file that i call killjboss and it works well with me.我在一个名为 killjboss 的 bash 文件中有这个,它对我很有效。

After dive on the Google, i managed to put this work:在 Google 上潜水后,我设法完成了这项工作:

#!/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.1.1
  ### 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/lib/jvm/java-7-oracle
  export PATH=$JAVA_HOME/bin:$PATH

  export JBOSS_HOME=/home/gaspar/jboss-as-7.1.1.Final
  export PATH=$JBOSS_HOME/bin:$PATH

  case "$1" in
  start)
  echo "Starting JBoss AS 7.1.1"
  #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.1.1"
  #original:
  #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown

  #updated:
  sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-cli.sh --connect command=:shutdown
  ;;
  *)
  echo "Usage: /etc/init.d/jboss {start|stop}"
  exit 1
  ;;
  esac

  exit 0

:) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM