Only respond to stdin EOF if connected at start

When we ran under systemd, stdin was not connected and so it exited
immediately.
Add a SIGTERM handler for clean shutdown
Merge pull request #27 from scraperwiki/stdin-closed

Fixes for running under systemd