4

I have recently started developing a little with vagrant and django in a vm.

To get my machine up I use vagrant up, and to destroy it I use vagrant down.

Both of these commands are time-consuming as hell, but I often need to change my source code on the django side of things, like, for example, my views.py file might need to have something added to it.

While I have SSH'd into the vm through vagrant ssh, I call run and the server is put up, but if I change a source file, and just reload the webpage, is that OK? Or should I exit the ssh, and re-provision or reload my vm?

3 Answers3

3

I think you have some misunderstanding and the correct answer (from the outside view) depends on your exact setup.

  • The process of destroying a box (VM) is triggered through vagrant destroy. This throws all data away. In your case, you shut the VM down (using vagrant down).
  • As you tagged this post with chef, it seems that your server is provisioned through Chef and also the whole stack to run Django on it, isn't it?
  • If your chef recipes are written correctly (or: with the intention to update your application), running a provisioning will update your code in the VM. In older Vagrant versions (IIRC <1.3), provisioning is done at vagrant reload. In newer versions, you would have to add the --provision option, however this isn't even needed. To trigger a chef run, just call vagrant provision. This just kicks off chef without reloading the whole box (which is, if your chef recipes are correct, not needed at all).
  • The frequently used phrase "if your chef recipes are correct" means that the recipes should, of course, do what is needed to not only bring the code changes into the box, but also to do the necessary things to make them active (flushing caches, restarting services, etc.). But that depends a lot.. I would say on Django. If such things are missing, the down/up might have helped you just because it e.g. stopped and started Apache (after the reboot).
  • You would just have to make sure that the same thing that you now run by hand via SSH is also triggered by the Chef recipe.

I'm not sure, where the run command is coming from. I couldn't find anything related to Django.

Without further code it's thus hard to give you detailed hints.

But provisioning your code into the VM and reloading things is kind of exactly a use case for Vagrant.

0

While developing, you might also want to consider using synced folders if you're just updating a file.

config.vm.synced_folder "../code", "/home/vagrant/code"
exic
  • 519
0

Well, after an incredibly easy test, I have found that I can just edit the source code of any of my Django files, save the file, and refresh the webpage to see my result.

This is what I mean by "just refresh the webpage": browser before refresh

And after I edit, save, refresh browser page: browser after refresh

What I mean by "run" might be something specific to my cookbooks (I think that's why both StephenKing and I couldn't find anything about it). Here's what my terminal looked like over the course of this: My terminal

Hope that clarifies my answer.