Advertisement
nabeel_molham

Vagrantfile - wordpress-vvv

Aug 3rd, 2014
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.65 KB | None | 0 0
  1. # -*- mode: ruby -*-
  2. # vi: set ft=ruby :
  3.  
  4. dir = Dir.pwd
  5. vagrant_dir = File.expand_path(File.dirname(__FILE__))
  6.  
  7. Vagrant.configure("2") do |config|
  8.  
  9.   # Store the current version of Vagrant for use in conditionals when dealing
  10.   # with possible backward compatible issues.
  11.   vagrant_version = Vagrant::VERSION.sub(/^v/, '')
  12.  
  13.   # Configurations from 1.0.x can be placed in Vagrant 1.1.x specs like the following.
  14.   config.vm.provider :virtualbox do |v|
  15.     v.customize ["modifyvm", :id, "--memory", 4096]
  16.     v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  17.     v.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
  18.   end
  19.  
  20.   # Forward Agent
  21.   #
  22.   # Enable agent forwarding on vagrant ssh commands. This allows you to use identities
  23.   # established on the host machine inside the guest. See the manual for ssh-add
  24.   config.ssh.forward_agent = true
  25.  
  26.   # increase ssh connection timeout
  27.   config.vm.boot_timeout = 600
  28.  
  29.   # show GUI
  30.   config.vm.provider :virtualbox do |vb|
  31.     vb.gui = true
  32.   end
  33.  
  34.   # Default Ubuntu Box
  35.   #
  36.   # This box is provided by Ubuntu vagrantcloud.com and is a nicely sized (332MB)
  37.   # box containing the Ubuntu 14.04 Trusty 64 bit release. Once this box is downloaded
  38.   # to your host computer, it is cached for future use under the specified box name.
  39.   config.vm.box = "ubuntu/trusty64"
  40.  
  41.   config.vm.hostname = "vvv"
  42.  
  43.   # Local Machine Hosts
  44.   #
  45.   # If the Vagrant plugin hostsupdater (https://github.com/cogitatio/vagrant-hostsupdater) is
  46.   # installed, the following will automatically configure your local machine's hosts file to
  47.   # be aware of the domains specified below. Watch the provisioning script as you may be
  48.   # required to enter a password for Vagrant to access your hosts file.
  49.   #
  50.   # By default, we'll include the domains setup by VVV through the vvv-hosts file
  51.   # located in the www/ directory.
  52.   #
  53.   # Other domains can be automatically added by including a vvv-hosts file containing
  54.   # individual domains separated by whitespace in subdirectories of www/.
  55.   if defined? VagrantPlugins::HostsUpdater
  56.  
  57.     # Capture the paths to all vvv-hosts files under the www/ directory.
  58.     paths = []
  59.     Dir.glob(vagrant_dir + '/www/**/vvv-hosts').each do |path|
  60.       paths << path
  61.     end
  62.  
  63.     # Parse through the vvv-hosts files in each of the found paths and put the hosts
  64.     # that are found into a single array.
  65.     hosts = []
  66.     paths.each do |path|
  67.       new_hosts = []
  68.       file_hosts = IO.read(path).split( "\n" )
  69.       file_hosts.each do |line|
  70.         if line[0..0] != "#"
  71.           new_hosts << line
  72.         end
  73.       end
  74.       hosts.concat new_hosts
  75.     end
  76.  
  77.     # Pass the final hosts array to the hostsupdate plugin so it can perform magic.
  78.     config.hostsupdater.aliases = hosts
  79.  
  80.   end
  81.  
  82.   # Default Box IP Address
  83.   #
  84.   # This is the IP address that your host will communicate to the guest through. In the
  85.   # case of the default `192.168.50.4` that we've provided, VirtualBox will setup another
  86.   # network adapter on your host machine with the IP `192.168.50.1` as a gateway.
  87.   #
  88.   # If you are already on a network using the 192.168.50.x subnet, this should be changed.
  89.   # If you are running more than one VM through VirtualBox, different subnets should be used
  90.   # for those as well. This includes other Vagrant boxes.
  91.   config.vm.network :private_network, ip: "192.168.50.4"
  92.  
  93.   # Drive mapping
  94.   #
  95.   # The following config.vm.synced_folder settings will map directories in your Vagrant
  96.   # virtual machine to directories on your local machine. Once these are mapped, any
  97.   # changes made to the files in these directories will affect both the local and virtual
  98.   # machine versions. Think of it as two different ways to access the same file. When the
  99.   # virtual machine is destroyed with `vagrant destroy`, your files will remain in your local
  100.   # environment.
  101.  
  102.   # /srv/database/
  103.   #
  104.   # If a database directory exists in the same directory as your Vagrantfile,
  105.   # a mapped directory inside the VM will be created that contains these files.
  106.   # This directory is used to maintain default database scripts as well as backed
  107.   # up mysql dumps (SQL files) that are to be imported automatically on vagrant up
  108.   config.vm.synced_folder "database/", "/srv/database"
  109.  
  110.   # If the mysql_upgrade_info file from a previous persistent database mapping is detected,
  111.   # we'll continue to map that directory as /var/lib/mysql inside the virtual machine. Once
  112.   # this file is changed or removed, this mapping will no longer occur. A db_backup command
  113.   # is now available inside the virtual machine to backup all databases for future use. This
  114.   # command is automatically issued on halt, suspend, and destroy if the vagrant-triggers
  115.   # plugin is installed.
  116.   if File.exists?(File.join(vagrant_dir,'database/data/mysql_upgrade_info')) then
  117.     if vagrant_version >= "1.3.0"
  118.       config.vm.synced_folder "database/data/", "/var/lib/mysql", :mount_options => [ "dmode=777", "fmode=777" ]
  119.     else
  120.       config.vm.synced_folder "database/data/", "/var/lib/mysql", :extra => 'dmode=777,fmode=777'
  121.     end
  122.   end
  123.  
  124.   # /srv/config/
  125.   #
  126.   # If a server-conf directory exists in the same directory as your Vagrantfile,
  127.   # a mapped directory inside the VM will be created that contains these files.
  128.   # This directory is currently used to maintain various config files for php and
  129.   # nginx as well as any pre-existing database files.
  130.   config.vm.synced_folder "config/", "/srv/config"
  131.  
  132.   # /srv/log/
  133.   #
  134.   # If a log directory exists in the same directory as your Vagrantfile, a mapped
  135.   # directory inside the VM will be created for some generated log files.
  136.   config.vm.synced_folder "log/", "/srv/log", :owner => "www-data"
  137.  
  138.   # /srv/www/
  139.   #
  140.   # If a www directory exists in the same directory as your Vagrantfile, a mapped directory
  141.   # inside the VM will be created that acts as the default location for nginx sites. Put all
  142.   # of your project files here that you want to access through the web server
  143.   if vagrant_version >= "1.3.0"
  144.     config.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :mount_options => [ "dmode=775", "fmode=774" ]
  145.   else
  146.     config.vm.synced_folder "www/", "/srv/www/", :owner => "www-data", :extra => 'dmode=775,fmode=774'
  147.   end
  148.  
  149.   # Customfile - POSSIBLY UNSTABLE
  150.   #
  151.   # Use this to insert your own (and possibly rewrite) Vagrant config lines. Helpful
  152.   # for mapping additional drives. If a file 'Customfile' exists in the same directory
  153.   # as this Vagrantfile, it will be evaluated as ruby inline as it loads.
  154.   #
  155.   # Note that if you find yourself using a Customfile for anything crazy or specifying
  156.   # different provisioning, then you may want to consider a new Vagrantfile entirely.
  157.   if File.exists?(File.join(vagrant_dir,'Customfile')) then
  158.     eval(IO.read(File.join(vagrant_dir,'Customfile')), binding)
  159.   end
  160.  
  161.   # Provisioning
  162.   #
  163.   # Process one or more provisioning scripts depending on the existence of custom files.
  164.   #
  165.   # provison-pre.sh acts as a pre-hook to our default provisioning script. Anything that
  166.   # should run before the shell commands laid out in provision.sh (or your provision-custom.sh
  167.   # file) should go in this script. If it does not exist, no extra provisioning will run.
  168.   if File.exists?(File.join(vagrant_dir,'provision','provision-pre.sh')) then
  169.     config.vm.provision :shell, :path => File.join( "provision", "provision-pre.sh" )
  170.   end
  171.  
  172.   # provision.sh or provision-custom.sh
  173.   #
  174.   # By default, Vagrantfile is set to use the provision.sh bash script located in the
  175.   # provision directory. If it is detected that a provision-custom.sh script has been
  176.   # created, that is run as a replacement. This is an opportunity to replace the entirety
  177.   # of the provisioning provided by default.
  178.   if File.exists?(File.join(vagrant_dir,'provision','provision-custom.sh')) then
  179.     config.vm.provision :shell, :path => File.join( "provision", "provision-custom.sh" )
  180.   else
  181.     config.vm.provision :shell, :path => File.join( "provision", "provision.sh" )
  182.   end
  183.  
  184.   # provision-post.sh acts as a post-hook to the default provisioning. Anything that should
  185.   # run after the shell commands laid out in provision.sh or provision-custom.sh should be
  186.   # put into this file. This provides a good opportunity to install additional packages
  187.   # without having to replace the entire default provisioning script.
  188.   if File.exists?(File.join(vagrant_dir,'provision','provision-post.sh')) then
  189.     config.vm.provision :shell, :path => File.join( "provision", "provision-post.sh" )
  190.   end
  191.  
  192.   # Always start MySQL on boot, even when not running the full provisioner
  193.   # (run: "always" support added in 1.6.0)
  194.   if vagrant_version >= "1.6.0"
  195.     config.vm.provision :shell, inline: "sudo service mysql restart", run: "always"
  196.   end
  197.  
  198.   # Vagrant Triggers
  199.   #
  200.   # If the vagrant-triggers plugin is installed, we can run various scripts on Vagrant
  201.   # state changes like `vagrant up`, `vagrant halt`, `vagrant suspend`, and `vagrant destroy`
  202.   #
  203.   # These scripts are run on the host machine, so we use `vagrant ssh` to tunnel back
  204.   # into the VM and execute things. By default, each of these scripts calls db_backup
  205.   # to create backups of all current databases. This can be overridden with custom
  206.   # scripting. See the individual files in config/homebin/ for details.
  207.   if defined? VagrantPlugins::Triggers
  208.     config.trigger.before :halt, :stdout => true do
  209.       run "vagrant ssh -c 'vagrant_halt'"
  210.     end
  211.     config.trigger.before :suspend, :stdout => true do
  212.       run "vagrant ssh -c 'vagrant_suspend'"
  213.     end
  214.     config.trigger.before :destroy, :stdout => true do
  215.       run "vagrant ssh -c 'vagrant_destroy'"
  216.     end
  217.   end
  218. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement