Daemon example from http://stackoverflow.com/a/9047339. Seems to work nicely.