Remove pid file when exiting.
Also move forking and pidfile management in a different file.
Support log redirection to a file.