Improve daemon mode

The daemon's process id can be written to a file, and output can be redirected to a logfile.
This makes it easier to write complete init-script.