为什么主厨不重新加载我的Nginx& Tomcat文件正常吗?

时间:2015-03-15 01:29:37

标签: tomcat nginx chef

我正在使用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的建议,我现在通过使用命令重新加载来结束配方,但它仍然不起作用。

1 个答案:

答案 0 :(得分:0)

TLDR;可能是nginx配置中的配置问题,比如提供了错误的listen指令。

更长的答案; 我一直在努力,但事实证明我的问题是我的nginx配置中的错误配置。奇怪的是,当我使用service reload nginx从服务器上的shell手动完成它时,它重新加载了。执行相同操作不会通过厨师。

当我还试图安排从Chef重新启动nginx并开始抛出[::]:80 failed (98: Address already in use)之类的错误时,它在我的情况下不起作用的原因变得明显。 我只用listen 80; listen [::]:80;替换listen [::]:80;来解决这个问题。

有关更深入的答案,请参阅以下文章:error here