Posts

Fixing the Vagrant Rename Directory Error

The other day one of our devs ran into a problem. They vagrant uped their VM and instead of a happy working VM they receive the following message:

Scotts-Air:ubuntu scottkeckwarren$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: ubuntu_default_1455929302562_42575
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
A customization command failed:

["modifyvm", :id, "--name", "BrokenVM"]

The following error was experienced:

#<Vagrant::Errors::VBoxManageError: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["modifyvm", "5b9eb013-65e0-4d4c-91f3-87b0fd19156a", "--name", "BrokenVM"]

Stderr: VBoxManage: error: Could not rename the directory '/Users/scottkeckwarren/VirtualBox VMs/ubuntu_default_1455929302562_42575' to '/Users/scottkeckwarren/VirtualBox VMs/BrokenVM' to save the settings file (VERR_ALREADY_EXISTS)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "SaveSettings()" at line 2788 of file VBoxManageModifyVM.cpp
>

Please fix this customization and try again.

Instead of booting the VM that already existed it created a new VM. When we looked at Virtual Box we saw that the old VM (BrokenVM in this example) still existed and the new vm (ubuntu_default_1455929302562_42575) had been created in error:

Image of both correct and incorrect vms

Vagrant uses a file to keep track of what VirtualBox VM it’s using. If you look in the “.vagrant/machines/default/virtualbox/” directory (“default” is the name of the Vagrant box so it might be different if you have multiple VMs) in the folder that contains your Vagrantfile you’ll see a file named “id”. This represents the VirtualBox ID of the VM it’s using. In my case it looks like this:

5b9eb013-65e0-4d4c-91f3-87b0fd19156a

Now we need to figure out what is the “correct” VM ID by using VBoxManage

Scotts-Air:ubuntu scottkeckwarren$ VBoxManage list vms
"BrokenVM" {cb533ed8-4267-4450-9955-b8b11add10b4}
"ubuntu_default_1455929302562_42575" {5b9eb013-65e0-4d4c-91f3-87b0fd19156a}

As you can see the second line refers to the ID of the newly created/wrong VM but the first line contains the correct VM. To fix this problem we just need to copy and paste the “cb533ed8-4267-4450-9955-b8b11add10b4” in the id file we looked at earlier.

Scotts-Air:ubuntu scottkeckwarren$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Mounting shared folders...
    default: /vagrant => /Users/scottkeckwarren/Projects/ubuntu

Because we’re using Vagrant it wouldn’t have been the end of the world if we had to reset the development box but this way the dev didn’t loose their test data.

On github/scientist

GitHub recently announced Scientist! and it allows you to refactor a piece of code that’s critical to your application so you can better “test” the change in production. I think it’s a great idea for those of us who are supporting legacy applications that need better tests.

The example on the GitHub projects page is a change in the permission system:

1
2
3
4
5
6
7
8
9
10
11
require "scientist"

class MyWidget
  def allows?(user)
    experiment = Scientist::Default.new "widget-permissions"
    experiment.use { model.check_user?(user).valid? } # old way
    experiment.try { user.can?(:read, model) } # new way

    experiment.run
  end
end

The important pieces of this are:

  • line 5 - defines the experiment’s name
  • line 6 - executes the old (control) way
  • line 7 - executes the new (experiment) way

It’s amazing how simple it is in it’s execution.

What about PHP?

I know what you’re saying, isn’t this in Ruby? Don’t you work in PHP? I do it just so happens the PHP community has created at LEAST two forks:

  1. daylerees/scientist
  2. aaronbieber/edison

