title: Run java application as background process via ssh
body: <p>I'm currently developing a simple deployment script for vms running ubuntu.
  All these machines are supposed to run a java application provided as a jar.</p>
  
  <p>This is the relevant part of the script installing java, copying a jar from local machine to remote machine and then starting the application:</p>
  
  <pre><code>ssh ubuntu@$line -i ~/.ssh/key.pem -o StrictHostKeyChecking=no &lt;java_installation.sh
  scp -i ~/.ssh/key.pem $JARFILE ubuntu@$line:~/storagenode.jar
  ssh ubuntu@$line -i ~/.ssh/key.pem &lt;java_start_jar.sh
  </code></pre>
  
  <p>the installation via the java_installation.sh script succeeds, the scp command does as well.
  The problem occurs when trying to execute the commands in java_start_jar.sh via ssh. 
  java_start_jar.sh:</p>
  
  <pre><code>#!/bin/sh
  # this script starts a jar file and creates a shellscript which can be used to stop the execution.
  nohup java -jar ~/storagenode.jar &amp; &gt; ~/storagenode.log
  pId=$!
  echo "kill $pId" &gt; ~/stop_storagenode.sh
  chmod u+x ~/stop_storagenode.sh
  </code></pre>
  
  <p>The scripts starts the execution of the .jar file, but then simply blocks.
  Ssh does not return, the rest of the local code is only executed after manually closing connection.
  Any ideas why the java application is not properly running as a background process?</p>