Bug 1028451, 1028899 — Handle SIGTERM.

- Wait for server stopping accepting new connections before calling process.exit(0);
- Adds tests for the shutdown implementation.

r=Alexis,Natim