Vagrant是否会改变我的变化?

时间:2014-12-29 17:33:45

标签: ssh vagrant vagrantfile

我们最近遇到了一些流浪问题,我一直试图修复它们。我现在迷路了,但是当我运行vagrant destroy然后vagrant up时,配置将在我们的脚本结束时失败。这个错误是我最初想要解决的问题。然而,当我带着vagrant ssh进入机器时,我现在要求输入密码(从未在1.6.3上询问,这是1.7.1),这是" vagrant"然后我刚刚提供的任何东西都没有。 Rbenv,红宝石一切都没了。我有一个简单的mkdir -p /home/vagrant/sphinx在错误之前运行,并且该目录不存在!是否有一些我不知道的Vagrant回滚功能?我甚至不确定从哪里开始尝试解决这个问题。

  • Vagrant:1.7.1
  • 主机操作系统:Mac OS X 10.10.1
  • 客户:Ubuntu 14.04.1

Vagrant档案

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "ubuntu/trusty64"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.network :private_network, ip: (ENV["VAGRANT_IP"] || "192.168.33.10")

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  config.vm.network :public_network

  # If true, then any SSH connections made will enable agent forwarding.
  # Default value: false
  config.ssh.forward_agent = true

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  config.vm.synced_folder ".", "/vagrant", nfs: true

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id, "--memory", "2048"]
  end

  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline <<-SHELL
  #   sudo apt-get install apache2
  # SHELL

  config.vm.provision :shell, path: "config/provision.sh"
end

provision.sh

set -e # Exit on first error
set -x # Print commands and their arguments as they are executed

# For postgresql-9.3-pgextwlist
set +e
grep "deb http://apt.postgresql.org/pub/repos/apt/ trusy-pgdg main" /etc/apt/sources.list.d/postgresql.list
if [[ $? -ne 0 ]]; then
  wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | \
  sudo apt-key add -

  sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
fi
set -e

apt-get -qy update

cat <<PACKAGES | xargs apt-get -qy install
apache2-threaded-dev
build-essential
curl
git
imagemagick
libcurl4-openssl-dev
libicu52
libmysqlclient-dev
libpq-dev
libqt4-dev
libreadline-dev
libsqlite3-dev
libxml2-dev
libxslt-dev
nfs-common
nodejs
openjdk-7-jre
postgresql-9.3
postgresql-contrib-9.3
postgresql-9.3-pgextwlist
qt4-qmake
redis-server
sphinxsearch
wkhtmltopdf
xvfb
vim
zsh
PACKAGES

# Postgres whitelisting
set +e
grep pgextwlist /etc/postgresql/9.3/main/postgresql.conf
if [[ $? -ne 0 ]]; then
  cat >> /etc/postgresql/9.3/main/postgresql.conf <<POSTGRES_CONFIG
local_preload_libraries = 'pgextwlist'
extwlist.extensions = 'hstore'
POSTGRES_CONFIG
fi
set -e

echo 'xvfb-run --server-args="-screen 0, 1024x768x24" /usr/bin/wkhtmltopdf $*' > /usr/bin/wkhtmltopdf.sh
chmod a+x /usr/bin/wkhtmltopdf.sh
ln -fs /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf

update-rc.d postgresql enable

set +e
service postgresql restart
set -e

# Create thinking sphinx directory
su - vagrant -l -c "mkdir -p /home/vagrant/sphinx"

echo Provisioning Powderhook User Environment...
su - vagrant -l -c 'test -d ~/.rbenv/ || git clone https://github.com/sstephenson/rbenv.git ~/.rbenv'

su - vagrant -l -c "cat > /home/vagrant/.bash_profile" <<'EOF'
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
cd /vagrant
EOF

su - vagrant -l -c 'test -d ~/.rbenv/plugins/ruby-build || git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build'
su - vagrant -l -c 'rbenv rehash'
su - vagrant -l -c 'test -d ~/.rbenv/versions/2.1.4 || rbenv install -v 2.1.4'
su - vagrant -l -c 'rbenv rehash'
su - vagrant -l -c 'rbenv global 2.1.4'
su - vagrant -l -c 'rbenv rehash'
su - vagrant -l -c 'gem update --system'
su - vagrant -l -c 'gem install bundler'
su - vagrant -l -c 'gem install debugger-ruby_core_source'
su - vagrant -l -c 'gem install foreman'
su - vagrant -l -c 'cd /vagrant && cp config/database.yml.pg config/database.yml'
su - vagrant -l -c 'cd /vagrant && cp .env.sample .env'
su - vagrant -l -c 'cd /vagrant && bundle install'
su - vagrant -l -c 'cd /vagrant && bundle exec rake db:migrate'
su - vagrant -l -c 'cd /vagrant && bundle exec rake test:prepare'
su - vagrant -l -c 'cd /vagrant && bundle exec rake ts:configure'
# This really should be a migration
su - vagrant -l -c 'cd /vagrant && bundle exec rake permalinked_urls:run_all'
su - vagrant -l -c 'cd /vagrant && bundle exec rake db:seed'
su - vagrant -l -c 'cd /vagrant && bundle exec rake ts:rebuild'

# Install bower and other necessities for testing JavaScript
su - vagrant -l -c 'cd /vagrant && chown vagrant node_modules'
su - vagrant -l -c 'cd /vagrant && sudo npm install -g grunt-cli'
su - vagrant -l -c 'cd /vagrant && sudo npm install -g grunt-mocha'
su - vagrant -l -c 'cd /vagrant && sudo npm install -g phantomjs'
su - vagrant -l -c 'cd /vagrant && sudo npm cache clean'
su - vagrant -l -c 'cd /vagrant && sudo npm install'

echo "Provisioning is complete"

脚本在su - vagrant -l -c 'cd /vagrant && bundle exec rake ts:rebuild'上失败。在此安装失败之前,已经安装了rbenv,安装了ruby,设置了.bash_profile,创建了/home/vagrant中的sphinx目录。当我接着进入ssh时,这些都不存在。

屏幕截图显示ruby在某些时候正在运行并运行rails迁移

Screenshot showing that at some point ruby was working and running rails migrations

Rbenv不再存在!

Rbenv is no longer there!

0 个答案:

没有答案