Monitoring Radiant CMS and Phusion Passenger on Slicehost

In my previous post, I wrote about quickly setting an Ubuntu Hardy slice up with Radiant and the latest Phusion tools (mod_rails and Ruby Enterprise) and alluded to some setting up logging and monitoring as next steps. As monitoring and logging are fascinating subjects, I figured I’d follow up with a few sentences about what I configured.

Apache will log to its own log files, as well as handle log rotation, so nothing much to write about there. However, as a good practice, you’ll likely want to rotate your Radiant logs. And for that, you’ll want logrotate.

Logrotate gets its configuration information from /etc/logrotate.conf, so one just needs to open it up and tell it to look at the Radiant logs and rotate them like so:


# Rotate Rails application logs
/path/to/radiant/shared/log/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}

This will rotate 7 days worth of logs, compress older logs and start a new log file. And it will do it daily. Simple.

Monitoring is a bit more involved, but God makes it fairly easy, and its all in Ruby. According to this helpful site mod_rails monitors its own processes, which leaves us to Monitor Apache, MySQL and any other processes running around. The God site has very good documentation, so I suggest you head over there if you want detailed descriptions of everything it can do. For the sake of this post, I'll just lead folks to simple Apache and MySQL configurations.

After installing God sudo gem install god --no-ri --no-rdoc, setup a conf.god somewhere sensible and take a look at the posts below, as it probably doesn't make sense for me to reiterate what others have already admirably accomplished:
Monitoring MySQL and setting up notifications.
Monitoring Apache.

Now I just need to figure out what will monitor God.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Writing a Simple MailChimp Web Service Using Merb

A while back, I was asked to build some code to help keep a businesses mailing list synchronized between SalesForce.com and their campaign management tool, which I suggested should be MailChimp and not the tool they were currently using, but I digress. The project never materialized, but I figured I would build it anyway and use it as a chance to explore Merb a bit.

My thinking at the time was that a standalone “wrapper” web service made sense. While it would have complicated application administration a bit, encapsulating the mailing list functionality in a simple service that could be called synchronously or asynchronously, as well as modified and deployed independent of core site logic, sounded reasonable.

So, let’s start with building a minimal Merb application to serve as a foundation:
merb-gen app mail_chimp_service --flat

This generates one controller, a few templates (if we want to build in some templated monitoring and for xml responses) and just enough configuration to get the Merb service started.

To test it out, just fire up Merb with the following command: merb and head to http://localhost:4000.

With a foundation in place, I started looking into my MailChimp plugin to see if I should turn it into a gem or do something simpler. I turned to hoe, thinking that making a gem would be interesting, but then decided otherwise, as I basically didn’t feel like writing that much. So instead, I wrote a simple chimp class to do the MailChimp API work:

require 'xmlrpc/client'
class Chimp
  cattr_accessor :client, :auth
  def add(subscriber)
    chimp_subscribe(auth, Merb::Config[:chimp_settings]['mail_chimp']['mailing_list_id'],
                            subscriber.email, subscriber.mail_merge)
  end
  private
  def chimp_subscribe(auth, mailing_list_id, email, merge_vars,
                                email_content_type="html", double_optin=true)
    begin
      client.call("listSubscribe", auth, mailing_list_id, email,
                     merge_vars, email_content_type, double_optin)
    rescue XMLRPC::FaultException => e
      Merb.logger e.faultCode
      Merb.logger e.faultString
    end
  end
end

This class adds users to a specific MailChimp mailing list using the MailChimp APIs. The client and auth attributes are set in the Merb init.rb class, as they really only need to be loaded once and not initialized per each request:


Merb::BootLoader.after_app_loads do
    Chimp.client = XMLRPC::Client.new2('http://api.mailchimp.com/1.0/')
    Chimp.auth = XMLRPC::Client.new2('http://api.mailchimp.com/1.0/').call("login",
                         Merb::Config[:chimp_settings]['mail_chimp']['username'],
                         Merb::Config[:chimp_settings]['mail_chimp']['password'])
end

I’m loading the MailChimp configuration parameters in the init.rb file in the config block. I’m just loading in a yaml file with the relevant information one would presumably want externalized from the application code:


