Playing around with Puppet

I had a great night last night playing around with Puppet, an open-source enterprise systems management tool. Puppet is a tool that allows you to write “manifests” for how to set up a server, or a part of a server, automatically. Using Puppet you can deploy ready-to-go systems into the cloud with a single command (after you’ve written all of your manifests). It allows for rapid scaling of an environment and also the ability to create multiple environments that are nearly if not completely identical to each other.

Another tool similar to Puppet is Chef. From what I can tell, both are equally well regarded. I will be using Chef at work, so I’m playing with Puppet at home for now so I can get an introduction to both tools.

Having had lots of experience supporting various sites and applications, it’s really fun to start using a tool that would drastically make that job easier. There’s always a desire to go back and do something you’ve done in the past, but to do it better with the benefit of one’s experience. If I were to start an IT operation from scratch, either Chef or Puppet would be a central part of my strategy.

Also, a note — I’ve gotten to the point in my life when a great Friday night is one spent at home, up late, playing with stuff on the computer. No apologies for that!

Starting a group of EC2 instances with a single command

I’m working on a project that involves a number of Amazon EC2 instances. To keep costs under control, I decided it would be worthwhile to write a script to start and stop my instances in bulk.

I started with the online documentation for AWS:

http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/index.html?SettingUp_CommandLine.html

I found it’s pretty easy to do. Once you install the Amazon command line tools and get your environment variables set up, it’s pretty simple to start and stop your instances. Here’s a quick and dirty shell script I wrote:


#!/bin/bash

ec_suite_start() {
echo "Starting ec_suite instances"

# Magento 01
ec2-start-instances i-7fe7e71c

# DB01
ec2-start-instances i-73e8e810
}

ec_suite_stop() {
echo "Stopping ec_suite instances"

# Magento 01
ec2-stop-instances i-7fe7e71c

# DB01
ec2-stop-instances i-73e8e810
}

case $1 in
start)
ec_suite_start
;;
stop)
ec_suite_stop
;;
*)
echo "Usage: control.sh {start|stop}"
;;
esac

Next up, I’m going to try to launch and configure a web server with Chef. Exciting!

Goal for the week: Build a LAMP stack with Chef

I’ve got a few projects that are going to involve building and configuring servers for different purposes. I’m excited to start using Chef to enable infrastructure build automation.

Here’s a screencast I just watched on building a load balanced LAMP stack on EC2 with Chef (courtesy Opscode).

Update after a busy year

2011 is coming to a close, and I’m beginning to start end of year activities for EK Mitchell, LLC.

The year began with an exciting new contract position at Best Buy, and things were looking up. I was busy through the spring and took on additional clients, working in the evenings and weekends. My job at Best Buy continued to go well, and in July they offered me a permanent position as a Senior Lead Developer. After careful consideration, I accepted the offer, and began the process of winding down my fledgling consulting business.

This fall I wrapped up my final work as an independent contractor and I am now putting 100% of my efforts toward my job at Best Buy, which has changed from Senior Lead Developer to Web Development Manager. I’m excited about the work that needs to be done in the year ahead.

When I’m not spending time with my wonderful wife and son I’m working on preparing my old house to become a rental property in South Minneapolis. My goal is to have that rented out in April or May.

Beyond that, I’m always coming up with ideas, as usual. I’ll take one thing at a time, and I have no plans to quit my day job, but who knows what the future holds.

Dark as a Dungeon

There’s a song on the first Nitty Gritty Dirt Band album called Dark as a Dungeon, originally written by Merle Travis, and it’s served as a parable for me on my philosophy of work. The song encourages young men to avoid seeking fortune in the mines, because the work is miserable. There might be quick gains, but the risks are high, and too often, you come away with nothing.

I always hear a message in between the lines of that song, that life is better as a farmer. The work is just as hard, but you have the sun on your shoulders, and the fields yield back year after year. The gains come slowly, but after years of work, you have fertile fields to pass down to another generation, which will continue to yield for years to come.

I found the same analogy the other day in this article on creating a software company. It seems the author shares the same philosophy that I do.

Tech startups have become a fetish. It could be seen at this year’s South by Southwest Festival. They had a bus that went from California to Austin, and it was filled with young techies challenged to create the next startup in the course of the trip.

There’s less emphasis paid these days on building a business that will last. In my opinion, that’s the measure of the quality of anything — how long will it last? Whether it’s a building, a bridge, software, or a business, the test of time reveals the measure of its value.

That’s the vision for EK Mitchell, LLC. To go to work each day, and do the little things right. To always leave a fertile field after every harvest. With hard work, I’ll add to my acreage, and increase my yield modestly year after year. A services business is no get rich quick scheme.

