Currently Mongo has a switch --service that is supposed tgo be passed to it when it is run as an NT service. This is unnecessary and against best practice on windows.
Currently --service causes StartServiceCtrlDispatcher() to be called in windows. However, as per the MSDN documentation for StartServiceCtrlDispatcher() if it is invoked from a console (cmd.exe) it returns ERROR_FAILED_SERVICE_CONTROLLER_CONNECT. As per http://msdn.microsoft.com/en-us/library/ms686324(VS.85).aspx:
This error is returned if the program is being run as a console application rather than as a service. If the program will be run as a console application for debugging purposes, structure it such that service-specific code is not called when this error is returned.
Therefore, StartServiceCtrlDispatcher() should always be called in main() in db.cpp, properly #ifdef'ed --service should be deprecated, doing nothing but emitting a message to log(). Also, this ticket should be linked to
SERVER-733 because logging should be fixed as well.