A Better Daemonize

ruby thin

Wed May 07 02:16:00 -0700 2008

Mongrel, Thin, and every other web application server I’ve ever used all suffer from a similar deficiency: they daemonize too early. That is, they daemonize prior to trying to boot your app, which means any error - even a really obvious, immediate boot problem - will silently feed into the log as the process dies, without so much as a peep on the command line.

Try this:

$ mkdir nothing
$ cd nothing
$ thin start -d && echo success

(Substitute “mongrel_rails” for “thin” here if you want, the result is identical.)

Wait, what? There’s not even anything there. Why does it return true? Early daemonization, that’s why.

A better approach would be to boot the app, and once it’s online and listening and ready to serve requests, then return.