Take the 2-minute tour ×

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

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

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

    to      node["postgres"]["conf_path"]
    action  :create
    notifies :reload, "service[postgresql]", :delayed

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

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...

share|improve this question
Please specify operating system. If at all possible, point to the basebox's URL. Adding chef.log_level = :debug to the Vagrantfile might give more clues to the problem. –  cassianoleal Nov 18 '13 at 16:27
Also, after reloading the Vagrant VM, can you start postgresql manually via service postgresql start? –  cassianoleal Nov 18 '13 at 16:29
I'm using config.vm.box_url = "http://files.vagrantup.com/precise64.box" –  user1161657 Nov 18 '13 at 17:40
I can start Postgres manually by running service postgresql start –  user1161657 Nov 18 '13 at 17:40
Weird. I recreated your scenario using the code and box you provided. Postgres starts just fine after installation, but after a reload if I issue service postgresql start it throws this error: * No PostgreSQL clusters exist; see "man pg_createcluster" and does not start. –  cassianoleal Nov 18 '13 at 21:56
show 1 more comment

4 Answers

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.


Run vagrant reload with the --provision flag

vagrant reload --provision


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.

share|improve this answer
Updated original post with more information –  user1161657 Nov 18 '13 at 18:11
@user1161657 I think the problem is with your init.d file, which I'm not an expert on. For some reason, the postgres service is not starting on boot, and that's outside of the scope of the Chef recipe you posted. –  sethvargo Nov 18 '13 at 18:18
Any suggestions on how to debug further? –  user1161657 Nov 19 '13 at 6:59
add comment

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

share|improve this answer
May I suggest you use the official postgresql cookbook? It's very well written and should cover for your use case just fine. –  cassianoleal Nov 19 '13 at 9:41
My usecase needs to use a predefined postgresql.conf, otherwise I would :/ –  user1161657 Nov 19 '13 at 18:09
add comment
up vote 0 down vote accepted

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

share|improve this answer
add comment

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

  # 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.

share|improve this answer
add comment

Your Answer


