I have Vagrant + VirtualBox.
In my Vagrantfile I have
config.vm.provider "virtualbox" do |v|
v.customize [ "createhd", "--filename", "disk", "--size", 100000 ]
v.customize [ 'storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', "disk"]
end
When I fire up with vagrant up it looks for "disk" in
C:\HashiCorp\Vagrant\bin\disk
VBoxManage.exe: error: Could not find file for the medium 'C:\HashiCorp\Vagrant\bin\disk' (VERR_FILE_NOT_FOUND)
I would like the disk to live alongside the virtual machine's first disk in
C:\Users\jma47\VirtualBox VMs\bin_build_1389371691
How can I do this in Vagrantfile?
This can be done if you define a name for virtual machine:
# Try to make it work on both Windows and Linux
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
vboxmanage_path = "C:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe"
else
vboxmanage_path = "VBoxManage" # Assume it's in the path on Linux
end
Vagrant.configure(2) do |config|
config.vm.box = "debian/wheezy64"
config.vm.provider "virtualbox" do |vb|
vb.name = "VM Name"
# Get disk path
line = `"#{vboxmanage_path}" list systemproperties`.split(/\n/).grep(/Default machine folder/).first
vb_machine_folder = line.split(':', 2)[1].strip()
second_disk = File.join(vb_machine_folder, vb.name, 'disk2.vdi')
# Create and attach disk
unless File.exist?(second_disk)
vb.customize ['createhd', '--filename', second_disk, '--format', 'VDI', '--size', 60 * 1024]
end
vb.customize ['storageattach', :id, '--storagectl', 'IDE Controller', '--port', 0, '--device', 1, '--type', 'hdd', '--medium', second_disk]
end
end
You need to use something like this in your Vagrantfile:
For Vagrant API v1:
# Where to store the disk file
disk = 'C:\Users\jma47\VirtualBox VMs\bin_build_1389371691\extra_disk.vdi'
Vagrant::Config.run do |config|
config.vm.box = 'base'
config.vm.provider "virtualbox" do | v |
unless File.exist?(disk)
config.vm.customize ['createhd', '--filename', disk, '--size', 500 * 1024]
end
config.vm.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
end
end
For Vagrant API v2:
# Where to store the disk file
disk = 'C:\Users\jma47\VirtualBox VMs\bin_build_1389371691\extra_disk.vdi'
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'base'
config.vm.provider "virtualbox" do | p |
unless File.exist?(disk)
p.customize ['createhd', '--filename', disk, '--size', 1 * 1024]
end
p.customize ['storageattach', :id, '--storagectl', 'SATA Controller', '--port', 1, '--device', 0, '--type', 'hdd', '--medium', disk]
end
end
The "disk" parameter should be a path, Virtualbox needs it to store the second disk.
Use an absolute one like "c:\temp.disk" or "/tmp/disk.img"
Related
I am implementing griddler(using Mandrill) to fetch e-mail in my app.
This is my class to receive mail
#app/email_receivers/incoming.rb
class EmailReceiver < Incoming::Strategies::Mandrill
def receive(mail)
%(Got message from #{mail.to.first} with subject "#{mail.subject}")
end
end
req = Rack::Request.new(Rails.env)
result = EmailReceiver.receive(req)
This is my rails controller that calls receive method of EmailReceiver class.
#emails_controller.rb
class EmailsController < ActionController::Base
def create
if EmailReceiver.receive(request)
render :json => { :status => 'ok' }
else
render :json => { :status => 'rejected' }, :status => 403
end
end
end
Routes for calling create method of EmailsController
#routes.rb
Rails.application.routes.draw do
post '/emails' => 'emails#create'
end
Note:- After running server in production environment
rails s -e production
I got this error
/home/bvc-2/.rvm/gems/ruby-2.2.1/gems/rack-1.6.4/lib/rack/request.rb:192:in `[]=': string not matched (IndexError)
Where "puts req" in
req = Rack::Request.new(Rails.env)
turns out to be:
#<Rack::Request:0xc3bace8 #env="production">
And my config/application.rb file is:-
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
ActionMailer::Base.smtp_settings = {
:address =>"smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "***#gmail.com",
:password => "pass*******",
:authentication => 'plain',
:enable_starttls_auto => true
}
module ComplaintSystem
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
config.active_job.queue_adapter = :delayed_job
config.time_zone = 'Mumbai'
config.active_record.default_timezone = :local
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
This type of error happens when you try to access a string variable as a Hash by mistake.
s = "hello world"
s["position"] = "programming is fun"
# > IndexError: string not matched
# > from (irb):5:in `[]='
# > from (irb):5
Look at your full stack trace and see where you are trying to do such operation.
I am trying to get my ENV variables in production mode ...
but now way .. cannot reach the server ... the SECRET_KEY_BASE is not found ... if I hardcode it , then go trouble w the database creds, and if I hardcode them, got trouble w the SMTP creds...
this means that no ENV[] variables cannot be reached ...
I added the gemfile to get it in :production environment, and bundled it
gem 'dotenv-rails', :groups => [:development, :test, :staging, :production]
my .env file is present in my remote server ( Ubuntu 14 - w .rbenv Ruby 2.0 , Rais 4.2 )
cat /var/www/workshop/shared/.env
SECRET_KEY_BASE=106063d5146566142b6aa4782b874115c73a61ac2505f11f8e
DATABASE_USER_NAME=myself
DATABASE_PASSWORD=mydbpwd
MAILGUN_SMTP_SERVER=smtp.mailgun.org
MAILGUN_SMTP_USER_NAME=postmaster#mydomain.com
MAILGUN_SMTP_PASSWORD=2fc998a7399999999a264b88c
MAILGUN_SMTP_DOMAIN=mydomain.com
I set my secrets.yml file on the remote server
cat secrets.yml
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
I set my database.yml
cat database.yml
production:
adapter: postgresql
database: workshop
encoding: unicode
pool: 5
username: <%= ENV['DATABASE_USER_NAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
and I updated my config/environments/production.rb w smtp creds
cat production.rb
.....
# SMTP settings for mailgun
config.action_mailer.smtp_settings = {
:port => 587,
:address => ENV['MAILGUN_SMTP_SERVER'],
:user_name => ENV['MAILGUN_SMTP_USER_NAME'],
:password => ENV['MAILGUN_SMTP_PASSWORD'],
:domain => ENV['MAILGUN_SMTP_DOMAIN'],
:authentication => :plain,
:enable_starttls_auto => true
}
...
Finally I gave up w .dotenv in production...
I resolved using Rails 4.1 secrets.yml...
as I am deploying w capistrano 3 ,
- I use the gem capistrano-upload-config
- I created : secrets.production.yml , database.production.yml, configuration.production.yml
- I added in my capistrano deploy.rb
set :config_files, %w{config/database.yml config/secrets.yml config/application.yml}
set :linked_files, %w{config/database.yml config/secrets.yml config/application.yml}
capistrano uploads these productions files from the local .production files and link them... so
the server database.yml is loaded/linked (from local database.production.yml)
the server secrets.yml is loaded/linked (from local secrets.production.yml)
the server application.yml is loaded/linked (from local application.production.yml)
regarding the production.rb SMTP settings , I use the secrets file :
:address => Rails.application.secrets.mailgun_smtp_server,
...
all these files are in .gitignore
I have this in my Vagrantfile:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.memory = 2056
v.cpus = 2
end
end
I'm getting this:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
VirtualBox:
* The following settings don't exist: cpus, memory
However, these settings are listed explicitly in the vagrant documentation here: http://docs.vagrantup.com/v2/virtualbox/configuration.html
The first thing that I would do is check the version of Vagrant that you are using (vagrant -v). I believe that both of those shortcuts were added in version 1.5 but, it might have been 1.6. I would recommend upgrading to the latest version, 1.6.2.
If you would like to do this in a way that will work with all versions of Vagrant, you can do by specifying those values like this:
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--memory", "2048"]
v.customize ["modifyvm", :id, "--cpus", "2"]
end
end
I have an NFS share on my Vagrant VM. It works but it can't write files (Symfony2 app, needs to write to app/cache/prod/sessions).
If I use "non-NFS" shares it works, but is dog slow!
From within the guest VM, /var/www/fh-admin is owned by user 501 group root, which I assume is a user on my host OS (OSX)?
Here is my Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
#config.vm.network :private_network, ip: '192.168.33.12'
config.vm.network :private_network, ip: "101.0.0.101", :netmask => "255.255.0.0"
config.vm.boot_timeout = 60
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.provision :ansible do |ansible|
ansible.limit = 'all'
ansible.sudo = true
ansible.playbook = '../fh-ansible/fh.yml'
ansible.inventory_path = 'inventory.ini'
ansible.verbose = "v"
end
config.vm.synced_folder '.', '/var/www/fh-admin', :nfs => { :mount_options => ["dmode=777","fmode=666"] }
config.vm.synced_folder '/var/www/surveyor-cordova/assets/www', '/var/www/fhapp', :nfs => { :mount_options => ["dmode=777","fmode=666"] }
config.vm.provider :vmware do |vb|
vb.customize ["modifyvm", :id, "--memory", "2048"]
end
config.vm.provider "vmware_fusion" do |v|
v.vmx["memsize"] = "2048"
v.vmx["numvcpus"] = "2"
end
end
One option would be to not store session data within the NFS share. There's details on how to move it on this blog post by Benjamin Eberlei: http://www.whitewashing.de/2013/08/19/speedup_symfony2_on_vagrant_boxes.html. I think you can also specify the Symfony2 session dir independently though config if you don't want to go down that involved route.
Adapt this to your requirements:
config.vm.synced_folder "./", "/var/www/fh-admin", id: "unique-id", type: nil,
group: 'www-data', owner: 'www-data', mount_options: ["dmode=775", "fmode=764"]
This assumes the group/user www-data exists within the box you are using.
This will work for non-NFS, and as far as I am aware NFS does not accept those extra flags (per mitchellh)
Using rails 4.1 & 4.1.0rc2
We're having this weird issue with rendering:
I, [2014-04-13T07:45:28.856574 #5695] INFO -- : Started GET "/xpto" for xxx.xxx.xxx.xxx at 2014-04-13 07:45:28 +0000
I, [2014-04-13T07:45:28.916947 #5695] INFO -- : Processing by XptoController#index as HTML
D, [2014-04-13T07:45:28.952666 #5695] DEBUG -- : Cart Load (2.5ms) sql
D, [2014-04-13T07:45:29.000582 #5695] DEBUG -- : SQL (2.5ms) sql
D, [2014-04-13T07:45:29.004601 #5695] DEBUG -- : SQL (2.6ms) sql
I, [2014-04-13T07:45:29.026042 #5695] INFO -- : Rendered xpto/index.html.erb within layouts/application (58.4ms)
I, [2014-04-13T07:45:29.719445 #5695] INFO -- : Completed 200 OK in 802ms (Views: 735.2ms | ActiveRecord: 31.4ms)
As you can see in the log the render took 58.4ms but the "View" took 735.2ms. Every data is being preloaded and the view consists only of:
<h1>xptos</h1>
<% #xptos.each do |xpto| %>
<p>link: <%= link_to xpto.name, xptos_path(xpto) %> (ID: <%= xpto.id %>)</p>
<% end %>
The configurations used:
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.force_ssl = false
config.log_level = :debug
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
config.paperclip_defaults = {
storage: :fog,
fog_credentials: { provider: 'aws',
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
},
fog_directory: 'xpto-bucket'
}
end
Requests are being served directly by Unicorn with config:
log_path = 'log/unicorn.log'
pid_path = 'tmp/pids/unicorn.pid'
pid pid_path
worker_processes 8
timeout 15
preload_app true
listen 3000, backlog: 1025
stderr_path log_path
stdout_path log_path
before_fork do |server, worker|
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord)
end
after_fork do |server, worker|
ActiveRecord::Base.establish_connection if defined?(ActiveRecord)
end
Is there any way to debug what is taking so long after render but before returning the response?