Chef :: Exceptions :: Exec:/ bin / systemctl start nginx返回1,预期为0

时间:2015-01-02 06:21:27

标签: nginx chef cookbook

我正在尝试使用yum cookbook作为依赖在CentOs机器上安装nginx。

这就是我的nginx / recipe / default.rb的样子,

#
# Cookbook Name:: nginxl
# Recipe:: default
#
# Copyright 2014, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

include_recipe "yum"

case node["platform"] #Create Yum Repository for Nginx
when "redhat"
  yum_repository "nginx" do
    name 'nginx_repo'
    baseurl 'http://nginx.org/packages/rhel/7/$basearch/';
    enabled true
    gpgcheck false
    action :create
  end
when "centos"
  yum_repository "nginx" do
    name 'nginx_repo'
    baseurl 'http://nginx.org/packages/centos/7/$basearch/';
    enabled true
    gpgcheck false
    action :create
  end
end

package "nginx" do #Install Nginx package
  version "1.6.2-1.el7.ngx"
  action :install
end


template "nginx.conf" do #Create Nginx Configuration in the specified path
  source "nginx.conf.erb"
  path "#{node['nginx']['dir']}/nginx.conf"
  action :create
  mode 0644
end


template "default.conf" do #Create SSL,Proxy,Logs configuration in the specified path
  source "default.conf.erb"
  path "#{node['nginx']['dir']}/conf.d/default.conf"
  action :create
  mode 0644
end

directory "#{node['nginx']['ssl_directory']}" do
  action :create
end

cookbook_file "nginx.crt" do #Drops the SSL Certificate from Files to the specified path.
  path "#{node['nginx']['ssl_directory']}/nginx.crt"
  action :create
end

cookbook_file "nginx.key" do #Drops the SSL Key from Files to the specified path.
  path "#{node['nginx']['ssl_directory']}/nginx.key"
  action :create
end


service "nginx" do
  supports :restart => :true
  action [:enable, :start]
end

尝试在客户端服务器上运行“sudo chef-client”时,出现以下错误:

[centos@ip-172-31-26-206 ~]$ sudo chef-client
[2015-01-02T05:49:19+00:00] WARN: 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
SSL validation of HTTPS requests is disabled. HTTPS connections are still
encrypted, but chef is not able to detect forged replies or man in the middle
attacks.

To fix this issue add an entry like this to your configuration file:

```
# Verify all HTTPS connections (recommended)
ssl_verify_mode :verify_peer

# OR, Verify only connections to chef-server
verify_api_cert true
```

To check your SSL configuration, or troubleshoot errors, you can use the
`knife ssl check` command like so:

```
knife ssl check -c /etc/chef/client.rb
```

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

Starting Chef Client, version 11.16.4
resolving cookbooks for run list: ["yum", "nginx"]
Synchronizing Cookbooks:
- yum
- nginx
Compiling Cookbooks...
Converging 9 resources
Recipe: yum::default
* yum_globalconfig[/etc/yum.conf] action create
* template[/etc/yum.conf] action create (up to date)
(up to date)
Recipe: nginx::default
* yum_repository[nginx_repo] action create
* template[/etc/yum.repos.d/nginx_repo.repo] action create (up to date)
* execute[yum-makecache-nginx_repo] action nothing (skipped due to action :nothing)
* ruby_block[yum-cache-reload-nginx_repo] action nothing (skipped due to action :nothing)
(up to date)
* package[nginx] action install (up to date)
* template[nginx.conf] action create (up to date)
* template[default.conf] action create (up to date)
* directory[/etc/nginx/ssl] action create (up to date)
* cookbook_file[nginx.crt] action create (up to date)
* cookbook_file[nginx.key] action create (up to date)
* service[nginx] action enable (up to date)
* service[nginx] action start

================================================================================
Error executing action `start` on resource 'service[nginx]'
================================================================================

Chef::Exceptions::Exec
----------------------
/bin/systemctl start nginx returned 1, expected 0

Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/nginx/recipes/default.rb

67: service 'nginx' do
68: supports :restart => :true
69: action [:enable, :start]
70: end

Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/nginx/recipes/default.rb:67:in `from_file'

service("nginx") do
provider Chef::Provider::Service::Systemd
action [:enable, :start]
supports {:restart=>:true}
retries 0
retry_delay 2
guard_interpreter :default
service_name "nginx"
enabled true
pattern "nginx"
cookbook_name "nginx"
recipe_name "default"
end

Running handlers:
[2015-01-02T05:49:21+00:00] ERROR: Running exception handlers
Running handlers complete
[2015-01-02T05:49:21+00:00] ERROR: Exception handlers complete
[2015-01-02T05:49:21+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
Chef Client failed. 0 resources updated in 2.227299679 seconds
[2015-01-02T05:49:21+00:00] ERROR: service[nginx] (nginx::default line 67) had an error: 
Chef::Exceptions::Exec: /bin/systemctl start nginx returned 1, expected 0
[2015-01-02T05:49:21+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

编辑:只有在我的nginx.conf中为目录lisitng添加以下代码片段时才会发生这种情况

server     {
              listen       443;
              server_name  <%= node['nginx']['server_name'] %>;
              location / {
               source  <%= node['nginx']['source'] %>;
               autoindex on;
                         }
            } 

1 个答案:

答案 0 :(得分:1)

http://nginx.org/en/docs/dirindex.html显示没有名为source的nginx配置指令。如果这是来自某种类型的第三方插件,则不太可能包含在官方软件包中。