【问题标题】:Vagrant & Chef - Postgresql not starting on rebootVagrant & Chef - Postgresql 未在重新启动时启动
【发布时间】:2013-12-01 06:14:20
【问题描述】:

我决定创建自己的厨师脚本来安装 Postgres。安装工作正常,但是当我vagrant reload 时,postgres 没有在启动时启动

这是我的食谱/default.rb:

include_recipe "apt"

apt_repository 'apt.postgresql.org' do
  uri 'http://apt.postgresql.org/pub/repos/apt'
  distribution node["lsb"]["codename"] + '-pgdg'
  components ['main', node["postgres"]["version"]]
  key 'http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc'
  action :add
end

package 'postgresql-' + node["postgres"]["version"] do
    action  :install
end

file "/etc/postgresql/#{node['postgres']['version']}/main/postgresql.conf" do
    action  :delete
end

link "/etc/postgresql/#{node['postgres']['version']}/main/postgresql.conf" do
    to      node["postgres"]["conf_path"]
    action  :create
    notifies :reload, "service[postgresql]", :delayed
end

service "postgresql" do
    action [:enable, :start]
    supports :status=>true, :restart=>true, :start => true, :stop => true, :reload=>true
end

这是我的属性/default.rb:

default["postgres"]["version"] = "9.3"
default["postgres"]["conf_path"] = "/home/vagrant/postgres/postgresql.conf"

任何帮助将不胜感激!

============ 编辑 1 ============

这是第一次使用chef.log_level = :debug 运行vagrant up 时的输出:http://pastebin.com/w8Lp8gzv

这里是/etc/init.d/postgresql:http://pastebin.com/dQ5Zb1yj

这里是/var/log/postgresql/postgresql-9.3-main.log:http://pastebin.com/0Y2RhWvL

============ 编辑 2 ============

我现在相当有信心这是我的 postgresql.conf 文件,它看起来像:http://pastebin.com/rjX89iU0

shared_buffers 可能太高了...

【问题讨论】:

  • 请指定操作系统。如果可能,请指向 basebox 的 URL。将chef.log_level = :debug 添加到Vagrantfile 可能会为问题提供更多线索。
  • 另外,在重新加载 Vagrant VM 后,您可以通过 service postgresql start 手动启动 postgresql 吗?
  • 我正在使用config.vm.box_url = "http://files.vagrantup.com/precise64.box"
  • 我可以通过运行service postgresql start手动启动 Postgres
  • 很奇怪。我使用您提供的代码和框重新创建了您的场景。 Postgres 安装后可以正常启动,但如果我发出 service postgresql start 重新加载,则会引发此错误:* No PostgreSQL clusters exist; see "man pg_createcluster" 并且无法启动。

标签: postgresql chef-infra vagrant upstart init.d


【解决方案1】:

当您运行vagrant reload 时,Chef Client 是否正在运行?我怀疑不是。 Mitchell 将最近版本的 vagrant 中的行为更改为仅在尚未配置机器时进行配置。此信息存储在您工作目录的.vagrant 目录中。简而言之,由于您已经使用 vagrant up 配置了您的计算机,所以当您运行 vagrant reload 时它没有配置。

  1. 您运行 vagrant up - 这实际上将运行 vagrant up --provision,它在节点上执行 Chef Client provisioner,执行您的 Chef Recipe。
  2. 您运行vagrant reload - 这实际上运行vagrant up --no-provision,因为.vagrant. 目录表明机器已经被配置。因此,您的机器重新启动,但未执行 Chef Client 配置程序。

解决方案

使用--provision 标志运行vagrant reload

vagrant reload --provision

注意事项

这仍然不能解释为什么 upstart(或您用来确保 postgres 服务在启动时运行的任何东西)没有为您自动启动服务器。为了回答这个问题,我需要查看更多信息。您可以在Vagrantfile 中设置chef.log_level = :debug 并使用输出更新您的问题吗?查看此 postgres 安装程序创建的 init.d 脚本以及来自 /var/log 的与 postgres 相关的任何日志输出也会很有帮助。

【讨论】:

  • @user1161657 我认为问题出在您的 init.d 文件上,我不是这方面的专家。出于某种原因,postgres 服务未在启动时启动,这超出了您发布的 Chef 食谱的范围。
  • 对如何进一步调试有什么建议吗?
【解决方案2】:

好吧,看起来 Postgresql 不能很好地使用 postgresql.conf 作为符号链接。复制文件就可以了。

【讨论】:

  • 我可以建议您使用official postgresql cookbook 吗?它写得很好,应该可以很好地涵盖您的用例。
  • 我的用例需要使用预定义的postgresql.conf,否则我会:/
【解决方案3】:

原来 postgresql 是在 postgersql.conf 文件被挂载之前启动的

【讨论】:

    【解决方案4】:

    如果您使用 Upstart 启动的服务依赖于 Vagrant 共享文件夹中的某些内容,请让您的 upstart conf 文件监听 vagrant-mounted 事件。

    # /etc/init/start-postgresql.conf
    start on vagrant-mounted
    
    script
      # commands to start postgresql...
    end script
    

    vagrant-mounted 事件在 Vagrant 完成设置共享文件夹后发出,这样您就可以在 vagrant reload 之后重新启动依赖服务,而无需再次运行您的配置器。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-13
      • 2013-08-08
      • 1970-01-01
      • 2011-10-02
      • 2015-05-05
      • 1970-01-01
      • 2016-11-19
      相关资源
      最近更新 更多