Monit restarting Mongrel Cluster - “Execution Failed”

Following in the footsteps of numerous other hapless people seeing this error - I had a frustrating number of hours, trying every combination of stuff that *should* work according to various recipes.

The following is what I had to do to get monit playing nice with mongrel cluster (and thereby avoiding the lovely error “execution failed” when trying to get mongrel restarted via monit)

This is on a CentOS 5 Enterprise x86_64 server. For some reason calling the cluster::start option on mongrel_rails would not work, I had to pass in all the flags manually to mongrel_rails, along with absolute paths for everything. But hey it works … you can manually kill a mongrel process and watch monit bring it back up for you, right as rain !!!

(note next step I’d change the monitrc to actually test a response from the mongrel server in question, rather than rely on the pid file)

Setup:
- mongrel user, in mongrel group.
- mongrel owns /var/www/apps/myappname/
- monit is run as root user
- mongrel user doesn’t have sudo privileges

in /etc/monitrc

check process mongrel_8000
with pidfile /var/www/apps/myappname/shared/pids/mongrel.8000.pid
start program = “/usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -c /var/www/apps/myappname/current/ –user mongrel –group mongrel -p 8000 -P /var/www/apps/myappname/shared/pids/mongrel.8000.pid -l /var/www/apps/myappname/shared/log/mongrel.8000.log”
[stop program, rules etc following]

