Answers: <p>Great, I was going to make a big disclaimer, but you have the right thing in mind, so I'll make a small one for people that come by and don't have the time to read it all thoroughly.</p>
  <p>** NOT FOR PRODUCTION **</p>
  <ol>
  <li>This will be a cycle of starting an app and waiting for a condition. In order for your script to progress from one command to the next, you will need to start all the applications in the background.</li>
  </ol>
  <p>So, in a nutshell</p>
  <pre><code>~ start app &amp; #don't wait for the script to end
  ~ some waiting script # runs until condition passes
  </code></pre>
  <p>Here's a good example of a waiting script: <a href="https://github.com/vishnubob/wait-for-it" rel="nofollow noreferrer">https://github.com/vishnubob/wait-for-it</a></p>
  <p>In a nutshell what this wait-for-it script does, you can implement manually by creating a while loop that runs until a timeout or until some condition is valid.</p>
  <p>Examples of valid conditions:</p>
  <ul>
  <li>status 200 on localhost on port 8000</li>
  </ul>
  <p>You could implement these bash functions manually, it's basically a while loop and if and a counter, but I'll assume you don't want to waste time on it and I'll make an example script using the wait-for-it.sh</p>
  <p>So, here it is:</p>
  <pre class="lang-bash prettyprint-override"><code>#! /bin/bash
  
  sudo docker-compose up -d # -d will start the containers in detached mode
  ./wait-for-it.sh localhost:12345 #replace 12345 with the correct port
  java -jar ./myapp.jar &amp; # &amp;sign, sends the app to the background
  ./wait-for-it.sh localhost:12345
  python3 ./myapp.py &amp;
  ./wait-for-it.sh localhost:12345
  npm start ./myapp &amp;
  ./wait-for-it.sh localhost:12345
  chromium-browser www.my.app
  
  #this is kill all background processes when you quit this script
  trap 'kill $(jobs -p)' EXIT 
  
  #this will wait for all the background processes to quit before letting this script exit
  wait -n 
  
  </code></pre>
  
Answers: CC BY-SA 4.0
Answers: 2021-11-19T08:37:44.303Z
Answers: That helps! Thanks a lot!
Answers: Martin Dvoracek
Answers: CC BY-SA 4.0
Answers: 2021-11-16T18:05:21.197Z
Answers: 2021-11-16T18:05:21.197Z
Answers: Magus
Answers: <p>If you're already launching one of these services with Docker Compose, I think it would be a very small lift to Dockerize the remaining Java, NodeJS, and Python components. When you have built a docker image for each one, then they can be configured to start in the correct order by using <a href="https://docs.docker.com/compose/compose-file/compose-file-v3/#depends_on" rel="nofollow noreferrer">depends_on</a> in your compose file. Then you can bring them all up in the correct order by just running <code>docker-compose up</code>.</p>
  <p>you can sleep for a bit before launching the browser, or monitor the stdout of the last service to start for a good &quot;ready&quot; message before launching chromium.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-11-19T08:37:00.113Z
Answers: that's actually really neat and easy solution
Answers: Martin Dvoracek
Answers: CC BY-SA 4.0
Answers: 2021-11-16T19:52:27.293Z
Answers: 2021-11-16T19:52:27.293Z
Answers: Segfault
Body: <p>I'd like to automatically start all of the following applications after the system startup. However, they need to be started in a specific order and when the previous application is done booting.</p>
  <p>The commands I'm now performing manually in the terminal are:</p>
  <pre><code>sudo docker-compose up
  java -jar ./myapp.jar
  python3 ./myapp.py
  npm start ./myapp
  chromium-browser www.my.app
  </code></pre>
  <p>So my java app needs to wait for the docker container to be started, otherwise it will fail to start. Analogically, the python app needs to wait for the java app to be started, and finally the web page needs to be opened after the angular frontend is ready to be served. Is there some easy way, how to handle this by a bash script, without getting way too deep with some DevOps tools? It's just a small pet project and I don't want to spend way too much time by over-engineering it.</p>
  
Tags: <docker><spring-boot>
Title: How to start start applications one after another with a shell script?
UserDisplayName: Martin Dvoracek
ThreadText: # How to start start applications one after another with a shell script?
  
  (Asked by: username_0 on 2021-11-15)
  
  I'd like to automatically start all of the following applications after the system startup. However, they need to be started in a specific order and when the previous application is done booting.
  
  The commands I'm now performing manually in the terminal are:
  
  ```
  sudo docker-compose up
  java -jar ./myapp.jar
  python3 ./myapp.py
  npm start ./myapp
  chromium-browser www.my.app
  
  ```
  
  So my java app needs to wait for the docker container to be started, otherwise it will fail to start. Analogically, the python app needs to wait for the java app to be started, and finally the web page needs to be opened after the angular frontend is ready to be served. Is there some easy way, how to handle this by a bash script, without getting way too deep with some DevOps tools? It's just a small pet project and I don't want to spend way too much time by over-engineering it.
  
  **Tags:** docker, spring-boot
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-11-16. Score: 1 | Accepted answer
  
  Great, I was going to make a big disclaimer, but you have the right thing in mind, so I'll make a small one for people that come by and don't have the time to read it all thoroughly.
  
  \*\* NOT FOR PRODUCTION \*\*
  
  1. This will be a cycle of starting an app and waiting for a condition. In order for your script to progress from one command to the next, you will need to start all the applications in the background.
  
  So, in a nutshell
  
  ```
  ~ start app & #don't wait for the script to end
  ~ some waiting script # runs until condition passes
  
  ```
  
  Here's a good example of a waiting script: <https://github.com/vishnubob/wait-for-it>
  
  In a nutshell what this wait-for-it script does, you can implement manually by creating a while loop that runs until a timeout or until some condition is valid.
  
  Examples of valid conditions:
  
  * status 200 on localhost on port 8000
  
  You could implement these bash functions manually, it's basically a while loop and if and a counter, but I'll assume you don't want to waste time on it and I'll make an example script using the wait-for-it.sh
  
  So, here it is:
  
  ```bash
  #! /bin/bash
  
  sudo docker-compose up -d # -d will start the containers in detached mode
  ./wait-for-it.sh localhost:12345 #replace 12345 with the correct port
  java -jar ./myapp.jar & # &sign, sends the app to the background
  ./wait-for-it.sh localhost:12345
  python3 ./myapp.py &
  ./wait-for-it.sh localhost:12345
  npm start ./myapp &
  ./wait-for-it.sh localhost:12345
  chromium-browser www.my.app
  
  #this is kill all background processes when you quit this script
  trap 'kill $(jobs -p)' EXIT 
  
  #this will wait for all the background processes to quit before letting this script exit
  wait -n 
  
  ```
  
  > **Comments:**
  > **username_0**: That helps! Thanks a lot!  
  
  ---
  
  ### Answer by username_2 on 2021-11-16. Score: 2
  
  If you're already launching one of these services with Docker Compose, I think it would be a very small lift to Dockerize the remaining Java, NodeJS, and Python components. When you have built a docker image for each one, then they can be configured to start in the correct order by using [depends\_on](https://docs.docker.com/compose/compose-file/compose-file-v3/#depends_on) in your compose file. Then you can bring them all up in the correct order by just running `docker-compose up`.
  
  you can sleep for a bit before launching the browser, or monitor the stdout of the last service to start for a good "ready" message before launching chromium.
  
  > **Comments:**
  > **username_0**: that's actually really neat and easy solution  
  
  ---
  
  