【问题标题】:Unable to start nginx service via Chef无法通过 Chef 启动 nginx 服务
【发布时间】:2016-04-29 11:02:27
【问题描述】:

我正在尝试使用 chef solo 启动 nginx,但不断收到以下错误。

错误

 * 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] open() "/home/deploy/apps/...-api/shared/log/nginx.access.log" failed (2: No such file or directory)
    ---- End output of /sbin/service nginx start ----
    Ran /sbin/service nginx start returned 1

    Resource Declaration:
    ---------------------
    # In /root/chef-solo/cookbooks-3/.../recipes/nginx.rb

     60: service 'nginx' do
     61:   action [:enable, :start]
     62: end

    Compiled Resource:
    ------------------
    # Declared in /root/chef-solo/cookbooks-3/.../recipes/nginx.rb:60:in `from_file'

    service("nginx") do
      action [:enable, :start]
      supports {:restart=>nil, :reload=>nil, :status=>nil}
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      service_name "nginx"
      enabled true
      pattern "nginx"
      declared_type :service
      cookbook_name :...
      recipe_name "nginx"
    end


Running handlers:
[2016-01-22T18:28:41+00:00] ERROR: Running exception handlers
Running handlers complete
[2016-01-22T18:28:41+00:00] ERROR: Exception handlers complete
Chef Client failed. 11 resources updated in 25 seconds
[2016-01-22T18:28:41+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2016-01-22T18:28:41+00:00] FATAL: Please provide the contents of the stacktrace.out file if you file a bug report
[2016-01-22T18:28:41+00:00] ERROR: service[nginx] (...::nginx line 60) 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] open() "/home/deploy/apps/...-api/shared/log/nginx.access.log" failed (2: No such file or directory)
---- End output of /sbin/service nginx start ----
Ran /sbin/service nginx start returned 1
[2016-01-22T18:28:41+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
ERROR: RuntimeError: chef-solo failed. See output above.

nginx.rb

include_recipe 'yum'

yum_repository 'nginx' do
  baseurl 'http://nginx.org/packages/centos/6/$basearch/'
  gpgcheck false
  enabled true
  action :create
end

yum_package 'nginx' do
  options '--enablerepo=nginx'
  action :install
end

# remove default nginx config
# default_path = '/etc/nginx/sites-enabled/default'
# execute "rm -f #{default_path}" do
#   only_if { File.exist?(default_path) }
# end

directory '/etc/nginx/sites-available' do
  owner 'deploy'
  group 'deploy'
  mode '0755'
  recursive true
  action :create
end

directory '/home/deploy/apps/...-api/current/public' do
  owner 'deploy'
  group 'deploy'
  mode '0755'
  recursive true
  action :create
end

cookbook_file '/etc/nginx/sites-available/default' do
  source 'nginx'
  owner 'deploy'
  group 'deploy'
  mode '0755'
  action :create
end

directory '/etc/nginx/sites-enabled' do
  group 'deploy'
  mode '0755'
  owner 'deploy'
end

# set custom nginx config
cookbook_file '/etc/nginx/nginx.conf' do
  source 'nginx-base'
  owner 'deploy'
  group 'wheel'
  mode '0755'
  action :create
end

service 'nginx' do
  action [:enable, :start]
end

【问题讨论】:

  • 顺便说一句,为什么nginx 食谱对你不起作用?
  • @StephenKing 我使用的是 CentOS,默认情况下它安装了一个非常旧的 nginx 版本。至于食谱,我对 Chef 还很陌生,仍然迷失在文档中。
  • 我建议使用 nginx::repo 配方来使用上游 nginx 存储库。

标签: nginx centos chef-infra chef-solo knife-solo


【解决方案1】:

如输出所示,以下nginx 服务无法启动:

STDOUT: Starting nginx: [FAILED]
STDERR: nginx: [emerg] open() "/home/deploy/apps/...-api/shared/log/nginx.access.log" failed (2: No such file or directory)

确保目录/home/deploy/apps/...-api/shared/log/ 存在并且对Nginx 是可写的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-20
    • 2022-10-22
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-23
    • 2016-02-16
    相关资源
    最近更新 更多