No, the reward is in the work. If you enjoy what you do, you never have to retire. And the fields will give back to you year after year.

Newsletter Number One

Taking a cue from this article, I’ve decided to start telling the story of my fledgling business by sending out a monthly email. (Editor’s note: I’m not trying to raise $635K anytime soon)

If you want to get these emails as they come out, please email me at erik -at- ekmitchell.com and I’ll add you to the list.

Here’s the text of yesterday’s email:

Hello Friends and Family!
Welcome to my first newsletter! I’m going to be sending an email out
about once a month. You’re on this list because I thought you might
want to be.

If you’d rather not get these emails, just hit reply and tell me to
take you off the list, and I’ll take care of it right away!

Ok, are you still with me? Great!

In this issue, I’ll tell you about my company, I’ll give you an update
on what I’m doing at Best Buy, I’ll tell you about the mobile
development I’m working on, and finally about a great community event
that I was able to be a part of.

So, about my company: EK Mitchell, LLC is a web and mobile software
development company, which I founded in 2002. In the early days, I
worked as a freelance web developer. At the end of 2003, I got a great
job and put the company on the back burner, doing a little freelance
work here and there in the years that followed.

But I always wanted to give it another go, and in 2010, I made the
leap to become an independent contractor, signing up to work full time
for Best Buy Co. Inc. (more about that later). This time around I’m
laying the groundwork for a web and mobile software company that
leverages my experience, my technical ability, and my commitment to
customer service.

In the next year I hope to build EK Mitchell, LLC into a seaworthy
vessel, and set forth on the adventure of entrepreneurship. I hope to
bring other talented people in to join me, and I hope you’ll follow
along as I tell the story.

- What’s going on at Best Buy?
I was brought into Best Buy to work on its “Local Store Pages” site,
which you can visit at http://stores.bestbuy.com/5/ (that’s the Edina
store, where I got my 3rd computer!). In cooperation with the Local
Store Page business team, I helped resolve technical issues and add
important features through the end of FY11, which ended February.

This site runs on WordPress, which is a great piece of software for
powering all kinds of websites. WordPress powers millions of websites
on the Internet. Best Buy’s implementation of WordPress is such a big
deal that it’s featured on WordPress.org:
http://wordpress.org/showcase/best-buy/.

Since March 1 I’ve been working on a new project at Best Buy, which
I’ll tell you more about in the months ahead!

