问题描述
我是一名厨师新秀。我想创建一个在后台运行jar的配方。
I am a chef rookie. I want to create a recipe to run a jar at background.
bash 'run_jar' do
code <<-EOH
wget https://github.com/kiwiwin/jar-repo/releases/download/kiwi/helloworld-1.0.jar -O hello.jar
java -jar hello.jar &
EOH
end
helloworld-1.0.jar是程序首次打印Hello World,然后执行while(true)循环。
The helloworld-1.0.jar is a program first print "Hello World", then execute a while(true) loop.
我希望当我登录chef-client机器时。它应该表明有一个使用jps命令运行的jar。但是没有这样的罐子运行。
I expect when I login to the chef-client machine. It should indicate there is a jar running using "jps" command. But there is no such jar running.
我可以看到下载了hello.jar,表明代码块已经执行。
And I can see the hello.jar is downloaded which indicates the code block has been executed already.
这个方法有什么问题?
推荐答案
建议您将代码配置为作为服务运行。可以使用几个包装器,例如:
You are best advised to configure your code to run as a service. Several wrappers available, for example:
- http://wrapper.tanukisoftware.com/doc/english/app-hello-world-server.html
完成后,您可以配置厨师来管理新服务:
Once this is done you can configure chef to manage the new service:
service "myapp_service" do
supports :status => true, :restart => true
start_command "/usr/lib/myapp/bin/myapp start"
restart_command "/usr/lib/myapp/bin/myapp restart"
status_command "/usr/lib/myapp/bin/myapp status"
action [ :enable, :start ]
end
这篇关于如何在厨师食谱的背景下运行java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!