我是 Chef 的新手,我想在每次部署后通过我的配方在云节点上重新启动 resque 工作人员。resque 提供了一个 Rake 任务来启动工作人员
QUEUE='*' bundle exec rake environment resque:work >>/log/resque.log 2>&1 &
为了停止它,我对 resque 进程进行 grep 并手动终止它。
我找不到任何关于如何在 Chef服务中运行 rake 任务的好例子。有人可以帮我提供一个样本服务来做我想做的事吗?
我是 Chef 的新手,我想在每次部署后通过我的配方在云节点上重新启动 resque 工作人员。resque 提供了一个 Rake 任务来启动工作人员
QUEUE='*' bundle exec rake environment resque:work >>/log/resque.log 2>&1 &
为了停止它,我对 resque 进程进行 grep 并手动终止它。
我找不到任何关于如何在 Chef服务中运行 rake 任务的好例子。有人可以帮我提供一个样本服务来做我想做的事吗?
创建一个用于重新启动工作人员的execute
资源action :nothing
(根据需要进行调整):
execute "restart_resque_workers" do
command "pkill resque && QUEUE='*' bundle exec rake environment resque:work >>/log/resque.log 2>&1 &"
cwd "/path/to/app"
action :nothing
end
然后,在部署资源上,添加:
application "app" do
...
notifies :run, "execute[restart_resque_workers]"
end
理想情况下stop
,start
和restart
机制将由适当的服务处理,但无论如何总体模式是相同的。
该notifies
属性仅在application
资源被修改时才会生效(通常这意味着新的部署)。
Chef 文档中有关通知的更多信息。
穷人的服务可以是这样的:
service 'resque_workers' do
start = "QUEUE='*' bundle exec rake environment resque:work >>/log/resque.log 2>&1"
stop = "pkill resque"
start_command start
stop_command stop
restart_command "#{stop}; #{start}"
supports [ :start, :stop, :restart ]
end
然后notifies :restart, "service[resque_workers]"
在application
资源中使用。