我相信您必须定义一个自定义配方来更新 database.yml 并重新启动应用服务器。
在本指南中,使用 redis 服务器作为示例完成了相同的操作:
node[:deploy].each do |application, deploy|
if deploy[:application_type] != 'rails'
Chef::Log.debug("Skipping redis::configure as application #{application} as it is not an Rails app")
next
end
execute "restart Rails app #{application}" do
cwd deploy[:current_path]
command "touch tmp/restart.txt"
action :nothing
only_if do
File.exists?(deploy[:current_path])
end
end
redis_server = node[:opsworks][:layers][:redis][:instances].keys.first rescue nil
template "#{deploy[:deploy_to]}/current/config/redis.yml" do
source "redis.yml.erb"
mode "0660"
group deploy[:group]
owner deploy[:user]
variables(:host => (node[:opsworks][:layers][:redis][:instances][redis_server][:private_dns_name] rescue nil))
notifies :run, resources(:execute => "restart Rails app #{application}")
only_if do
File.directory?("#{deploy[:deploy_to]}/current")
end
end
end
我还没有为自己测试过这个,但我相信我会很快,我会尽快更新这个答案。