Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a Java application I am deploying with Chef. I would like it to start, and allow the Chef client to exit. However, it seems like chef-client waits for the command to finish, no matter how I run it.

I have tried:

  1. Executing javaw with the execute resource
  2. Executing with start
  3. Executing with start /B
  4. Creating a batch script and running that with start and start /B

Is there a way to run the Java program without blocking chef-client?

share|improve this question

2 Answers 2

Edit: the answer below works on Linux, not Windows. It's probably not what you need, but since I wrote it already without noticing that it's a Windows question, I'll leave it for the sake of potential future readers.

This is how it can be done on Linux:

I guess you could write a bash script and run it as a service. I'm using the daemon package to do this. Here is an example recipe you can start with:

# the package that lets you easily define new services
package "daemon"

# script file used by service to launch your java program
file "/my/path/run_script.cmd" do
    content "java --flag1 --flag2 -jar /my/program.jar\n"
end

# setup the service (based on the script above),
# start it, and make it start at boot
cookbook_file '/etc/init.d/myservice' do
    source 'etc_initd_myservice'
end
service "myservice" do
    supports :restart => true, :start => true, :stop => true, :reload => true
    action [:enable]
end

Note that you'll need to add a file named etc_initd_myservice to your cookbook. You can use the content in this answer as basis for this file. This is the file that employs the "daemon" package to run a script as a service.

Also, the following question might contain relevant information if you're having problems with defining a service and creating its init.d script in the same recipe.

share|improve this answer
    
I wish creating a service in WIndows was as easy as it is in Linux. Unfortunately, you need either a program coded to be a service, or use a service wrapper. –  kjw0188 Feb 18 '13 at 19:59
up vote 0 down vote accepted

I ended up solving this by making the program a service, and running it that way. A Windows service requires either a code change or a service wrapper. YAJSW worked for me. YAJSW is easy to set up, since it includes scripts to help generate configuration, install as a service, and run the service. In the chef recipe, I include the configuration file generated on a test machine, and install and run the service with the build in scripts.

One gotcha was making sure the user running the service can run services.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.