I am new to Chef 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.
Specifically, I want the cookbook to:
- Download
http://myrepo.example.com/myapp.jar
to/opt/myapp/bin
on the node; then - Set
MYAPP_HOME
env var to/opt/myapp/bin
; then - Run
java -jar /opt/myapp/bin/myapp.jar --setup
Obviously this cookbook depends on Java (ideally 8+) being installed on the server ahead of time.
Using this excellent guide as my starting point, here is my best attempt thus far:
Create the cookbook:
knife create cookbook cookbook-myapp -o cookbooks/ -r md
/cookbooks/cookbook-myapp/recipes/default.rb
:
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 <<-EOH
java -jar ${MYAPP_HOME}/myapp.jar --setup
EOH
end
But this is obviously wrong. Any ideas or nudges in the right direction anyone can give me?