daylerees/scientist seems to be the better maintained (based on # of commits, contributers, forks, etc.) so I would highly recommend you look at that project. I personally think edison is a great name for this but I’ll have to move past that. :-)

It’s example is much more generic but still helpful:

// We need a Laboratory to do science.
$experiment = (new Scientist\Laboratory)

    // Define an experiment with a name.
    ->experiment('experiment title')

    // Set a callback containing our control code.
    ->control($controlCallback)

    // Set a callback containing our trial code.
    ->trial('trial name', $trialCallback);

// Run the experiment, receiving the control return value.
$value = $experiment->run();

I have a project at work that requires me to refactor large sections of legacy (non-unit tested) code so I’ll be experimenting with this in the very near future.

Moved To Jekyll

A couple minutes ago I bit the bullet and switch the DNS settings for this blog. We’re now officially running on the new server.

Starting My Fifth Year Telecommuting

When I logged into Facebook recently I saw the following on my news feed:

errors

It’s hard to believe I’ve spend 4 years working remotely and I thought would take the time to look back at what’s worked and what’s been difficult.

Read More

Jekyll: Development vs Production Settings

When I work on this site I generally run through a quick check to see if the content looks like I want it too. The downside to using Google Analytics, AdSense, and Disqus is that it really slows down the total load time of a page. While it’s not a huge problem when the site is just loading once it’s a little annoying when I’m loading it 10+ times in a row and making small changes.

In order to get around this I can add the following around any code block I only want on my live server (production):

{% if jekyll.environment == 'production' %}
    Production only code 
{% endif %}

The bonus to this is that if you use Github Pages to generate the pages for you it automatically uses the production environment.

If you’re self hosting like me you’ll need to specify the environment when you build the page:

JEKYLL_ENV=production jekyll build

I added this to my deploy script and it’s working well.

Moving From Wordpress To Jekyll - Sitrep/annoyance

So hit a wall of busy last month which really limited the amount of time I could work on my migration. As of today, I’m not adding anything additional to my Wordpress installation and I’m think I’m ready to transition the site over. The goal is to get everything checked out this week and then switch the DNS on Sunday of next week (2016-02-07).

As I’ve worked with Jekyll I have run into a annoyance.

The way I work I write a couple posts at a time and then schedule the release so I have content regularly posted. There isn’t any easy way to do that with Jekyll. My quick solution would be to write a script the redeploys the site every hour but that seems very heavy handed. I’ll have to see if there’s a better way. Right now I’m just going to not worry about it and force myself to push whenever there’s scheduled posts.

Link Post and Podcast Roundup: February 2016 Edition

Links for February 2016

Read More

PHP Blocks in Jekyll

I use a lot of code blocks in my writing so I wanted to look at my options for how to format them now that I’m using Jekyll. Wordpress had me install extra plugins to get syntax highlighting.

Read More

Moving From Wordpress To Jekyll - Data Cleanup

Time to do some cleanup.

Read More

Fixing the No pdftotext Available Error With wkhtmltopdf in Ubuntu

We’re changing our infrastructure at work and moving from our old server(that isn’t well documented) to a new setup that is better documented and faster. As we’re doing this we’re finding odd problems that need to fixed. One of our processes uses wkhtmltopdf to convert some pages to PDF for reporting purposes. When we ran those processes on the new server the PDF file was corrupt and contained the string “No pdftotext Available”.

As an example, we ran the command and received the output below:

# wkhtmltopdf.11rc1 "https://site.com/example/" output.pdf
Loading pages (1/6)
QSslSocket: cannot call unresolved function SSLv23_client_method0%
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function ERR_get_error
Warning: Failed loading page https://site.com/example/ (ignored)
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
Done

I would think the “Failed loading page” error would have kept it from going but we are running an old version.

The fix was to install the libssl-dev package

apt-get install libssl-dev

And this fixed the errors and caused the PDF to generate correctly.

# wkhtmltopdf.11rc1 "https://site.com/example/" output.pdf
Loading pages (1/6)
QSslSocket: cannot resolve SSLv2_client_method               ] 10%
QSslSocket: cannot resolve SSLv3_client_method
QSslSocket: cannot resolve SSLv2_server_method
QSslSocket: cannot resolve SSLv3_server_method
Counting pages (2/6)
Resolving links (4/6)
Loading headers and footers (5/6)
Printing pages (6/6)
QPixmap: Cannot create a QPixmap when no GUI is being used===] Page 1 of 1
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
QPixmap: Cannot create a QPixmap when no GUI is being used
Done
RSS

Join Our Mailing List!

View previous campaigns.

Top Posts

  1. Working With Soft Deletes in Laravel (By Example)
  2. Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
  3. Upgrading to Laravel 8.x
  4. Get The Count of the Number of Users in an AD Group
  5. Multiple Vagrant VMs in One Vagrantfile
  6. Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
  7. Changing the Directory Vagrant Stores the VMs In
  8. Accepting Android SDK Licenses From The OSX Command Line
  9. Fixing the 'Target class [config] does not exist' Error
  10. Using Rectangle to Manage MacOS Windows

subscribe via RSS

All content copyright This Programming Thing 2012 - 2021
Blogging about PHP, MySQL, Zend Framework, MySQL, Server Administration and Programming in general