简体   繁体   中英

Spring Boot: Starting multiple services using shell script (.sh)

I like to write a shell script for a backend server using Spring Boot (v2.1.1) to start multiple microservices in a certain order - some services depend on other to be running.

What is the 'best practice'?

Of course i could run the .jar s like this ( original post ):

#!/bin/bash

java -jar myjar1.jar &
java -jar myjar2.jar &
java -jar myjar3.jar &

But this would start the .jar s simultaneously, afaik.

How can i ensure, that a certain service myjar1.jar started properly and after that, another service myjar2.jar is started. Because every service is a SpringBootApplication i assume that there are certain possibilities to do so?!

I read this SO solution but I don't want to create any symlinks, because i just need that for development purposes.

Well it is very specific to your service as to when it gets started. At process level, as soon as you execute the command service is running, so you will need your service to share the state when its up. One way i can think of is in your script start the service, expose health api and check if its up. if it is move to next one. You need to make use of curl and sleep command in your scripts.

But I would like to know why you want to do that. Specially for your microservices, your services should not depend on each other. They may need some data, but they should be resilient to the fact that services may come and go. You should have a very strong reason to do as you are doing, cause in real world env, it is very difficult to ensure order is maintained.

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