Merb::Config.use { |c|
 .....
 c[:chimp_settings]      = YAML.load_file(Merb.root/'mailing.yml')
}

I then created a simple subscriber.rb class to encapsulate user elements and wired the relevant classes together in my single controller like so:


require 'chimp'
require 'subscriber'
class Foo < Merb::Controller
  provides :x ml

  def _template_location(action, type = nil, controller = controller_name)
    controller == "layout" ? "layout.#{action}.#{type}" : "#{action}.#{type}"
  end

  def index
    subscriber = Subscriber.new(params)
    chimp = Chimp.new
    chimp.add(subscriber)
    render false
  end
end

I subsquently added an index.xml.erb class to my views directory in order to render successful responses, fired up my app with the merb command and then ran a test in a separate console to ensure everything was working:


curl -H "Accept: text/xml" -L -d
"email=matt@mandarinsoda.com&first_name=swanky&last_name=mango" http://localhost:4000

It worked – the very first time!  (joking, but it did work after a bit of tinkering). I saw the content of my index.xml.erb and received a MailChimp opt-in email. Not too shabby for a few hours of tinkering. I’m sure there are interesting Merb features missing as well that could make this all the more compact.  More to explore later.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Where is Triumph These Days?

Triumph at a Star Wars opening. Funny stuff.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Installing Radiant CMS and Phusion Passenger + Ruby Enterprise on Slicehost

I don’t really bother writing anything about Slicehost installs anymore, as Pickled Onion over at the slicehost articles site writes excellent, up-to-date articles on the most relevant deployment and configuration topics. However, I just did a Radiant install, complete with Phusion Passenger (mod_rails) and Ruby Enterprise on Ubuntu Hardy and found a nice shortcut I thought I would share.

The shortcut in question is a fork of the Sprinkle gem by Mitchell Hashimoto. Check out his screencast for the details and read the comments as well. I just had to change the Phusion Passenger versions in the scripts, modify the scripts to install MySQL and Radiant (gem install radiant) and I was good to go.

If you’ve never setup a Slice before, I don’t usually recommend using ready-made scripts, as it’s good to go through the steps – particularly as things do tend to break. I had problems installing the MySQL gem from Capistrano for some reason I didn’t bother to dwell on for too long. Otherwise, I found the Sprinkle gem to be very helpful.

Now onto monitoring with God, some logrotate and the other usual suspects.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

New Baaba Maal Live Acoustic Album

Definitely a posting for the random category, but having waited 7 years for a new album since his excellent album Missing You, I figured the release of Baaba Maal’s new album was worth blogging about. He’s an absolutely amazing live performer. Do yourself a favor and check him out. Especially if you have a dreary job and/or are occasionally forced to code CSS, which can be spirit crushing (caveat: particularly if you don’t exactly know what you’re doing).

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Recent Adventures with Rake and Cron

I might be the last person to know these things, but if you wish to invoke a rake task within another rake task, here’s the syntax:

Rake::Task["thinking_sphinx:index"].invoke

And, if you happen to get funky “bad minute” errors when trying to setup said rake task via cron, make sure your cron command fits on one line while ediiting via crontab -e.

Choose your next adventure.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Mamadou Diabate in Some Random Ohio Town

Love it. Song to celebrate my new fish.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Good News for Jellyfish

What a great week if you’re a jellyfish or one of the world’s largest oil companies. Can’t be related can it?

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Excess Baggage

Two traveling monks reached a river where they met a young woman. Wary of the current, she asked if they could carry her across. One of the monks hesitated, but the other quickly picked her up onto his shoulders, transported her across the water, and put her down on the other bank. She thanked him and departed.

As the monks continued on their way, the one was brooding and preoccupied. Unable to hold his silence, he spoke out. “Brother, our spiritual training teaches us to avoid any contact with women, but you picked that one up on your shoulders and carried her!”

“Brother,” the second monk replied, “I set her down on the other side, while you are still carrying her.”

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Web Site Optimization News

Some interesting resources and news in the world of web site optimization recently. Good stuff for those who care about this sort of thing. I look forward to clogging up my works print queue with Velocity presentations on Monday even though printing is a bit evil.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]