Support stopping cleanly on SIGTERM

Also removed the redundant fflush on stdout after writing the status -
buffering has been disabled so this is pointless.