Search code examples
nginxchef-infracookbook

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


I am trying to install nginx on CentOs machine using yum cookbook as dependancy.

This is what my nginx/recipe/default.rb looks like,

#
# 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

On trying to run 'sudo chef-client' on client server, I get the following error:

[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)

EDIT: This happens only when I add below piece of code for directory lisitng in my nginx.conf

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

Solution

  • http://nginx.org/en/docs/dirindex.html shows no nginx config directive called source. If this is coming from a third-party plugin of some kind, it is unlikely to be included in the official packages.