Run "nginx restart" automatically after "vagrant up" has completed

755 views
Skip to first unread message

James Newton

unread,
Sep 12, 2017, 5:07:33 AM9/12/17
to Vagrant
Hello Vagrant experts!

In this thread I asked how to copy the nginx folder out to Vagrant project folder, so that I can edit the server block definitions from the comfort of the host machine.

It turns out that, if I do this, when I run `vagrant up`, nginx starts, but fails to initialize the sites (presumably because the contents of the nginx folder is changed by Vagrant after nginx has loaded). The short term solution is to run...

vagrant ssh
sudo service nginx restart

... after `vagrant up`.

My question is: Is there a way to automate this restart of nginx? 

Can this be done through an entry in the Vagrantfile? Or would it be cleaner to set up a script that will run automatically on the guest server, and if so what would this script be and how would it be run?

Thanks in advance for all your enlightenment,

James

Alvaro Miranda Aguilera

unread,
Sep 13, 2017, 3:29:51 AM9/13/17
to vagra...@googlegroups.com
Sure.


Vagrant.configure("2") do |config|
  config.vm.provision "shell", run: "always", inline: "service nginx restart"
end

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/984f1523-3327-4ec4-b8cc-8ebb5a220ce3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

James Newton

unread,
Sep 13, 2017, 3:38:37 AM9/13/17
to Vagrant
Thanks Alvaro!  That works perfectly.

Alvaro Miranda Aguilera

unread,
Sep 13, 2017, 6:34:51 AM9/13/17
to Vagrant
hello

can you share your project in github? perhaps all can be incorporated into the same script

Alvaro

On Wednesday, September 13, 2017 at 9:38:37 AM UTC+2, James Newton wrote:
Thanks Alvaro!  That works perfectly.
Reply all
Reply to author
Forward
0 new messages