restart a service on another machine after connecting to it

I'm new to chef and struggling with this concept - I'm not sure if it's possible and if it is, how to achieve it. Thus far Google Fu has failed me.

I have a chef client and chef server, i'm uploading cookbooks to run on my client. I trigger the code by running chef-client on the chef client machine.

What I'm then trying to do is connect to several other boxes via ssh and then stop a service, clear out a directory and restart the service.

When working I'll be targeting Solr service

My basic test code is as follows:

    ruby_block 'do something' do
    block do
        Chef::Log.info('Do Something')
        Chef::Resource::Notification.new('stop', :run, self)
    end
end

#define the service - does nothing
service 'atd' do
    action :nothing
end

#do something that triggers
execute 'start' do
  command 'pwd'
    Chef::Log.info('triggers start')
    action :nothing
    notifies :start, run_context.resource_collection.find(:service => 'atd')
end

execute 'stop' do
    # some stuff
    # on success...
    command 'pwd'
    Chef::Log.info('triggers restart')
    notifies :stop, run_context.resource_collection.find(:service => 'atd'), :immediately
    notifies :run, 'execute[start]'
end

in the ruby block I plan on iterating through a list of machines that I have and ssh'ing to them. Is it then possible to run the remainder of the code on those machines?

Thanks for any help / advice.

链接地址: http://www.djcxy.com/p/78318.html

上一篇: 计数与GREP匹配模式的文件

下一篇: 连接到另一台机器后重新启动服务