Who Moved My Gems?

Posted by smoe Fri, 22 May 2009 20:13:00 GMT

I appreciate the tough decisions the guys at Phusion had to make. Distributing products like Ruby Enterprise Edition and mod_rails is a lot of work. It's got to run on dozens of different operating systems and Linux distributions, every one with it's own package manager and configuration preferences. They did a great job of it. Their install script is the best of it's kind that I have seen, and I applaud their decision to use /opt, they are using that directory for it's intended purpose.

The problem is that the executable files in /opt/ruby-enterprise/bin are not in the default path, and it's a lot of keys to type /opt/ruby-enterprise-1.8.6-20090421/bin/ every time you want to run rake or rails or any other gem based executable. This is not a problem for your production application. Once you have Apache configured to load Passenger it knows where to find all the gems, but in development or deployment you may experience pain.

I have been around and around on this problem. At first I just typed in the whole /opt path, when I remembered too, and used the regular version of gems and Debian's ruby1.8 when I forgot. When I set up some new servers with REE and passenger from the start with no other ruby interpreter on the machine I knew I needed to stop winging it. I could have just run a parallel installation with ruby1.8 and all the gems installed twice, once for Apache and once for the command line, but I found that unappealing.

I did not test the first version of this post well enough. I had thought I solved the problem by changing the PATH environment variable so /opt/ruby-enterprise/bin was the first place searched for executables, but there are situations when that just does not work.

For example: you will need to run rake as a normal user during development, with sudo when you install gems specified in environment.rb, as root if you su – to work through a new installation or a system upgrade, as a non-interactive user when you deploy with capistrano, and with sudo via capistrano. I changed /etc/profile, /etc/environment, /root/.bashrc, ~./bashrc, and aliased sudo but I still couldn't get every situation to work correctly. I need to warn you in particular about using an alias for sudo as I showed in the first version of this post. It removed the sbin directories from the PATH you get with sudo and system commands cannot be found.

One thing I had tried early on was to use /etc/alternatives. It was tedious to run update-alternatives by hand and every new gem could add a new executable and when Phusion released a update to REE I had to do it all over again.

My new approach goes back to /etc/alternatives and, so far so good, it seems to solve all these problems. If you are running Ubuntu and installed REE from Phusion's .deb you will already have a /opt/ruby-enterprise directory. If you are running Debian you can create a link by that name to the current release of REE. Then we can depend on /opt/ruby-enterprise being the current release. When a new version comes out just update the link and you should be ready to go. This is how I create the link for Debian.

$ sudo ln -s /opt/ruby-enterprise-1.8.6-20090421 /opt/ruby-enterprise

Now to automate the chore of creating the /etc/alternative links. I just did a rake task because it simplifies a few things, but it is just a simple loop and it could be done as a real script someday.

namespace :ree_alt do
  desc 'find ruby-enterprise-edition executables and link as alternatives'
    task :install do
      Dir.entries("/opt/ruby-enterprise/bin").each do |executable|
        unless [".", ".."].include? executable
          `update-alternatives --install /usr/bin/#{executable} #{executable} /opt/ruby-enterprise/bin/#{executable} 100`
        end
      end
    end

desc 'remove all ruby-enterprise based alternatives'
  task :remove do
    Dir.entries("/opt/ruby-enterprise/bin").each do |executable|
      unless [".", ".."].include? executable
        `update-alternatives --remove-all #{executable}`
      end
    end
  end
end

As usual there is plenty of room for improvement. When you need to update the alternatives what you have to do is run the remove task and then run the install task, with sudo. Trick is when you run install you will not have rake in your path so you need to go back to the long /opt path name.

$ sudo /opt/ruby-enterprise/bin/rake ree_alt:install

So it's not beautiful, but it does work this time, and it's not too much of a chore.

The Crime of Offending

Posted by smoe Fri, 01 May 2009 14:25:00 GMT

I was not at GoGaRuCo, I really don’t know what it was like to sit through Matt Aimonetti’s presentation, and I surely don’t know what it would have been like to be a woman in that room. So I feel quite confident in stating that I think everybody is wrong. As humans our natural condition is be incorrect while we puff up, posture, and strut about indignantly. Follow along while I demonstrate.

Matt gave a presentation to our local users group, ORUG, last year after RubyConf. It was an interesting talk on framework performance and I took away some useful information. He followed a talk by Thomas Meeks on Nanite, which was a lot more interesting and memorable. I don’t blame Matt for looking for a way to make his talk edgy and provocative. I have seen the slides from Matt’s talk at GoGaRuCo, apparently with the most salacious three images removed, and it didn’t do anything for me. I’ve seen episodes of South Park that made me way more uncomfortable than any of those pictures. I suspect the real problem was reaction of the audience. A gang of aroused juveniles is more intimidating than any image.

If you felt the images were worth an NC-17 rating while the next guy says R or PG-13 is not the point. There is certainly room for edgy humor in a technical talk, it can even be helpful, but there is no need for distracting puerile imagery. That said, if you are offended by a person, it’s your problem, not theirs. Get up and walk out, turn off the television, block the twitter account, blacklist the email address, just don’t whine that others need to accommodate your sensitivities. Personally I am offended when someone claims their state of being offended requires others to change their ideas, language, or culture. It makes for a vicious cycle of intolerance for the intolerant. If we are going to get along we need to accept that everyone has the right to be as wrong and offensive as you.