title: Writing custom Chef cookbook to install and run homegrown app
body: <p>I am new to <a href="https://www.chef.io" rel="nofollow">Chef</a> and am trying to create a simple custom cookbook. I have an executable JAR that I have hosted on a private binary repo, and I'd like my cookbook to install this JAR, configure the server to be able to run the JAR, and then 
  actually run it.</p>
  
  <p>Specifically, I want the cookbook to:</p>
  
  <ul>
  <li>Download <code>http://myrepo.example.com/myapp.jar</code> to <code>/opt/myapp/bin</code> on the node; then</li>
  <li>Set <code>MYAPP_HOME</code> env var to <code>/opt/myapp/bin</code>; then</li>
  <li>Run <code>java -jar /opt/myapp/bin/myapp.jar --setup</code></li>
  </ul>
  
  <p>Obviously this cookbook depends on Java (ideally 8+) being installed on the server ahead of time.</p>
  
  <p>Using this <a href="http://www.devopsnotes.com/2012/02/how-to-write-good-chef-cookbook.html" rel="nofollow">excellent guide</a> as my starting point, here is my best attempt thus far:</p>
  
  <h3>Create the cookbook:</h3>
  
  <blockquote>
    <p>knife create cookbook cookbook-myapp -o cookbooks/ -r md</p>
  </blockquote>
  
  <h3><code>/cookbooks/cookbook-myapp/recipes/default.rb</code>:</h3>
  
  <pre><code>package http://myrepo.example.com/myapp.jar
  
  service "myapp" do
      action :install
  end
  
  env 'MYAPP_HOME' do
      value '/opt/myapp/bin'
  end
  
  bash 'run_jar' do
      code &lt;&lt;-EOH
      java -jar ${MYAPP_HOME}/myapp.jar --setup
      EOH
  end
  </code></pre>
  
  <p>But this is obviously wrong. Any ideas or nudges in the right direction anyone can give me?</p>