Provide posibility of gracefull web server restart

1. Implement on exit event handler interface in daemon.
2. Update web server to make possible to stop listening
and wait until all active connections will end
3. Refactoring in database library. Split it into
parts, to make possible to override something