簡體   English   中英

chef-solo:在postgresql之前安裝build-essential配方

[英]chef-solo: Installing build-essential recipe before postgresql

我正在嘗試使用chef-solo在我的服務器上安裝postgresql。 我通過自己做引導程序並在腳本中手動包含build-esential包來完成這項工作。 現在我想使用knife-solo來處理引導,我在定義執行配方的順序時遇到了問題。

我想在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 cookbook。 您觀察到的問題已在最近版本的cookbook中修復(所有版本> = 1.0.0)。

現在他們是如何解決的? 首先,您會注意到客戶端配方已分解為client.rbruby.rb 前者只是安裝操作系統包,后者是Ruby gem,用於后續的Chef運行。 正如您所觀察到的那樣,安裝該gem需要先安裝build-essentials。 這是由build-essential cookbook使用的一個名為node['build-essential']['compile_time']的新屬性控制的。 這確保在編譯期間安裝所需的包,即直接在包含構建必需配方時。

要理解為什么這很重要,你必須要了解一下Chef Run剖析 ,即執行配方源代碼的編譯時間與后續轉換的資源集合的構建時間和后續收斂之間的差異執行資源以將系統移向預期狀態的位置。

通常,大多數實際變化是在收斂階段完成的。 然而,有時需要在編譯階段之前構建一些東西,以便能夠使用它來確定哪些資源與此處的情況完全一致。 當我們盡早安裝到pg gem時,我們可以使用它早期與數據庫通信,例如決定是否創建數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM