Implementing shutdown in daemon code