Slightly Ahead of Behind the Curve

Brain droppings found here.

README: The Bare Necessities

I gave a lightning talk at Steel City Ruby Conf 2012 today on writing a decent README. Instead of putting the slides up somewhere, I thought I would write up a more detailed post of the talk’s points.

Active Record, PostgreSQL and Sequence Naming

If you use PostgreSQL to back your Active Record models, you should check the current names for your tables and their sequences. Prior to Active Record 3.2.7, renaming a table did not rename the associated sequence for the table’s primary key.

A demonstration may be in order.

RC File for Your Windows Command Prompt

I had trouble today with my Windows %HOME% changing and throwing off Vagrant’s awareness of what boxes are installed. This may be your problem if Vagrant on Windows was working happily for you and then barks about no boxes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
C:\Users\you> vagrant box list
There are no installed boxes! Use `vagrant box add` to add some.

C:\Users\you>dir /b .vagrant.d\boxes
base-i-really-exist
centos-does-too

C:\Users\you>echo %HOME%
<somewhere not C:\Users\you>

C:\Users\you>set HOME=%USERPROFILE%

C:\Users\you>vagrant box list
base-i-really-exist
centos-does-too

%HOME% was different depending on whether I logged into Windows while on my Active Directory managed network or while I was offline. When on the AD network, %HOME% is set by policy to a mapped drive. When offline, %HOME% is my Windows %USERPROFILE%. I installed Vagrant and some base boxes while off my AD network and everything worked as expected. Base boxes were added to %USERPROFILE%/.vagrant.d/. Back in the office and logged in on the AD network, Vagrant was no longer aware of the base boxes because %HOME% now pointed at my personal mapped drive.

Creating a batch file to set %HOME% to %USERPROFILE% solved the problem.

cmdrc.bat
1
2
3
4
REM %USERPROFILE%/cmdrc.bat
@echo off

set HOME=%USERPROFILE%

For UNIXy goodness, name it cmdrc.bat, place it in %USERPROFILE% and then add the following to the registry so that this file is run whenever a command prompt opens.

cmdrc.reg
1
2
3
4
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%USERPROFILE%\\cmdrc.bat"

One Unity Launcher

T’was decided that the default behavior for Unity’s launcher will be to appear only on the primary monitor in Ubuntu 12.04. For some reason, when I upgraded to 12.04 (beta) today, my setting was for the launcher to appear on ALL desktops. Not a fan of it on all desktops.

For those who want to change this setting, you’ll need to install the Compiz configuration manager.

1
sudo aptitude install compizconfig-settings-manager

Once installed, run it.

  1. Hover the Dash Home (Ubuntu icon on launcher)
  2. Type in compiz and click on the CompizConfig Settings Manager icon that appears.
  3. Select Desktop on the left.
  4. Click on Ubuntu Unity Plugin on the right.
  5. Select the Experimental tab and scroll all the way down.

The setting for where launchers appear is Launcher Monitors. As of today (2012/04/05), you can select either Primary Desktop or All Desktops.

Give Your Gems Some Context for SELinux

Are you deploying your Ruby app to Red Hat or CentOS? Is Passenger complaining about not having permission to load the gems you have bundled with your app–e.g. failed to map segment from shared object: Permission denied–despite all the basic filesystem permissions looking correct? Would you like to avoid the nearly ubiquitous advice to disable SELinux, thus turning off the security that comes out of the box with SELinux enabled?

1
sudo chcon -R -h -t httpd_sys_content_t <gems path>
  • chcon :: Changes the security context for those executables and libraries.
  • -R :: (recursive) All the files here, please.
  • -h :: Affect symbolic links instead of any referenced file.
  • -t httpd_sys_content_t :: Set the TYPE in the security context.

We deploy with capistrano, so I have added this as a task called after bundle:install vendors my gems to <appdir>/shared/bundle.

1
2
3
4
5
6
7
namespace :application do
  after 'bundle:install', 'application:update_selinux'
  task :update_selinux, :roles => :web do
    puts 'Updating SELinux context for bundled gems'
    run "#{try_sudo} chcon -R -h -t httpd_sys_content_t #{applicationdir}/shared/bundle/"
  end
end