【发布时间】:2016-09-07 01:45:21
【问题描述】:
我正在使用 Chef、Tomcat 和 Nginx 来配置我的前端机器,使用 Tomcat 根目录中的一个 .war 文件,当它被放置在那里并第一次访问时会展开。这是我的食谱:
include_recipe 'selinux::disabled'
%w{curl zip unzip tomcat7 lynx mysql-client}.each do |pkg|
package pkg do
action :install
end
end
package 'nginx' do
action :install
end
service 'tomcat7' do
service_name 'tomcat7'
supports :restart => true, :status => true
action [:start, :enable]
end
service 'nginx' do
action [ :enable, :start ]
end
cookbook_file "/usr/share/nginx/html/index.html" do
source "index.html"
mode "0644"
end
execute "setsebool -P httpd_can_network_connect 1" do
only_if "getsebool -a | grep 'httpd_can_network_connect --> off'"
end
user 'nginx' do
comment 'nginx user'
system true
shell '/bin/false'
end
template "/etc/nginx/nginx.conf" do
source "nginx.conf.erb"
mode '0644'
owner 'root'
group 'root'
notifies :reload, 'service[nginx]', :delayed
end
[ bunch of stuff copying the .war file in ]
service 'tomcat7' do
action :restart
end
execute "reload nginx" do
command "nginx -s reload"
action :nothing
end
而且效果很好。它甚至在最后正确地重新加载 nginx - 这是运行的结束:
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com * service[tomcat7] action restart
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com - restart service service[tomcat7]
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com * service[nginx] action reload
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com - reload service service[nginx]
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com * service[nginx] action reload
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com - reload service service[nginx]
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com Running handlers:
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com Running handlers complete
ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com Chef Client finished, 17/25 resources updated in 171.195633435 seconds
一切都设置好了,但是当我加载页面时,我得到了默认的 nginx 页面,就好像 nginx 没有正确获取配置文件一样。该文件肯定存在,并且格式正确。我去执行:
sudo nginx -t
而且效果很好。然后,当我终于找到所有东西并且一切正常时,我所做的就是:
sudo nginx -s reload
一切正常。这让我相信 Chef 在重新加载 nginx 时没有正确执行某些操作,但我终其一生都无法弄清楚那是什么。
更新
根据 SlayedByLucifer 的建议,我现在通过使用命令重新加载来结束配方,但它仍然不起作用。
【问题讨论】:
-
reload资源中的reload操作并不完全等同于nginx -s reload。手动测试时,不要运行nginx -s reload并尝试使用service nginx reload命令重新加载。如果您仍然面临同样的问题,那么这不是厨师的问题。但如果它解决了问题,那么你应该提交一个厨师错误。 -
哼...我被难住了。我现在已经更新了上面的内容以包含内联命令,但它仍然不起作用。我必须延迟运行它吗?
-
没有必要使用
nginx -s reload。你用的是什么发行版?发布厨师日志,以便我们知道发生了什么 -
你能说更多关于发布日志的信息吗?我正在使用 Ubuntu 14.04。我发布了上面的输出。
-
嗨,亲爱的,有进展吗?我在 ubuntu 14.04 和 nginx 上遇到了同样的问题
标签: tomcat nginx chef-infra