Question

I decided to create my own chef script to install Postgres. The installation works perfectly fine, but postgres doesn't start on boot when I vagrant reload

Here's my recipes/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

And here's my attributes/default.rb:

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

Any help would be greatly appreciated!!

============ EDIT 1 ============

Here is the output when running vagrant up for the first time with chef.log_level = :debug: http://pastebin.com/w8Lp8gzv

Here is /etc/init.d/postgresql: http://pastebin.com/dQ5Zb1yj

Here is /var/log/postgresql/postgresql-9.3-main.log: http://pastebin.com/0Y2RhWvL

============ EDIT 2 ============

I'm now fairly confident that it's my postgresql.conf file, which looks like: http://pastebin.com/rjX89iU0

shared_buffers might be too high...

Was it helpful?

Solution 3

Turns out the postgresql was starting before the postgersql.conf file was mounted

OTHER TIPS

When you run vagrant reload, is the Chef Client running? I suspect not. Mitchell changed the behavior in a recent version of vagrant to only provision if the machine hasn't already been provisioned. This information is stored in the .vagrant directory in your working directory. In short, since you already provisioned your machine with vagrant up, it is not provisioned when you run vagrant reload.

  1. You run vagrant up - this is actually going to run vagrant up --provision, which executes the Chef Client provisioner on the node, executing your Chef Recipe.
  2. You run vagrant reload - this actually runs vagrant up --no-provision, because the .vagrant. directory indicates the machine has already been provisioned. So your machine is rebooted, but the Chef Client provisioner is not executed.

Solution

Run vagrant reload with the --provision flag

vagrant reload --provision

Notes

This still doesn't explain why upstart (or whatever you're using to ensure the postgres service is running at boot) isn't starting the server for your automatically. In order to answer that question, I'll need to see more information. Can you set the chef.log_level = :debug in your Vagrantfile and update your question with the output? It would also be helpful to see the init.d script this postgres installer creates, and any log output from /var/log related to postgres.

Alright, it looks like Postgresql doesn't play nice with postgresql.conf being a symbolic link. Copying the file instead did the trick.

If you're starting services with Upstart that depend on something in Vagrant's shared folders, have your upstart conf file listen for the vagrant-mounted event.

# /etc/init/start-postgresql.conf
start on vagrant-mounted

script
  # commands to start postgresql...
end script

The vagrant-mounted event is emitted after Vagrant is done setting up shared folders, this way you can restart dependent services after vagrant reload without having to run your provisioners again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top