简体   繁体   中英

How to schedule nightly restart of application server in Elastic Beanstalk

I have a Java web application running on Tomcat 8.5 in AWS Elastic Beanstalk. Everyday (judging from the localhost.log, around midnight Pacific Time), AWS does something to cause a java.lang.NoClassDefFoundError: Could not initialize <my.app.MyServlet$InnerClass> . I would then need to restart the app server in the Elastic Beanstalk environment to fix the problem. How do I schedule a daily automatic restart of the Tomcat server? Or better yet: Is there a way to detect the error and then automatically restart Tomcat? Why is this happening?

The easiest way to do this is to use the AWS SDK combined with your own scheduling system. Every day, this Java code runs in the middle of the night. Make sure you have the credential provider chain ( https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html ) set properly. System properties works pretty well.

Region usEast1 = Region.getRegion(Regions.US_EAST_1);
    AWSElasticBeanstalk client = AWSElasticBeanstalkClientBuilder.standard().withRegion(Regions.US_EAST_1).build();

    RestartAppServerRequest request = new RestartAppServerRequest().withEnvironmentId(ENVIRONMENT_ID);
    RestartAppServerResult response = client.restartAppServer(request);
            

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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