- And the Mobile Development thing I mentioned?
In March I was able to take a 2 day course in iPhone application
development, taught by Dan Grigsby of Drivetrain
(http://drivetrainagency.com/). It was a great intro into the world of
mobile development and I’m excited to be entering this new space as a
developer.

And I already have a project to work on! In collaboration with Nate
Mueller (http://www.nate-mueller.com/), I’m developing an iPhone app!
Look for more on that in future newsletters.

- How about Community Involvement?
Last weekend I participated in the Nerdery Overnight Web Challenge
(http://tc2011.overnightwebsitechallenge.com/), where 18 teams of web
pros came together to crank out 18 websites for 18 deserving
non-profits in 24 hours. My team built a brand new website for
Someplace Safe, a women’s crisis center in western Minnesota. The site
looks awesome, and I’ll have a link in next month’s newsletter for
everyone to see.

- In Conclusion
If you’ve made it this far, thank you. Next month I’ll have more to
talk about with Best Buy, including a project I did that solved a
nasty problem and brought a huge return on investment. I’ll update you
on mobile development, and also point you to the new website from the
Overnight Web Challenge.

Until then, have a great April!

These are planned for the first Friday of every month. If you want to follow along, let me know!

TCLUG Out of Hibernation

Over on the TCLUG Mailing List we’ve decided to take a break from snarking at each other an organize a meetup, just like the good old days.

If you think you might go, please choose the Buffalo Wild Wings location that is most preferable to you. We’ll go to the highest voted location. I’m proposing that we meet on Tuesday, February 8th, 2011.

The poll should be visible in the right hand sidebar, immediately to the right of this text. Please only vote once!

Resolution for 2011

Those of you who follow me on Twitter might have seen a post yesterday that my resolution is to exercise more. Consider that a rough draft.

After giving it a little more thought, I’ve decided that my resolution is to ride my bike to work 100 times this year. To help me keep track of my progress, I put a little widget in on the right side of the page. If things go well, you’ll see that tick up slowly but surely starting this week!

[Update 1/20/2011]
Anyone watching the counter will notice that I’m not off to a very good start on biking to work. Well, it’s been very cold, and when it hasn’t been very cold, it’s still been somewhat cold, and snowing.

There’s a warmup coming next week. I’m bound and determined. I’ll get that sucker to 1 next week if it kills me!

Safely upgrading WordPress with diff and patch

The more you do with with WordPress, the more likely it is that your installed codebase is going to stray from the default distribution from WordPress.org. Making minor changes is tempting. There are a lot of forum posts out there asking how to apply minor tweaks, and some of the proposed solutions aren’t always the most forward thinking.

For many years now I’ve been responsible for websites that are powered by Open Source software (Drupal, Magento, and WordPress, primarily). I’ve tried a lot of different ways to manage the integration of updates. One thing I’ve learned is that the longer you wait between upgrading your site, the more work each upgrade is. Keeping on top of changes is important, for a couple of reasons. First, you want to integrate new features and obviously security fixes. Secondly, the less complex each update is, the easier it is to apply and verify that it doesn’t break anything.

Currently, my favorite approach is to use the tools “diff” and “patch,” which are standard on any common UNIX or Linux system. Here’s what I do.

Download the “stock” releases

Go to the website of your open source software and download the latest release. Also, if you don’t have it, you’ll want to download the release of your current install as well. You might have to search for the “release archives” section to find this.

Create a directory to extract these two releases into, and extract each and rename to reflect the release. In this example, I’m going to show an upgrade from WordPress 3.0.1 to WordPress 3.0.4.


you@foo:~/$ cd Projects
you@foo:~/Projects/$ mkdir WordPress && cd WordPress
you@foo:~/Projects/Wordpress/$ tar -zxf ~/Downloads/wordpress-3.0.1.tar.gz && mv wordpress wordpress-3.0.1
you@foo:~/Projects/Wordpress/$ tar -zxf ~/Downloads/wordpress-3.0.4.tar.gz && mv wordpress wordpress-3.0.4
you@foo:~/Projects/Wordpress/$ ls
wordpress-3.0.1 wordpress-3.0.4

Compare the releases

Now is a good time to see what changed between the two releases. You can use the diff command to do this.


you@foo:~/Projects/Wordpress/$ diff -rq wordpress-3.0.1 wordpress-3.0.4
Files wordpress-3.0.1/readme.html and wordpress-3.0.4/readme.html differ
Files wordpress-3.0.1/wp-admin/includes/file.php and wordpress-3.0.4/wp-admin/includes/file.php differ
Files wordpress-3.0.1/wp-admin/includes/plugin.php and wordpress-3.0.4/wp-admin/includes/plugin.php differ
Files wordpress-3.0.1/wp-admin/includes/update-core.php and wordpress-3.0.4/wp-admin/includes/update-core.php differ
Files wordpress-3.0.1/wp-admin/plugins.php and wordpress-3.0.4/wp-admin/plugins.php differ
Only in wordpress-3.0.4/wp-content/plugins/akismet: admin.php
Files wordpress-3.0.1/wp-content/plugins/akismet/akismet.php and wordpress-3.0.4/wp-content/plugins/akismet/akismet.php differ
Only in wordpress-3.0.4/wp-content/plugins/akismet: legacy.php
Files wordpress-3.0.1/wp-content/plugins/akismet/readme.txt and wordpress-3.0.4/wp-content/plugins/akismet/readme.txt differ
Files wordpress-3.0.1/wp-includes/canonical.php and wordpress-3.0.4/wp-includes/canonical.php differ
Files wordpress-3.0.1/wp-includes/capabilities.php and wordpress-3.0.4/wp-includes/capabilities.php differ
Files wordpress-3.0.1/wp-includes/comment.php and wordpress-3.0.4/wp-includes/comment.php differ
Files wordpress-3.0.1/wp-includes/formatting.php and wordpress-3.0.4/wp-includes/formatting.php differ
Files wordpress-3.0.1/wp-includes/functions.php and wordpress-3.0.4/wp-includes/functions.php differ
Files wordpress-3.0.1/wp-includes/kses.php and wordpress-3.0.4/wp-includes/kses.php differ
Files wordpress-3.0.1/wp-includes/load.php and wordpress-3.0.4/wp-includes/load.php differ
Files wordpress-3.0.1/wp-includes/ms-files.php and wordpress-3.0.4/wp-includes/ms-files.php differ
Files wordpress-3.0.1/wp-includes/version.php and wordpress-3.0.4/wp-includes/version.php differ
Files wordpress-3.0.1/xmlrpc.php and wordpress-3.0.4/xmlrpc.php differ

Since the output of this command can be unwieldy, I’ll break it down by grepping the words “Only in” and “differ”:


you@foo:~/Projects/Wordpress$ diff -rq wordpress-3.0.1 wordpress-3.0.4 | grep differ
Files wordpress-3.0.1/readme.html and wordpress-3.0.4/readme.html differ
Files wordpress-3.0.1/wp-admin/includes/file.php and wordpress-3.0.4/wp-admin/includes/file.php differ
Files wordpress-3.0.1/wp-admin/includes/plugin.php and wordpress-3.0.4/wp-admin/includes/plugin.php differ
Files wordpress-3.0.1/wp-admin/includes/update-core.php and wordpress-3.0.4/wp-admin/includes/update-core.php differ
Files wordpress-3.0.1/wp-admin/plugins.php and wordpress-3.0.4/wp-admin/plugins.php differ
Files wordpress-3.0.1/wp-content/plugins/akismet/akismet.php and wordpress-3.0.4/wp-content/plugins/akismet/akismet.php differ
Files wordpress-3.0.1/wp-content/plugins/akismet/readme.txt and wordpress-3.0.4/wp-content/plugins/akismet/readme.txt differ
Files wordpress-3.0.1/wp-includes/canonical.php and wordpress-3.0.4/wp-includes/canonical.php differ
Files wordpress-3.0.1/wp-includes/capabilities.php and wordpress-3.0.4/wp-includes/capabilities.php differ
Files wordpress-3.0.1/wp-includes/comment.php and wordpress-3.0.4/wp-includes/comment.php differ
Files wordpress-3.0.1/wp-includes/formatting.php and wordpress-3.0.4/wp-includes/formatting.php differ
Files wordpress-3.0.1/wp-includes/functions.php and wordpress-3.0.4/wp-includes/functions.php differ
Files wordpress-3.0.1/wp-includes/kses.php and wordpress-3.0.4/wp-includes/kses.php differ
Files wordpress-3.0.1/wp-includes/load.php and wordpress-3.0.4/wp-includes/load.php differ
Files wordpress-3.0.1/wp-includes/ms-files.php and wordpress-3.0.4/wp-includes/ms-files.php differ
Files wordpress-3.0.1/wp-includes/version.php and wordpress-3.0.4/wp-includes/version.php differ
Files wordpress-3.0.1/xmlrpc.php and wordpress-3.0.4/xmlrpc.php differ


you@foo:~/Projects/Wordpress$ diff -rq wordpress-3.0.1 wordpress-3.0.4 | grep '^Only in'
Only in wordpress-3.0.4/wp-content/plugins/akismet: admin.php
Only in wordpress-3.0.4/wp-content/plugins/akismet: legacy.php

So we can see a number of files have been altered, and a couple of files in the akismet plugin have been added. In this release, no files were deleted. If they had been any, we would have see that in the “Only in” portion.

Create a patch file

The next step is to create a patch file so that we can apply these changes to our active codebase. The patch program takes a special diff file and uses it to systematically apply changes to any number of files. The diff file that it uses will indicate which lines to remove, and which to add. When a line is modified, the old version is removed by patch, and the new version is added. Using patch is handy because if there are target files which you have made changes to, your changes will be preserved, unless they conflict with the changes that need to be made by patch. This happens on a line by line basis. It’s for this reason that these tools are so useful when upgrading a codebase that contains little tweaks that you’ve made. You can apply the changes from the upgrade, and preserve your tweaks at the same time.

Here’s how to create the patch file:


you@foo:~/Projects/Wordpress$ diff -rupN wordpress-3.0.1 wordpress-3.0.4 > wordpress-3.0.1_to_wordpress-3.0.4.patch

Apply the patch to your install

Now you need to apply this patch file to your codebase. I wouldn’t recommend doing this on a live site without testing it first in a different environment. I’m applying the patch on my laptop, which is where I do my development. My WordPress codebase lives in ~/Sites/ekmitchell.com/public.


you@foo:~/Projects/Wordpress$ cd ~/Sites/ekmitchell.com/public
you@foo:~/Sites/ekmitchell.com/public$ patch -p1 < ~/Projects/Wordpress/wordpress-3.0.1_to_wordpress-3.0.4.patch

It's on this step that you're going to find out if any of your changes conflict with the changes made to the released versions. I'll leave dealing with that as an exercise for the reader :) . If you run into problems, please leave a comment here and we'll figure it out.

If everything goes smoothly, your code has now been updated. Depending on how you manage your development code and your production site, you'll need to migrate your updated code base to your web server.

If you're using WordPress, you'll need to go to http://yoursite.com/wp-admin/upgrade.php to apply any database updates that need to happen. Other software is likely going to have an equivalent step that needs to happen. Refer to your software's documentation for more information.

I hope this post is helpful to anyone managing open source software for websites. I want to thank Stephen Jungles for his post on diff and patch, which I used this morning to refresh my memory.

If you have any questions or problems, please leave a comment below!