部署可以自行停止吗? [英] Can a deployment stop itself?

查看:177
本文介绍了部署可以自行停止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在寻找一种以编程方式停止在wildfly上部署的方法。



背景:




  • 应用程序在启动阶段使用MBean执行一些运行状况检查。

  • 如果应用程序确定环境无效,因为缺少某些资源,则需要停止自己的部署。



它的方式:




  • 该应用程序以前在JBoss 4上运行,只是使用JMX停止整个app服务器调用shutdown命令。

  • 如果此命令失败,它只是终止了整个JVM使用System.exit(1)。



当前问题:




  • 通过JMX调用shutdown()对wildfly无效,因为整个服务器在尝试从已部署的应用程序中停止时会挂起。

  • System.exit( )也不会有效,因为必须以任何方式捕捉命令。



那么是否有人知道如何从部署中停止服务器或停止部署过程或取消部署应用程序?



<非常感谢!

解决方案

好的,我还没有设法取消部署应用程序,但我已经能够关机了发生错误时的服务器。这不是完美的,但是与旧版JBoss上的应用程序的行为相匹配,所以我认为它根本不是太糟糕。



我现在正在调用CLI像这样的接口

  try {
String jbossBinDir = System.getProperty(jboss.server.base.dir) .replace(standalone,bin);
Runtime.getRuntime()。exec(sh+ jbossBinDir +/ jboss-cli.sh -c command =:shutdown);
} catch(IOException e){
...
}

这对我们来说是可靠的。



在上面的评论中,我说执行返回错误代码,但这可能就是这种情况,因为我一定有错字在命令调用中。


I'm currently searching for a way to stop a deployment on wildfly programmatically.

Background:

  • The application does some health checks in its startup phase using an MBean.
  • If the app determines that the environment is not valid because some resources are missing, it needs to stop its own deployment.

The way it was:

  • The application was formerly running on JBoss 4 and simply stopped the whole app server calling the shutdown command using JMX.
  • In case this command failed, it simply terminated the whole JVM using System.exit(1).

Current problems:

  • Calling shutdown() via JMX does not work on wildfly since the whole server hangs when trying to stop it from within a deployed application.
  • System.exit() will also not work since wildly must be catching the command in any way.

So does anyone know how to stop the server from within the deployment or stop the deployment process or undeploy the app?

Thanks a lot!

解决方案

Ok, I did not yet manage to undeploy the app but I've been able to shutdown the server in case of an error. This is not perfect but matches the behavior of the app on the older version of JBoss, so I think it's not too bad at all.

I'm now calling the CLI interface like so

try {
  String jbossBinDir = System.getProperty("jboss.server.base.dir").replace("standalone", "bin");
  Runtime.getRuntime().exec("sh " + jbossBinDir + "/jboss-cli.sh -c command=:shutdown");
} catch(IOException e) {
  ...
}

This works reliable for us.

In my comment above I stated that the execution returns with an error code but this was probably the case because I must have had a typo in the command call.

这篇关于部署可以自行停止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