Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a deployment stop itself?

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!

like image 292
shillner Avatar asked Apr 24 '26 18:04

shillner


1 Answers

I assume the core question is stopping the deployment process if some health checks fail. Throwing a run-time exception during app startup is enough to do the job.

@Startup
@Singleton
public class StartupBean {


    @PostConstruct
    public void start() {
        //your checks
        boolean check = doHealthCheck();
        if(!check){
           throw new RuntimeException("Your error message");
        }

    }
}

or

@Startup
@Singleton
public class StartupBean {


    @PostConstruct
    public void start() {
        //your checks
        boolean check = doHealthCheck();
        if(!check){
           throw new Error("Your error message");
        }

    }
}
like image 70
Emmanuel Edwards Avatar answered Apr 26 '26 10:04

Emmanuel Edwards



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!