title: Can a deployment stop itself?
body: <p>I'm currently searching for a way to stop a deployment on wildfly programmatically.</p>
  
  <p>Background:</p>
  
  <ul>
  <li>The application does some health checks in its startup phase using an MBean.</li>
  <li>If the app determines that the environment is not valid because some resources are missing, it needs to stop its own deployment.</li>
  </ul>
  
  <p>The way it was:</p>
  
  <ul>
  <li>The application was formerly running on JBoss 4 and simply stopped the whole app server calling the shutdown command using JMX.</li>
  <li>In case this command failed, it simply terminated the whole JVM using System.exit(1).</li>
  </ul>
  
  <p>Current problems:</p>
  
  <ul>
  <li>Calling shutdown() via JMX does not work on wildfly since the whole server hangs when trying to stop it from within a deployed application.</li>
  <li>System.exit() will also not work since wildly must be catching the command in any way.</li>
  </ul>
  
  <p>So does anyone know how to stop the server from within the deployment or stop the deployment process or undeploy the app?</p>
  
  <p>Thanks a lot!</p>