[Rinse and repeat for each mongrel you're running in the cluster]

Note that this will not work…
start program = “/usr/local/bin/mongrel_rails cluster::start -C /var/www/apps/myappname/current/config/mongrel_cluster.yml –clean –only 8000″

require, RMagick, and case sensitivity

(At least on Leopard with Ruby 1.8.6)

Ruby will try to reload rmagick if you get the case of rmagick different from the original require. And when that happens it all goes up the whop.

We were using attachment_fu’s image magick processor, then doing a require ‘rmagick’ seperately which resulted in tonnes of errors like this

/usr/local/lib/ruby/gems/1.8/gems/rmagick-1.15.10/lib/rmagick.rb:32:
  warning: already initialized constant PercentGeometry

Keep your case’s of require’s consistent. Even if this is file system dependent behaviour in mixed development environments you can imagine how weird problems could get!

HTML_QuickForm in …. Rails ?

Caution Thinking Out Aloud:

Okay the purists have just decided to kill me. Let the religious wars begin !

No seriously, everytime I do some coding in an old PHP app which is heavily dependent on HTML_QuickForm, I keep questioning how possible would it be to convert it across to Rails, and whether any other persons like myself would think all of their Christmases have come at once. Here’s my hopefully rational thought processes behind this. Rails is a fantastic CRUD machine. If you want to build single model forms with validations in them, absolutely beautiful. Nothing could feel more clean and make you as a developer go ‘thats sweet’. Fantastic.

Now try and do a model-less form, with validations, or combine multiple models within one form. Things like the presenter pattern get bandied about. Real world case example - a form to choose options for defining a report. Nothing that you want to put in a model as it’s not a represenation of a ‘thing’ (although some may argue it is).

I wonder and am sitting on the fence of, whether to try implementing quickform for rails. For those that haven’t been exposed to it, in a nutshell it’s a brilliant little php library that lets you create a representation of a form, with rules, pass the form into a renderer which dumps out the html on a page, but that’s not all, it assists you in processing the form on submission. So some code can look like this (not syntactically correct, but close enough), which does all of the hard work of writing out html, setting up client side js, and server side processing.

//page myform.php
 
$myform = new HtmlQuickForm('form_name', 'myform.php'); 
$abc = $myform->addElement('text', 'product_name', 'Product Name:'); 
$myform->addRule('product_name', 'required', 'You must enter a product name'); 
if ($myform->validate()) {
   //process form
   var_dump( $abc->getValue() ); 
} else {
   //setup form 
   $abc->setValue('123')
}
 
// then in any template which dumps out the rails code
$myForm->display();

It doesn’t seem like much, but put half a dozen or more options on the form, different processing rules, and suddenly it’s done a lot of the heavy lifting for you.

What would it take to add this to Rails ? How would (I personally) fit it in. It doesn’t really sit within either the model, view, or controller. The view should render the output, it doesn’t really fit within a model as it’s not a representation of a thing. It most closely sits in the controller, but you don’t really want to clutter the controller with your form models.
Here’s some thoughts

An initial idea, with everything defined in the controller, then dumped into the view by a @my_form.output

class FormController < Application 
  def do_form
    get_form
    if @myForm.posted 
       #do stuff
    else
       #populate stuff
    end
  end
 
protected
  def create_report
    @myform = RFormBuilder.new do |f|
       f.call_back_url = { :controller => 'form', :action => 'do_form' }
       f.name = 'myform'
    end
    @myform.add_text( :name => 'product_name', :label => 'Product Name', 
              :rule => { :required => :true, :msg => 'You must add this' } )
 
  end
 
end

OR

Maybe we add in a new folder in the main app

  /app/
      /controllers
      /models
      /views
      /forms
        myform.rb

And the treat myform.rb kinda like a model, but kinda not.

 
class MyForm < RFormBuilder
  defaults :name => 'my_form', :call_back_url => '/myform' 
  text_field :name => 'product_name', :label => 'Product Name', :required => :true
 
  #gets called when form is posted   
  def validate
    return true if field_product_type == 'abc'
  end 
end
 
 
# now in FormController 
 
 def do_form
    get_form
    @my_form = MyForm.new
    if @myForm.valid
       #do stuff
       render :text => @my_form.field_product_name
    else
       #populate stuff
    end
  end

What do you think ? Am I stark raving mad. Could this just work ? I think so and am willing to take up the challenge…

Rowan

Gotta love *those* recruiters

From a blanket spam email I (and probably a good portion of the rails community just received)

“I have a direct client who is seeking a strong Programmer who posses experience with Rudy on Rails. If you are qualified and interested, please send me your most current resume in a word.doc format to..”

Yes, Rudy was actually put in bold, just to place even more emphasis on the spelling error.

Want to know what Toronto’s councillors are spending your money on ?

Check this out. Council Expenses (robford.ca)

Absolutely brilliant, and questionable all at the same time…

JungleDisk - online backup done right?

Following some links last week I ended up on jungledisk.com. All of 30 secs later I had the client downloaded and started backing up my hard drive.

What is it ? It’s a collection of clients for the 3 majors (Windows, OS X, Linux) that essentially mount up an S3 storage bucket as a separate volume. You purchase the jungledisk client for $20 after a trial period, then get an S3 account with Amazon.com and settle your bill with them, based on exactly how much transfer and disk space you use. Set the whole lot up, and bingo you have an online volume, that (one would hope) is near infallible.

Over the past week I’ve had a mac connected up, and an xp box, to the same S3 account. I’m in the process of slowly backing up all of my very precious photos etc. You do need a fat pipe to go and store all this stuff online but that comes with the territory. The beauty of this system is it appears just as another volume, and with cross platform clients, it means you can have your data storage off in some other place, without worrying about it.

The cost.. well, hardly anything to get worked up around. So far I’ve spent a princely sum this month of $0.16USD with Amazon for ~1gb transfer, and 300mb storage.

I’m stoked. No iffy external hard drives, or optical media to get damaged. Of anyone I expect Amazon to be the most reliable service, much more than anyone could acheive with a SOHO RAID storage device, for a fraction of the cost.

Very tidy solution, and well worth a look at.

PGR4 event ? Atoms ? .. so close yet so far.

Ariel atomOh the humanity of it all! On my way to work this morning I was stopped in my tracks by two Ariel Atoms parked outfront of an events place just round the corner. Instant parallel thought trains rocked through my mind, how the hell are they road legal in Canada ? and how the hell do I get myself in the passenger seat ?. Then a 360 Modena rocks up, along with a Porker. What’s going on ? Finally I look out of my Atom induced haze to see the XBox 360 signage everywhere. Aha. Makes sense…Project Gotham Racing 4.

Righto so I rock back to the office. Get dressed so I look more professional than bike courier, rock back and start talking to various people. 5 mins later I’d managed to wangle a potential ride later in the day after telling my true tale of woe that I left New Zealand when an Atom track day was going down and missed out on the drive of my life. The clock strikes 4 (after hearing the Ferrari opening it up many times during the afternoon… Torture! Torture I tell you…). I jump up, grab camera, rock round the corner. “Oh No”

The Police. (with a heavy weighting on the period there)

Who would’ve thought that would’ve happened? No cars were going anywhere. Period. However the silver lining is at least I’m on the list for a track day for next summer, which gives me a good 10 months to work out how to justify the money for it to my S.O.

Goodbye MediaTemple

Okay, I’m not one to publicly rant but really, I’ve given up with the performance of MediaTemple’s GridServer implementation. More to the point the marketing and statements simply do not measure up to what actually has happened with this blog at Mediatemple. It’s not high load at all, never been dugg, slashdotted or anything else that might bring ill fate to a web site, however it’s been subject to outages last week and weekend. Maybe someone had tried deploying a facebook app using the same grid server cluster my site was on ? Who knows. But whatever happened to the “no single point of failure” and “rapid scaling”… ?

My particular favourite piece of copy is the “Guaranteed Resources” bit. Couple that with a sub par customer support response and the plug was pulled.

I do know personally of one other with a media temple account (who I had recommended MT), he’s serving static pages only and experiencing no troubles, so credit where credit is due. If you’re backing it with a database, be prepared…

Of course, now I’ve setup Murphy to come bit me in the ass with his law on my new host!.

Automated testing of websites via “real” users.

Of all the testing we can do, there’s nothing quite like firing up your browser and navigating to the website in question, logging in and doing stuff. All of the integration tests, port tests, contrived “I’m alive” tests etc can give you an *indication* that your website code is all well and good. However what you really want to test is “can I jump to it, do x y z action, and complete those actions without it bombing out”. We have a two options, we hire an army of minions who will do that for us every 15minutes on the dot OR we could do it automatically. How do we do this ?

Well there are a number of ways. One option I’m going to walk through is using the magic genius of Safari Watir, RSpec tests, ruby, a few gems, cron and any Mac you can lay your hands on. We set this up a while ago monitoring some of our sites and it’s great for finding out when something in your webstack has fallen over. For a < $1k investment it’s a no brainer for any web site.

Caveat - this ain’t going to test your flash/flex content - this is just for HTML based sites. Read on…

Yet another multicolumn layout - rocks!

test.jpgOne chasm between traditional desktop application development and web application development is layout/forms design. It’s my constant pain point “I just want a 2 column layout, with a data table in the middle” - many hours later you’re still tearing your hair out trying to get it working. It should not be this way (and that’s just for prototyping).

To get a production tested basic grid/column based layout, that looks reasonable across all browsers and is flexible enough to grow as the app grows - well we all know how much a top notch HTML/CSS wizard is going to cost us right ? Why for every project the same ground of IE hacks and cross browser issues are solved over and over again ? This is half the reason that a sandbox environment like AIR is very appealing - don’t deal with it, just get your users to use a standard environment.

Enter from stage left, in the why hasn’t anyone thought about it before category, are two CSS frameworks that I happened upon on Friday. One called Blueprint which is getting a bit of attention, and one with the rather confusing name of YAML. After seeing all of the examples of YAML, and reviewing the documentation I thought what the heck lets give this a go.

Continue Previous page Next page

About

Rowan is a Director of Technology for a large marketing services company, specialising in architecting, developing and putting web applications into production - in particular Ruby on Rails based apps. He lives in Toronto, Canada but speaks in a funny accent as he's originally from New Zealand. He's been working in the software and web business for over a decade. This blog covers Web Application development and deployment in the real world, dealing with topics from business fundamentals to Ruby on Rails, Merb, PHP, Flex, MySQL, Apache and more.

Read more ...

 

 

View Rowan Hick's profile on LinkedIn

 

Subscribe to my RSS feed