Return an appropriate exit code if the daemon exists because of errors

Currently we only return an exit code of 1 if an error occurred,
otherwise an exit code of 0 is returned.

Close #1008