Ian*_*son 5 nginx phusion-passenger chef
我正在编写一个厨师食谱来安装 nginx 和 Phusion Passenger。简短的总结是我的运行列表中的配方没有按照我期望的顺序执行,这导致 apt 包安装以我不知道如何修复的方式失败。整个序列有点复杂,我会尽力保留基本细节。
我有自己的配方,lr-web
用于将 Web 服务器自定义为我希望它处于的状态。它对nginx.conf
. 我还有一个角色来协调整体配置,其运行列表是:
"run_list":[
"recipe[apt]",
"recipe[nginx]",
"recipe[passenger]",
"recipe[lr-web]"
]
Run Code Online (Sandbox Code Playgroud)
此外,lr-web
配方列表passenger
,并nginx
在它的依赖metadata.rb
。
在apt
和nginx
食谱是标准的Opscode公司的。但是我已经编写了自己的passenger
配方,因为 OpsCode 使用 rubygems 来安装乘客,但该版本不再受支持。按照modrails.com上的建议通过 apt 安装,我的passenger
食谱中有以下步骤:
cookbook_file "/etc/apt/sources.list.d/passenger.list" do
source "passenger.list"
mode 600
action :create_if_missing
end
bash "apt-get-update" do
user "root"
code <<-EOF
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
apt-get install apt-transport-https ca-certificates
apt-get update
EOF
end
apt_package "nginx-extras" do
action :install
end
Run Code Online (Sandbox Code Playgroud)
当我收敛节点时会发生什么,我从 apt-get 得到一个提示,即使它通过了-y
标志,因为nginx-extras
包安装程序不想覆盖nginx.conf
:
Configuration file `/etc/nginx/nginx.conf'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** nginx.conf (Y/I/N/O/D/Z) [default=N] ?
Configuration file `/etc/nginx/sites-available/default'
==> Modified (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** default (Y/I/N/O/D/Z) [default=N] ? dpkg: error processing nginx-common (--configure):
EOF on stdin at conffile prompt
dpkg: dependency problems prevent configuration of nginx-extras:
nginx-extras depends on nginx-common (= 1:1.4.4-2.4.0.37~precise1); however:
Package nginx-common is not configured yet.
dpkg: error processing nginx-extras (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
Errors were encountered while processing:
nginx-common
nginx-extras
E: Sub-process /usr/bin/dpkg returned an error code (1)
Run Code Online (Sandbox Code Playgroud)
据我所知,发生这种情况的唯一方法是我的lr-web
食谱在乘客食谱之前运行,这是不应该的。
所以。我遇到的问题lr-web
是之前运行passenger
,因此更改了 nginx conf。我要么需要找出发生这种情况的原因,然后停止它,要么找到一种方法在apt_package
安装nginx-extras
时传递“N”响应,说“不要覆盖 nginx.conf”。任何关于任一攻击角度的建议将非常受欢迎。
这可能是因为说明书在 apt 安装后nginx
修改了文件,并且 dpkg 命令警告您有关该更改的信息。/etc/nginx/nginx.conf
这也会在 上发生冲突/etc/nginx/sites-available/default
。
将乘客配方放在 nginx 配方上方将确保安装存储库和软件包。由于 nginx-extras 提供了它自己的 nginx.conf 文件,因此该文件将立即被 nginx 配方覆盖,并从那里开始控制。
您修改后的运行列表将如下所示:
"run_list":[
"recipe[apt]",
"recipe[passenger]",
"recipe[nginx]",
"recipe[lr-web]"
]
Run Code Online (Sandbox Code Playgroud)
您还可以尝试强制 apt 按照您想要的方式做出响应 - 这有可能对 apt 的行为过于激进,从而可能影响 Chef 运行的其余部分。我不推荐这样做,但您可以尝试一下,看看它是否适合您的用例。
ENV['DEBIAN_FRONTEND'] = 'noninteractive'
package 'nginx-extras' do
options '--force-yes'
options '-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"'
action :install
end
Run Code Online (Sandbox Code Playgroud)
在这里阅读更多相关内容。
这存在以这种方式回答其他资源的危险,而不是向操作员展示问题,以及资源可能会相互覆盖,并触发对其他资源的不需要的通知,例如在配置文件更改时触发 nginx 重新启动, ETC。
这并不是真正解决排序问题,只是更好地利用 Chef 资源。
您将提供一个说明书文件,然后执行 bash 资源来激活它们。如果没有使用 only_if/not_if 语句进行保护,每次运行都会发生这种情况。
apt
您正在使用的食谱已经有一个存储库资源,并且会将您的食谱更改为如下所示:
apt_repository 'passenger' do
uri 'https://oss-binaries.phusionpassenger.com/apt/passenger'
distribution node['lsb']['codename']
components ['main']
keyserver 'keyserver.ubuntu.com'
key '561F9B9CAC40B2F7'
end
Run Code Online (Sandbox Code Playgroud)
然后,这将以更明智的方式运行,在运行期间运行 apt-get 命令,并且输出几乎相同:
deb https://oss-binaries.phusionpassenger.com/apt/passenger precise main
Run Code Online (Sandbox Code Playgroud)
(在 Ubuntu 12.04 上)
使用第一个解决方案更改配方对两个不同包提供的文件应用更改的顺序。
使用第三种解决方案进一步清理代码。
归档时间: |
|
查看次数: |
2303 次 |
最近记录: |