Notes

Why I Stopped self-hosting my mails, IM and website

A year ago, I started an experiment. I wanted to quit gmail and gtalk services and prove me that I could host my emails and my IM myself. It went quite well but I decided to stop and subscribed to fastmail.fm and to hosted.im.

Installation

A year ago, I spent some days installing a fully functionnal mail/web/jabber server. Hopefully, I had some good tutorials about setting up a mail server. On the jabber side, it was quite easy even if sometime, my WTF-o-meter level was really high. I blame my totally absent knowledge of erlang and mnesia here.

The easiest part was to set-up varnish and nginx on the server. This is because I use these technologies every day. I still think that serving static files with a reverse proxy could be much more easier and quicker to setup.

Backuping is easy and cheap, thanks to Amazon S3. I did not suffer any crash and did not have to restore my data. I think I would have cried if I had to do that because of the time needed to set-up the server again. The pain would have been bearable thanks to the EBS (if it doesn’t fail).

My final set-up used these technologies: Amazon EC2, Amazon S3, Amazon CloudFront, Amazon Elastic Block Storage, Postfix, Dovecot, Sieve, Varnish, Postgrey, Spamassassin, Nginx and Ejabberd.

Running it

Here is what I learned:

  • SMTP servers obey Murphy’s Law. If you have an important mail to send, it will fail. Fallbacking to gmail happened too many time.
  • ejabberd is stable. In a year of operation, it failed once and restarting it made did the trick. The guys behind ejabberd did a really great job.
  • Spam was virtually absent from my mail. Spamassasin and postgrey worked well.
  • Sieve is great. I mean really really GREAT. Filtering mail in gmail is a pain.
  • Mail clients all suck. Sparrow was an exception.
  • I’m not nerdy enough to use Mutt.
  • I should have used a configuration management system like Chef, Puppet or CFEngine to create the server. It would have doubled/tripled the time required to configure it properly, but it would have been an asset if I wanted to migrate my services to another host, which I considered at some point.

Now

Yesterday, and after too many problem with my SMTP server, I decided to end this experiment and started looking for a reliable mail provider. I chose fastmail.fm because of the price, migrations processes and the Sieve support.

This website is now hosted by Amazon S3. The only cron job that I had is now run on heroku. My jabber service is being migrated to hosted.im.

This will costs me around 50$ a year and this is definitely worth the time I won’t put in managing a server.

Creating, installing and configuring software is easy. Achieving reliability is hard.

Authenticated Cross-Domains AJAX Requests with CORS

Yesterday, I lost a significant amount of time dealing with cross-domain AJAX requests and I thought I might share a bit of what I learned.

  1. jQuery 1.5.0 is BROKEN when it comes to cross-domain AJAX requests. Upgrade to at least jQuery 1.5.1.
  2. Access-Control-Allow-Origin WON’T accept a wildcard value if your XHR’s withCredentials option is set to true. Also, it won’t accept a list of origin. If you want to accept requests from a lot of domains, you can match the Origin request header against a set of domains and set the Access-Control-Allow-Origin accordingly.
  3. Access-Control-Allow-Headers and Access-Control-Allow-Methods CORS header does not support * as a value. You have to be specific, even during your prototyping phase.

Hope it helps.

Serving a maintenance page with varnish

Yesterday during the SOPA Blackout, this website was on strike. The billions of readers of this blog had a static page explaining why this website was offline instead of the normal content. As a good nerd, I turned this operation into a technological one and instead of serving a static html with nginx, I decided to use varnish.

Yes, varnish.

I never wrote anything about the absolutely amazing architecture of this blog but basically, static files are generated from RestructuredText, served by nginx and cached by varnish.

Let’s get back to the point. I wanted varnish to serve a static page with a 503 status code (for SEO purpose).

It took a bit of VCL knowledge and here is how to do it:

# /etc/varnish/maintenance.vcl
backend default {
    .host = “127.0.0.1”;
    .port = “8080”;
}

sub vcl_recv {
    error 503;
}

sub vcl_error {
    set obj.http.Content-Type = “text/html; charset=utf-8”;
    # you can put absolutely what you want
    synthetic {“
    <html>
    <head>    
    </head>
    <body>
    <h1>This website is under maintenance.</h1>
    </body>
    </html>
    “};
    return (deliver);
 }

The trick here is the synthetic keyword which is described in the varnish documentation like this:

The synthetic keyword is used to produce a synthetic response body in vcl_error. It takes a single string as argument.

Now that you have a cool VCL for your maintenance page, you can load this vcl in varnish like this:

varnishadm -T 127.0.0.1:6082 -S /etc/varnish/secret "vcl.load maintenance /etc/varnish/maintenance.vcl

and to replace the original rules by those described in maintenance.vcl

varnishadm -T 127.0.0.1:6082 -S /etc/varnish/secret "vcl.use maintenance"

And varnish will serve the maintenance page. Like a boss.

Back from SfDay 2011 Cologne

I’m now back to my daily work at SensioLabs after some days spent at Cologne, mostly for the Symfony Day 2011. It was truly great to be there. I had the chance to put faces on twitter nicknames and to talk in front of the crowd. I was a bit nervous and wasn’t as relaxed as I would liked to be. I will try to work on my english pronunciation for the next times.

Many thanks to the SensioLabs Deutschland & Interlution team, it was really a nice moment.

Oh, and here are the slides of my talk.

I assure you, it’s open

screenshot of Clerks movie

Kids. Backuping your data is great. But assure you that your backups also contain your database. I’ve lost all the posts of this blogs and much more. Nothing to say that I was really pissed off.

I wanted to recreate this blog from scratch but got distract by other things. After a few months of procrastinating and slapping myself for not having a place to write, I found a great theme based on twitter bootstrap for wordpress and decided to give it a go. I’m pretty happy with that.

Let’s hope I’ll have the strength to write some interesting articles.

Oh, I’m currently concerned by twitter/facebook tracking on the web and won’t add “tweet this” or “like” button but I will, for now, conserve the Google analytics tracking script and the feedburner thingy.

P.S : The picture and the post’s title come from the awesome Clerks and Clerks 2 movies. If you haven’t seen them, it’s never too late.