Pre-populate vagrant synced folder contents
Solution 1:
Vagrant's built-in provisioning features should be a perfect fit for this. There are a whole bunch of ways you could do it, but the simplest is probably to take the guts of your Upstart script and make them a plain shell script. Then, put one of these blocks in your Vagrantfile
:
-
Using an "inline" script. Vagrant will copy the contents from the
Vagrantfile
into a script in the/tmp
directory and execute it.$script = <<<SCRIPT // The contents of your script go here SCRIPT config.vm.provision "shell", inline: $script
Note that the script here is inside a "heredoc", which means that you need to be careful to make sure that the
SCRIPT
token which ends the heredoc is in the right place - i.e. on a line by itself, without extra whitespace. (The link about heredoc above does show a way to allow whitespace, but you need to be careful anyway.) -
Pointing to a script file. Vagrant will copy this file into the
/tmp
directory and execute it.config.vm.provision "shell", path: "setup.sh"
Note that the path here is relative to the
Vagrantfile
location. However, the file is not executed from that location, so if you need the file to be in a certain directory, you should follow method #3. -
Using an "inline" script that points to a script file. This way, you can execute a script in a chosen location (in the example below, that's in
/vagrant
after you have done prerequisites likechmod
or setting environment variables.$script = <<SCRIPT chmod +x /vagrant/setup.sh cd /vagrant ./setup.sh SCRIPT config.vm.provision "shell", inline: $script
You could also use a provisioning method that works through a "real" deployment and provisioning system, but depending on your requirements that may be overkill.