Komal Chheda
Komal Chheda

Reputation: 1

How do I automatically restart tomcat in linux

I have created a Spring Boot microservice and hosted inside a Tomcat on a Linux machine.

Everything is inside the container and the container is inside the IBM cloud private platform.

Now the microservice should be running continuously.

But suppose for any reasons the microservice got stop or tomcat got crashed.

Is there any way we could restart the Tomcat server or microservice automatically without manual intervention?

Upvotes: 0

Views: 685

Answers (1)

soumitra goswami
soumitra goswami

Reputation: 891

Why are you deploying a Spring boot app in your local tomcat? By default Springboot comes with embedded Tomcat server in it, so if you just build and run the jar, a tomcat will be started with the service itself.You can also , configure the server type(tomcat or jetty) and other server properties in the application.yml file. More details here - https://www.springboottutorial.com/spring-boot-with-embedded-servers-tomcat-jetty Coming to the second part, of the question,about how to make sure , that if one service crashes, a new instance should be started automatically, for this you might be needing to do some reading on container managers like dockerswarm or kubernetes, which support auto-scaling, and can take care of restarting services (pods) as and when required,they can even scale up, meaning increase the number of instances of a service if existing containers reach a resource usage threshold and then load balancing requests to that service through some discovery and registry client.I think this would be helpful to you - https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy

Upvotes: 1

Related Questions