gpt4 book ai didi

ruby - Chef 独奏 : Installing build-essential recipe before postgresql

转载 作者:数据小太阳 更新时间:2023-10-29 07:27:20 25 4
gpt4 key购买 nike

我正在尝试使用 chef-solo 在我的服务器上安装 postgresql。我通过自己进行引导并在脚本中手动包含 build-esential 包来完成这项工作。现在我想使用 knife-solo 来处理 Bootstrap ,但我在定义执行配方的顺序时遇到了问题。

我想在 postgresql 之前安装 build-essential 包。这是我正在构建的服务器的 json 文件

{
"dbuser": "myuser",
"dbpass": "mypassword",

"postgresql":{"password":{"postgres":"mypassword"}},
"passenger":{"version":"3.0.14", "max_pool_size":"2"},
"default_attributes":{"build_essential":{"compiletime": "true"}},

"run_list": [
"recipe[build-essential]",
"role[web_server]",
"recipe[sqlite]",
"recipe[postgresql::server]",
"recipe[pope::default]"
]

}

当我发出命令时

knife cook <user>@<my server's ip>

我收到这个错误

WARNING: No knife configuration file found
Checking cookbook syntax...
Checking Chef version
Enter the password for test@<my server's ip>:

[2012-10-29T16:14:44+11:00] INFO: *** Chef 10.16.2 ***
[2012-10-29T16:14:45+11:00] INFO: Setting the run_list to ["recipe[build-essential]", "role[web_server]", "recipe[sqlite]", "recipe[postgresql::server]", "recipe[mysettings::default]"] from JSON
[2012-10-29T16:14:45+11:00] INFO: Run List is [recipe[build-essential], role[web_server], recipe[sqlite], recipe[postgresql::server], recipe[pope::default]]
[2012-10-29T16:14:45+11:00] INFO: Run List expands to [build-essential, apache2, passenger_apache2, sqlite, postgresql::server, mysettings::default]
[2012-10-29T16:14:45+11:00] INFO: Starting Chef Run for test-VirtualBox
[2012-10-29T16:14:45+11:00] INFO: Running start handlers
[2012-10-29T16:14:45+11:00] INFO: Start handlers complete.
[2012-10-29T16:14:46+11:00] INFO: Processing package[postgresql-client] action install (postgresql::client line 37)
[2012-10-29T16:14:47+11:00] INFO: Processing package[libpq-dev] action install (postgresql::client line 37)
[2012-10-29T16:14:47+11:00] INFO: Processing package[make] action install (postgresql::client line 37)
[2012-10-29T16:14:47+11:00] INFO: Processing gem_package[pg] action install (postgresql::client line 42)

================================================================================
Error executing action `install` on resource 'gem_package[pg]'
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" ----
STDOUT: Building native extensions. This could take a while...
STDERR: ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

/opt/chef/embedded/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/chef/embedded/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib


Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/pg-0.14.1 for inspection.
Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/pg-0.14.1/ext/gem_make.out
---- End output of /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" ----
Ran /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" returned 1

Cookbook Trace:
---------------
/tmp/chef-solo/cookbooks/postgresql/recipes/client.rb:44:in `from_file'
/tmp/chef-solo/cookbooks/postgresql/recipes/server.rb:24:in `from_file'

Resource Declaration:
---------------------
# In /tmp/chef-solo/cookbooks/postgresql/recipes/client.rb

42: gem_package "pg" do
43: action :nothing
44: end.run_action(:install)

Compiled Resource:
------------------
# Declared in /tmp/chef-solo/cookbooks/postgresql/recipes/client.rb:42:in `from_file'

gem_package("pg") do
provider Chef::Provider::Package::Rubygems
action [:nothing]
retries 0
retry_delay 2
package_name "pg"
version "0.14.1"
cookbook_name :postgresql
recipe_name "client"
gem_binary "/opt/chef/embedded/bin/gem"
end


================================================================================
Recipe Compile Error in /tmp/chef-solo/cookbooks/postgresql/recipes/server.rb
================================================================================

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
gem_package[pg] (postgresql::client line 42) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" ----
STDOUT: Building native extensions. This could take a while...
STDERR: ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

/opt/chef/embedded/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/chef/embedded/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib


Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/pg-0.14.1 for inspection.
Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/pg-0.14.1/ext/gem_make.out
---- End output of /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" ----
Ran /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" returned 1

Cookbook Trace:
---------------
/tmp/chef-solo/cookbooks/postgresql/recipes/client.rb:44:in `from_file'
/tmp/chef-solo/cookbooks/postgresql/recipes/server.rb:24:in `from_file'

Relevant File Content:
----------------------
/tmp/chef-solo/cookbooks/postgresql/recipes/client.rb:

37: package pg_pack do
38: action :nothing
39: end.run_action(:install)
40: end
41:
42: gem_package "pg" do
43: action :nothing
44>> end.run_action(:install)
45:

[2012-10-29T16:15:03+11:00] ERROR: Running exception handlers
[2012-10-29T16:15:03+11:00] ERROR: Exception handlers complete
[2012-10-29T16:15:03+11:00] FATAL: Stacktrace dumped to /tmp/chef-solo/chef-stacktrace.out
[2012-10-29T16:15:03+11:00] FATAL: Mixlib::ShellOut::ShellCommandFailed: gem_package[pg] (postgresql::client line 42) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" ----
STDOUT: Building native extensions. This could take a while...
STDERR: ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

/opt/chef/embedded/bin/ruby extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/opt/chef/embedded/bin/ruby
--with-pg
--without-pg
--with-pg-dir
--without-pg-dir
--with-pg-include
--without-pg-include=${pg-dir}/include
--with-pg-lib
--without-pg-lib=${pg-dir}/lib
--with-pg-config
--without-pg-config
--with-pg_config
--without-pg_config
--with-pqlib
--without-pqlib
--with-libpqlib
--without-libpqlib
--with-ms/libpqlib
--without-ms/libpqlib


Gem files will remain installed in /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/pg-0.14.1 for inspection.
Results logged to /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/pg-0.14.1/ext/gem_make.out
---- End output of /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" ----
Ran /opt/chef/embedded/bin/gem install pg -q --no-rdoc --no-ri -v "0.14.1" returned 1

最佳答案

最简单的解决方案是更新您本地的 postgresql 说明书。您观察到的问题已在最新版本的 Recipe 中得到修复(所有版本 >= 1.0.0)。

现在他们是怎么解决的?首先,您会注意到客户端配方被拆分为 client.rbruby.rb。前者只安装操作系统包,后者安装 Ruby gem,供后续 Chef 运行使用。如您所见,该 gem 的安装需要先安装构建要素。这是由 build-essential 使用的新属性控制的名为 node['build-essential']['compile_time'] 的 Recipe 。这确保在编译时安装所需的包,即直接在包含 build-essential 配方时安装。

要理解为什么这很重要,您必须了解一点 Anatomy of a Chef Run ,即执行配方源代码和构建用于稍后转换的资源集合时的编译时间与执行资源以将系统移向预期状态的后续收敛之间的差异。

通常,大多数实际更改是在收敛阶段完成的。然而,有时有必要在编译阶段之前构建一些东西,以便能够使用它来决定要定义哪些资源,就像这里的情况一样。当我们这么早安装到 pg gem 时,我们可以使用它来尽早与数据库对话,例如决定是否创建数据库。

关于ruby - Chef 独奏 : Installing build-essential recipe before postgresql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13116282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com