title: How to run Spring Boot application on test server using Jenkins
body: <p>I'm trying to run a Spring Boot application with the embedded Tomcat server from a jar that is generated by Gradle. </p>
  
  <p>Nothing too fancy I would say, but somehow I can't get this to work the way I would like. </p>
  
  <p>There are some issues here. The goal is to run the Spring Boot application on a test server so that we can do some integration tests on it. We have created some Postman tests that we'll run on Jenkins after the Spring Boot app has started. </p>
  
  <h1>Run the jar artifact plain and simple</h1>
  
  <p>My guess was that the easiest way would be to deploy the jar to the server and run it with <code>java -jar my-app.1.0.0-SNAPSHOT.jar</code>. When I run this command on localhost and go to <em><a href="http://localhost:8100" rel="nofollow noreferrer">http://localhost:8100</a></em> I can see the website. But when I do the same thing on the server, the website does not show. </p>
  
  <h1>Run the jar using a script</h1>
  
  <p>To automate starting and stopping the Spring Boot app I figured a script would be nice. </p>
  
  <p>I created a script that should shut down all running processes and then start a new one. This script would be called after the new artifact is deployed to the test server. </p>
  
  <pre><code>#!/bin/sh
  ps | grep my-app | awk '{print $1}' | xargs kill -9 || true
  /usr/bin/java -jar my-app.1.0.0-SNAPSHOT.jar &amp;
  </code></pre>
  
  <p>What happens when this script is run is the following:</p>
  
  <p>First a message is displayed indicating the <code>ps</code> command is not used properly:</p>
  
  <pre><code>$ ./start-app
  
  Usage:
   kill [options] &lt;pid&gt; [...]
  
  ...
  </code></pre>
  
  <p>Then I would expect the Spring Boot application to start, but first I see another prompt and then the Spring Boot app starts. </p>
  
  <pre><code>$
   .   ____          _            __ _ _
   /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
   \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
    '  |____| .__|_| |_|_| |_\__, | / / / /
   =========|_|==============|___/=/_/_/_/
   :: Spring Boot ::        (v2.0.5.RELEASE)
  ...
  2018-09-29 18:11:45.142 ERROR 29971 --- [           main] o.apache.catalina.core.StandardService   : Failed to start connector [Connector[HTTP/1.1-8100]]
  ...
  </code></pre>
  
  <p>Which says another instance is running, which can be verified by calling <code>ps</code>. And I also don't get another prompt until I press the <em>enter</em> key.</p>
  
  <p>The question is: how can I get the Spring Boot application to run on it's own and to start a new instance when it is available?</p>