0

I have a weird problem with a Chef Recipe. Let me tell you that I'm new to Chef so pardon me if something looks awfully wrong.

I have my war file, which is built by Spring Boot. I just need to run java -jar <file>.war -config=config/ to run my app.

I recently started experimenting with Chef, and getting to write recipes that do this job.

The code from my recipe is as follows:

#Some code has been omitted intentionally.

directory "#{home}" do
  owner 'root'
  group 'root'
  mode '0755'
  recursive true
end

directory "#{home}/config" do
  owner 'root'
  group 'root'
  mode '0755'
end
cookbook_file "#{home}/config/ehcache.xml" do
  source "ehcache.xml"
  mode "0644"
end
# Get the war file from the repo
remote_file "#{home}/app.war" do
   source "#{node['baseos']['files_repo_url']}/wars/app.war"
   owner 'root'
   group 'root'
   mode '0644'
end

execute 'Run the war file' do
  command "java -jar '#{home}/app.war' -config='#{home}/config/'"
  action :run
end

The war file, and the related config folder along with its contents are successfully being copied to their respective destinations before the execute command gets fired. The problem is when the machine gets freshly created with kitchen create, the first kitchen verify would fail, saying 'Errno::ENOENT: No such file or directory - java -jar /opt/com/app.war -config=config/'. This only happens for the first time. Surprisingly, after saying kitchen verify again, the app starts up, and successfully runs.

This is weird because of the fact that the required file app.war and the config/ are [or should be] already there in the machine with appropriate privileges.

I know Chef processes these things sequentially, so given that the execute command is the very last line in my recipe, it should already have what is required to run the war file. I'm going nuts, can anyone provide some insight into this one?

Thank you!

Sasanka Panguluri
  • 3,058
  • 4
  • 32
  • 54
  • possible duplicate of [how to run a java program at background from chef recipe](http://stackoverflow.com/questions/18414090/how-to-run-a-java-program-at-background-from-chef-recipe) – Mark O'Connor Jun 26 '15 at 22:32
  • a gist or something of the run and the debug output might help. and i'm wondering if is not complaining about the war but the config and i notice you've got gh_home in the cookbook_file resource to drop the config. your error output also looks like it doesn't match the execute resource when it comes to the config argument. – lamont Jun 27 '15 at 01:52
  • Sorry it's a typo, it's actually home, not gb_home. Corrected it now. – Sasanka Panguluri Jun 27 '15 at 14:12
  • @Mark I don't even understand how it can be thought of as a duplicate of the other question you mentioned. Can you go through the question again? This one's a problem I have. It's not about running something in the background. It's about not being able to run something at all. – Sasanka Panguluri Jun 27 '15 at 14:15

1 Answers1

1

While it is somewhat counter-intuitive, this is probably because you don't have java available on your $PATH. This might mean java is not installed, or that it is installed but not in a way that Chef can find it. Remember that environment variables are only inherited when a process starts, so if you installed Java in such a way that the installer set up some global change to $PATH it wouldn't be visible to Chef. A good fix would be to use the full path to the JVM binary (/opt/whatever/bin/java or something).

coderanger
  • 52,400
  • 4
  • 52
  • 75