Yami Medina
Yami Medina

Reputation: 670

How to start already-provisioned Vagrant box without losing data

I get this error whenever I try to start my vagrant box with vagrant up (on Mac OSX) without the --provision flag:

==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

I'm able to ssh into the vagrant box, but I can't access the web server.

The box starts and I can access the server when I run vagrant up --provision, but that deletes all the data from each session.

The problem occurs after entering vagrant halt and trying to start the box again with vagrant up. It doesn't happen when entering vagrant up after vagrant destroy, but destroy also gets rid of all the databases, etc. so I want another option. Does anyone have suggestions?

I'm using an existing repo with its own Vagrantfile. The project uses Ruby on Rails and Sqlite3.

Edit: link to vagrantfile

Upvotes: 3

Views: 9887

Answers (2)

zachee
zachee

Reputation: 167

Running vagrant destroy, and then restart by running vagrant up solved my issue.

Upvotes: 1

Frederic Henri
Frederic Henri

Reputation: 53713

The issue is that your provisioning launches rails command but after its not persisting so when you restart the VM this command does not run and rails does not launch, You could for example add the command in a cron job to make sure it starts automatically.

But to keep things simple, you can add the following provisioner to start rails every time you boot the VM

  config.vm.provision :shell, privileged: false, run: "always", inline: %(
    cd /vagrant/
    bundle exec unicorn_rails -D
    sudo service nginx restart
  )

Upvotes: 2

Related Questions