Search code examples
nginxchef-infrachef-recipecookbook

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


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

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

include_recipe "yum"


yum_repository 'epel' do
    mirrorlist 'http://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=$basearch'
    description 'Extra Packages for Enterprise Linux 7 - $basearch'
    enabled true
    gpgcheck true
    gpgkey 'https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-7'
end

yum_repository "nginx" do
    name 'nginx_repo'
    baseurl  'http://nginx.org/packages/rhel/7/$basearch/'
    enabled true
    gpgcheck true
    #gpgkey      'http://nginx.org/keys/nginx_signing.key'
    action :create
end


package "nginx" do

      action :install
end


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


template "default.conf" do
      source "default.conf.erb"
      path "#{node['nginx']['dir']}/conf.d/default.conf"
      action :create
      mode 0644
end


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

Also, I have added ' depends "yum" ' in metadata.rb

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

[2014-12-17T08:53:03+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:
  - nginx
  - yum
Compiling Cookbooks...
Converging 7 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[epel] action create
* template[/etc/yum.repos.d/epel.repo] action create (up to date)
* execute[yum-makecache-epel] action nothing (skipped due to action :nothing)
* ruby_block[yum-cache-reload-epel] action nothing (skipped due to action :nothing)
 (up to date)
* 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)
* service[nginx] action enable (up to date)
* service[nginx] action start

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

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /sbin/service nginx start ----
STDOUT: Starting nginx: [FAILED]
STDERR: nginx: [emerg] invalid log level "pid" in /etc/nginx/nginx.conf:5
---- End output of /sbin/service nginx start ----
Ran /sbin/service nginx start returned 1

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

 53: service 'nginx' do
 54:   #supports :restart => :true
 55:   action [:enable, :start]
 56: end
 57: 

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

service("nginx") do
  action [:enable, :start]
  supports {:restart=>false, :reload=>false, :status=>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:
[2014-12-17T08:53:05+00:00] ERROR: Running exception handlers
Running handlers complete
[2014-12-17T08:53:05+00:00] ERROR: Exception handlers complete
[2014-12-17T08:53:05+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out

Chef Client failed. 0 resources updated in 2.259546529 seconds

[2014-12-17T08:53:05+00:00] ERROR: service[nginx] (nginx::default line 53) had an error:      Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /sbin/service nginx start ----
STDOUT: Starting nginx: [FAILED]
STDERR: nginx: [emerg] invalid log level "pid" in /etc/nginx/nginx.conf:5
---- End output of /sbin/service nginx start ----
Ran /sbin/service nginx start returned 1
[2014-12-17T08:53:05+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited  unsuccessfully (exit code 1)

Solution

  • The log is quite clear I think:

    STDERR: nginx: [emerg] invalid log level "pid" in /etc/nginx/nginx.conf:5

    your nginx.conf.erb file as somewhere a problem as it writes a log_level = pid instead of info/error.