July 11th, 2009
This post contains a cross platform Ruby method to return the total number of CPU cores. There are gems, such as facter, that will do the same thing and much more but if you just want a quick and dirty single purpose method this will probably suffice. The only tricky bit was picking the best way to do the determination in Windows. I ended up using a WMI approach described in Rick Minerich's There Counting Processors in .NET: The Pros and Cons of Five Different Methods post. Read the rest of this entry
January 22nd, 2009
January 14th, 2009
Last month Mephisto 0.8.1: Drax was relaunched. Seeing activity on Mephisto was great news in itself. The update includes support for Rails 2.2.2 and several significant security fixes. The release is considered experimental but important because of the security fixes. That's a bit of a mixed message but I have no financial stake in my blog so decided to do an update.
This post describes my update process. It provides some general information about the changes and provides an example of using interactive git rebasing but in most cases it won't be a cookie cutter approach that you can follow for your own Mephisto implementation. In gitting Started with Mephisto and other posts I've described how I set-up Mephisto 0.8. Unless you've followed along and are maintaining Mephisto in the same way, or at least maintain your Mephisto blog in a git repository with customizations in your own branch, then your update procedure will probably be significantly different. Read the rest of this entry
January 13th, 2009
In Adding Gmail SSL SMTP Support to Rails I described the use of a simple Rails plugin to provide SSL SMTP support. Today I upgraded to a new version of Mephisto and while testing it in production I discovered that I couldn't send emails. It turns out that it had nothing to do with the Mephisto upgrade; my DreamHost server had been updated to Ruby 1.8.7 and the action_mailer_tls plugin I was using wasn't compatible. Oh well, I guess I deserved that surprise for using shared hosting and adding a monkey patch plugin. This post describes a simple fix. Read the rest of this entry
December 20th, 2008
December 19th, 2008
I just recently built and installed three different Ruby versions (see Installing Ruby 1.8.6, 1.8.7 and 1.9 on Leopard). Following that I wanted to do some benchmark testing between 1.8 and 1.9 on a separate project so I began to use ZenTest's
multiruby. It worked great for the benchmarking and I started to think about how to use
multiruby as a way to manage and switch between Ruby installations. As I started looking into it I came across Dr Nic's Future proofing your Ruby code. Ruby 1.9.1 is coming post, which turned on the rest of the lights for me. The Dr Nic post does a nice job of describing how to use
multiruby including setting up specific Ruby versions, adding gem support and using it with sake tasks. I'll cover some of the same setup and usage information so that this post stands alone but I won't repeat it all so I recommend you read Dr Nic's post. In addition I'll provide information about how to overcome a RubyGems installation issue that I encountered and how to use the
multiruby Ruby installations as a way to dynamically switch between Ruby versions. I'll also discuss how the static build and install from source approach used in Installing Ruby 1.8.6, 1.8.7 and 1.9 on Leopard could be modified to be provide a non-
multiruby dependent way to do Ruby version switching. At the end of the post I'll mention using symlinks as an alternative and how that approach could be used with
Read the rest of this entry
December 12th, 2008
Ruby provides several simple ways to launch subprocesses. Ruby's
popen method comes into play in situations where cross platform handling of subprocess IO is required. Ruby also provides mechanisms to trap and send signals, such as the
SYSINT (Control-C) signal. Putting
popen and signal handling together to launch and manage a subprocess is straight forward but there's a limitation;
popen lacks support for capturing standard error. By default standard error output is just displayed on the screen as if the subprocess was launched from the command line. There are a couple of workarounds available, in some cases it may be acceptable to discard standard error by redirecting it as part of the subprocess launch command, i.e. "
command 2>/dev/null"; another, and typically better, option is to redirect standard error so that it's merged with standard output, i.e. "
command 2>&1". Unfortunately the redirection impacts the Process ID (pid) for the launched subprocess, which breaks the simple standard signal handling that I mentioned earlier. In addition to the pid issue, getting the Control-C signalling support to work in Windows can be challenging. This post walks through an example that shows
popen usage and how to send Control-C signals to a subprocess in Windows and Unix when standard error is redirected. It concludes with a brief discussion of
popen4 as alternatives to
Read the rest of this entry
December 10th, 2008
Dec. 19, 2008 Update: This post covers setting up and switching the default Ruby installation in
/usr/local. If you're looking for a more dynamic way to test and/or switch between Ruby versions see Switching Between Ruby 1.8 & 1.9 with multiruby.
I had originally installed Ruby 1.8.6 on Tiger from source using Dan Benjamin's Building Ruby, Rails, Subversion, Mongrel, and MySQL on Mac OS X instructions. I upgraded to Leopard but continued to run the
/usr/local version of Ruby. It has been working fine for me but for various reasons I decided it was time to upgrade to 1.8.7. I was happy to see Dan had created updated instructions for Leopard in his Installing Ruby, Rubygems, Rails, and Mongrel on Mac OS X 10.5 (Leopard) post. So I decided that I'd just install over my 1.8.6 version. It didn't go off without a hitch, I ran into a problem compiling readline. This post documents what worked to resolve the problem, my journey back to 1.8.6, how to add 1.9 support and how to switch between versions.
Read the rest of this entry
December 4th, 2008
Jan. 13, 2009 Update: If you're using Ruby 1.8.7 see Updating Gmail SSL SMTP Support for Ruby 1.8.7 for a compatibility fix to the plugin used in this post.
DreamHost provides it's own SMTP support but their default set-up uses Gmail, which only supports SSL based SMTP connections. Rails 2.2 with Ruby 1.9 provides SSL support in ActionMailer via Ruby's 1.9 Net::SMTP class. That's great but it's still a very new combination and I wanted support for DreamHost's Ruby 1.8.5 and Mephisto using Rails 2.0.2. Fortunately it's simple to get SSL (a.k.a. TLS) based SMTP connections to work. Within a few minutes of hitting the browser search button I saw three options: lift 1.9 Net::SMTP code, use msmtp, and, the method I chose, a small plugin that patches Net::SMTP. No, I didn't look into the merits of each solution and I didn't do any type of exhaustive search to see what else might be available, I just picked what looked like an easy way to get the job done. This post documents where to find the plugin and how to use it. Read the rest of this entry
December 3rd, 2008
Jan. 14, 2009 Update: The techniques discussed in this post are still relevant but the externals only apply to Mephisto 0.8. See Upgrading to Mephisto 0.8.1 for information about the externals that I'm currently caching.
Cached Externals is a Rails plugin that extends Capistrano to speed up deployments by not deploying vendor gems and plugins unless they change. The way it accomplishes the performance gain also results in explicit management of the cached gems and plugins, something worthwhile in it's own right. In this this post I'll walk you through installation and use of the plugin by describing how I used it for this Mephisto blog application. gitting Started with Mephisto describes how the application was set-up and Deploying Mephisto with Capistrano to DreamHost provides the pre-Cached Externals deployment details. Basically the app is just a customized copy of Mephisto in a git repository. The vendor directory holds Rails 2.0.2 and TZInfo along with all the gems and plugins that are part of the Mephisto distribution. The repository is kept locally on a laptop so Capistrano's copy strategy is used to deploy it to the production server. Read the rest of this entry
December 1st, 2008
It's often helpful to be able to bring MySQL production data down to a development machine. I wanted to do this for my Mephisto blog engine (see gitting Started with Mephisto and Deploying Mephisto with Capistrano to DreamHost) so that I could see how changes would look with existing data before deploying an update. Production data is also useful for tracking down bugs with production data and for backups. This post describes the Capistrano namespace I created for doing this. Read the rest of this entry
December 1st, 2008
I was using Capistrano 2.5.2 to run a MySQL dump on a deployment target and what started as a simple implementation to prevent the command line password from showing up in the Capistrano log evolved into a research effort about the security of using passwords on the MySQL command line. This post describes how to suppress
run execution lines from showing up in the Capistrano log, the real risks with using passwords on the MySQL command line and how to use Capistrano to avoid command line passwords without putting the password in a
Read the rest of this entry
November 30th, 2008
This post describes how to use Capistrano to deploy a Mephisto based blogging engine to a DreamHost account running Phusion Passenger. The blog code is deployed from a local git repository. gitting Started with Mephisto describes how the repository was set-up. With some modifications the script and commands presented here should be adaptable to other hosting services and other Phusion based Rails applications. Read the rest of this entry
November 30th, 2008
Jan. 14, 2009 Update: This post applies to Mephisto 0.8. See Upgrading to Mephisto 0.8.1 for information about moving to version 0.8.1
I took what I bet is a pretty common approach to setting up Mephisto. I put a copy on my laptop, played with it just enough to get it to work and then found and followed some fairly simple instructions to install it directly on my DreamHost account. It was an easy and straight forward approach but in my case by the time I finished my installation I knew I wanted to start over. The problem was that I quickly found myself modifying too many things to get Mephisto to work and look the way I wanted. I could tell it was going to be easier for me in the long run to get the blog engine in source code control with a development and deployment environment that made it to easy tweak and update from my laptop. Since Mephisto is a Rails application I went with the common choices: maintaining the blog code in a local git repository and deploying it using Capistrano.
In this post I cover setting up a custom git branch for Mephisto along with a couple of Mephisto modifications I recommend to prepare it for deployment to a DreamHost account. Actually there's really nothing DreamHost specific here but other hosting services could require additional changes to environment files. I'll cover deployment to DreamHost using Capistrano in a my next post. If you want to take this approach then I'm assuming you're fairly technical and already have git and Rails and MySQL installed on your computer. The use of git and Rails in this post is basic but going down this maintenance and deployment path is only worthwhile if you're reasonably comfortable with both technologies. Read the rest of this entry
November 29th, 2008
I recently set-up a secure shell account for a DreamHost shared hosting account that I intend to use for automating deployment and backup tasks from a Mac OS X Leopard client. While not overly complicated there were a couple of gotchas that I ran into. This post consolidates my findings and gives you a brief background for what's going on when you set up SSH access. The information applies to Mac OS X 10.5.1 or greater. Read the rest of this entry