1

I want to accomplish two things: 1) clean out any pointless pid files (if elasticsearch is not running) and then start it, and 2) check that ES has started up before proceeding

Now between what Chef offers out-of-box and what Ruby allows, I can only figure out a pseudo-code like syntax for making it happen but its not going to run so I need some help/advice writing the real thing.

Pseudo-Code For (1):

bash "start it up" do
    user "root"
    only_if { # pretty sure this syntax is all incorrect, any ideas to make it happen?
        (sudo service elasticsearch status).match(/^elasticsearch not running/)
    }
    code <<-EOS
        sudo rm -rf /usr/local/var/run/elasticsearch/*.pid
        sudo service elasticsearch restart
    EOS
end

Pseudo-Code For (2):

bash "wait for it to start up" do
    user "root"
    only_if { # pretty sure this syntax is all incorrect, any ideas to make it happen?
        (sudo service elasticsearch status).match(/^elasticsearch  running with PID/)
    }
    retries 20
    retry_delay 5
    code <<-EOS
        echo "I can now go on with my life..."
    EOS
end
4

1 回答 1

0

如果您希望在继续之前确保某个特定状态,请将其插入到配方中(这是一个示例,未经测试):

service "elasticsearch" do
  action [ :enable, :start ]
  status_command "/usr/sbin/service elasticsearch status | grep 'running with PID'" 
end

start等待服务实际启动是初始化脚本命令的工作。

厨师文档 说:

没有理由使用执行资源来控制服务,因为服务资源直接公开了 start_command 属性,这使得配方可以完全控制以更清晰、更直接的方式发出的命令。

于 2014-03-13T17:46:55.533 回答