Skip to content

How to automatically start 2 Java jars on AWS EC2?

I’m learning to deploy Spring Boot apps on AWS EC2. And I know how to automate app launch, when I start the EC2 instance, I don’t need to manually use the command java -jar java-service.jar, I just add this command in the /etc/rc.local file and that is all. But I have 2 microservice, and I want to start both of them automatically, but if I try to add both commands in the /etc/rc.local it’s not working, only the first service will start, the second service will not start. So I have the commands added like this:

enter image description here

And after I start the EC2 instance only the first service is started:

enter image description here

Thank you!



I am not a unix expert, but I see the only issue in running 2 java commands from terminal is that unless the first command returns, the next command is not executed. So, I think the solution would be run the 1st command in some interactive mode so that the other commands can be executed simultaneously.

There are ways in unix shell to run a command in background. I found this useful link –

In bash terminal, a command can be made to run in background by appending it with &. So, I think you should be able to start both jars if you do something like –

java -jar /home/ec2-user/first.jar &
java -jar /home/ec2-user/second.jar
User contributions licensed under: CC BY-SA
6 People found this is helpful