Reputation: 29477
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:
http://myrepo.example.com/myapp.jar
to /opt/myapp/bin
on the node; thenMYAPP_HOME
env var to /opt/myapp/bin
; thenjava -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:
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?
Upvotes: 0
Views: 431
Reputation: 4223
remote_file '/path/to/myapp' do
source 'http://myapp.repo.com/myapp.jar'
end
template '/etc/init.d/myapp.conf' do
source 'myapp.init.config.erb'
variables :home => '/opt/myapp/bin'
end
service 'myapp' do
action [:enable, :start]
end
and, of course, you'll need to write myapp.init.conf.erb in cookbook/templates/default
. That is your init script for running the app as a service, and includes the bash command and setting the environment variable.
Upvotes: 1