nginx on vagrant box doesn't start automatically

1

I've set up a vagrant box with this vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
  config.vm.box = "puphpet/debian75-x64"

  config.vm.synced_folder "../.", "/kweetet", id: "vagrant-root",
    owner: "vagrant",
    group: "www-data",
    mount_options: ["dmode=777,fmode=777"]

  config.vm.network "forwarded_port", guest: 80, host: 8080

  # install packages
  config.vm.provision "chef_solo" do |chef|
    chef.cookbooks_path = ["./cookbooks", "./dk_cookbooks"]
    chef.add_recipe "nginx"
    chef.json = {
      "nginx" => {
        "init_style" => "upstart"
      }
    }
  end
end

When I vagrant up the machine for the first time, the nginx service is started automatically, because the provisioning is executed. But when I halt the machine and up it again, I have to manually start the nginx server.

So my question is: how to configure my nginx recipe so it starts nginx automatically on system startup?

UPDATE

I've included this in a custom recipe as suggested bu Tejay but it doesn't work:

# make a daemon for nginx
service 'nginx' do
  action :enable
end

When I halt my machine and reboot it, nginx isn't started automatically. My custom recipe is included in the vagrant runlist, and I'm sure it is run correctly, because other actions in it, run well.

Any ideas?

Ernie

Posted 2015-01-19T15:44:03.463

Reputation: 153

Answers

0

You'll need to add a recipe to your runlist that will :enable the nginx service. The default nginx recipe for upstart will only :start it.

Tejay Cardon

Posted 2015-01-19T15:44:03.463

Reputation: 101

I tried that: I have included it in a custom recipe (see update above), but it doens't help. When I halt my vagrant box and 'up' it again, nginx isn't started automatically – Ernie – 2015-01-22T09:02:22.977

0

Strange, but when I put it like this in my custom recipe, it works:

service 'nginx' do
    action [ :enable, :start ]
end

I thought setting the :enable action alone, was sufficient to start the server on boot

Ernie

Posted 2015-01-19T15:44:03.463

Reputation: 153

It should be. Try a minimal test case. If you can have a recipe that ONLY does the :enable on the nginx service, and nothing else, and you still see this issue, then you should file a bug with the nginx cookbook. – Tejay Cardon – 2015-01-22T14:20:29.307