与配置NGINX的通知错误的Puppet文件依赖关系

时间:2015-12-10 14:47:01

标签: nginx debian puppet

使用文件配置Nginx"资源:

MutableList<Integer> distinct = ListAdapter.adapt(integers).distinct();

导致错误:

# We install NGINX
package { "nginx":
  ensure => installed
}

service { "nginx":
  require => Package["nginx"],
  ensure => running,
  enable => true
}

file { ["/var/www/html", "/var/www/html/index.nginx-debian.html"]:
  require => Package["nginx"],
  ensure  => absent,
  notify  => Service["nginx"]
}

file { "/etc/nginx/sites-available/aerospace":
  ensure => "file",
  content => file("nginx/aerospace"),
  notify => Service["nginx"]
}

file { "/etc/nginx/sites-enabled/aerospace":
  require => File["/etc/nginx/sites-available/aerospace"],
  ensure => "link",
  target => "/etc/nginx/sites-available/aerospace",
  notify => Service["nginx"]
}

调用 systemctl 对我没有任何帮助:

==> default: Notice: /Stage[main]/Main/File[/etc/nginx/sites-enabled/aerospace]/ensure: created
==> default: Error: /Stage[main]/Main/Service[nginx]: Failed to call refresh: Could not start Service[nginx]: Execution of '/usr/sbin/service nginx start' returned 1: Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
==> default: Error: /Stage[main]/Main/Service[nginx]: Could not start Service[nginx]: Execution of '/usr/sbin/service nginx start' returned 1: Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
==> default: Wrapped exception:
==> default: Execution of '/usr/sbin/service nginx start' returned 1: Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.

有什么想法吗?我在这里错过了一些关于Puppet或Debian的内容吗?

1 个答案:

答案 0 :(得分:1)

正如maxd所说,来自systemd的错误是配置文件上的nginx -t失败,表明配置文件的语法不正确。运行nginx -t并查看其内容:

-t  Don’t run, just test the configuration file. NGINX checks configuration for correct syntax and then try to open files referred in configuration.

如果您使用Puppet管理nginx配置文件,您实际上可以将validate_cmd添加到文件资源以专门对其进行检查,这可以防止在验证失败时覆盖文件:< / p>

file { "/etc/nginx/sites-available/aerospace":
   ensure => "file",
   content => file("nginx/aerospace"),
   notify => Service["nginx"]
   validate_cmd => '/usr/bin/nginx -t',
}

file { "/etc/nginx/sites-enabled/aerospace":
  require => File["/etc/nginx/sites-available/aerospace"],
  ensure => "link",
  target => "/etc/nginx/sites-available/aerospace",
  notify => Service["nginx"]
  validate_cmd => '/usr/bin/nginx -t',
}