Start as a service on Windows XP (sp3) does not work

20574 views
Skip to first unread message

Richard

unread,
Dec 7, 2009, 10:14:28 AM12/7/09
to mongodb-user
When I try to start mongod as a service I see:

c:\mongo\bin>mongod --service
Mon Dec 07 16:10:41 dbexit:
Mon Dec 07 16:10:41 shutdown: going to flush oplog...
Mon Dec 07 16:10:41 shutdown: going to close sockets...
Mon Dec 07 16:10:41 shutdown: waiting for fs...
Mon Dec 07 16:10:42 shutdown: closing all files...
Mon Dec 07 16:10:42 closeAllFiles() finished
Mon Dec 07 16:10:42 dbexit: really exiting now

The Event Viewer (System) shows the message:
The Mongo DB service failed to start due to the following error:
The system cannot find the file specified.

Any suggestions?

Richard

Eliot Horowitz

unread,
Dec 7, 2009, 5:22:49 PM12/7/09
to mongod...@googlegroups.com
None of us really windows experts.
Can you start the db successfully not as a service?
That would at least give us some direction.
> --
>
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>
>

Michael Dirolf

unread,
Dec 7, 2009, 5:25:36 PM12/7/09
to mongod...@googlegroups.com
just a hunch, but do you have c:\data\db created?

Kristina Chodorow

unread,
Dec 7, 2009, 5:27:06 PM12/7/09
to mongod...@googlegroups.com
Also, if you run it with "-vvvvv" (very verbose) it might print more about why it thinks it should shut down.

Richard

unread,
Dec 8, 2009, 3:04:26 AM12/8/09
to mongodb-user
I have been looking in the registry and I know what's wrong.
The key HKLM/SYSTEM/CurrentControlSet/Services/MongoDB/ImagePath has
the value 'mongod --service'. After I have changed it to 'c:\mongo\bin
\mongod --service' it worked.
Now it is possible to start and stop the service with the Windows
services menu (services.msc).

It seems that ServiceController::installService and
ServiceController::startService are not OK.
ServiceController::removeService works fine.


On Dec 7, 11:22 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
> None of us really windows experts.
> Can you start the db successfully not as a service?
> That would at least give us some direction.
>

devfuel

unread,
Dec 10, 2009, 11:47:07 PM12/10/09
to mongodb-user
I can shed some light here (albeit just a bit). After running into
this myself, I found this thread. I reinstalled the new version of
mongodb and, on a hunch, used the full path of the executable:

c:\> c:\dir1\dir2\mongodb\bin\mongod.exe --install

I then checked the registry for the service, and, indeed the full path
was there and i could start/stop the service from the control panel
without issue.

I am guessing that people who have this issue have (as I did the first
time) used the shortcut name for the executable:

c:\dir1\dir2\mongodb\bin\> mongod --install

The command line seems to be inserted as typed into the registry
without taking into account the current working directory.

-ee

Marinho Brandão

unread,
Jan 21, 2010, 11:39:49 AM1/21/10
to mongodb-user
Hello,

the problem still happens, when dbpath is a path with spaces (i.e. c:
\Program Files\something\db\)

even if you put the path quoted, when it is installed, the quotes are
removed and is necessary to change the path in the registry key.

I'm going to make a script to solve it as a quickfix for myself and I
will check the source code to see if I get to solve it and send a
patch.

best regards,

On Dec 11 2009, 2:47 am, devfuel <e...@devfuel.com> wrote:
> I can shed some light here (albeit just a bit). After running into
> this myself, I found this thread. I reinstalled the new version of
> mongodb and, on a hunch, used the full path of the executable:
>
> c:\> c:\dir1\dir2\mongodb\bin\mongod.exe --install
>

> I then checked the registry for theservice, and, indeed the full path
> was there and i could start/stop theservicefrom the control panel


> without issue.
>
> I am guessing that people who have this issue have (as I did the first
> time) used the shortcut name for the executable:
>
> c:\dir1\dir2\mongodb\bin\> mongod --install
>
> The command line seems to be inserted as typed into the registry
> without taking into account the current working directory.
>
> -ee
>
> On Dec 8, 12:04 am, Richard <richardverz...@gmail.com> wrote:
>
>
>
> > I have been looking in the registry and I know what's wrong.
> > The key HKLM/SYSTEM/CurrentControlSet/Services/MongoDB/ImagePath has
> > the value 'mongod --service'. After I have changed it to 'c:\mongo\bin
> > \mongod --service' it worked.

> > Now it is possible to start and stop theservicewith the Windows


> > services menu (services.msc).
>
> > It seems that ServiceController::installService and
> > ServiceController::startService are not OK.
> > ServiceController::removeService works fine.
>
> > On Dec 7, 11:22 pm, Eliot Horowitz <eliothorow...@gmail.com> wrote:
>
> > > None of us really windows experts.
> > > Can you start the db successfully not as aservice?
> > > That would at least give us some direction.
>
> > > On Mon, Dec 7, 2009 at 10:14 AM, Richard <richardverz...@gmail.com> wrote:

> > > > When I try to start mongod as aserviceI see:


>
> > > > c:\mongo\bin>mongod --service
> > > > Mon Dec 07 16:10:41  dbexit:
> > > > Mon Dec 07 16:10:41      shutdown: going to flush oplog...
> > > > Mon Dec 07 16:10:41      shutdown: going to close sockets...
> > > > Mon Dec 07 16:10:41      shutdown: waiting for fs...
> > > > Mon Dec 07 16:10:42      shutdown: closing all files...
> > > > Mon Dec 07 16:10:42      closeAllFiles() finished
> > > > Mon Dec 07 16:10:42  dbexit: really exiting now
>
> > > > The Event Viewer (System) shows the message:

> > > > The Mongo DBservicefailed to start due to the following error:

Marinho Brandao

unread,
Jan 21, 2010, 12:26:26 PM1/21/10
to mongodb-user
Hi folks

actually, I solved the problem running mongod.exe with
--dbpath="\"c:\Program Files\etc...\db\"" --install

2010/1/21 Marinho Brandão <mar...@gmail.com>:

--
Marinho Brandão (José Mário)
http://marinhobrandao.com/

Dwight Merriman

unread,
Jan 21, 2010, 2:47:07 PM1/21/10
to mongod...@googlegroups.com
i'm no expert on windows services -- if someone knows them well and wants to tell me the change needed in the util/ntservice.cpp mongodb source file, I can make it.

devfuel

unread,
Jan 25, 2010, 5:41:32 PM1/25/10
to mongodb-user
The eighth parameter to the :CreateService(...) function is the full
command path to the executable to run as a service. (Line 55 -
http://github.com/mongodb/mongo/blob/master/util/ntservice.cpp)

The code here just takes what is sent to the install command, replaces
"--install" with "--service", and registers the application.

If the path to mongodb.exe (lets call it PATH_TO_MONGO) is relative (".
\mongodb.exe") instead of fully qualified ("c:\program files\mongo\bin
\mongodb.exe"), then when launched in the context of the service
sandbox, the path cannot be found because it would be relative to the
server environment, rather than where the user called the --install
operation from.

On fully qualified vs relative paths:
http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx#fully_qualified_vs._relative_paths

In other words, if you couldn't run PATH_TO_MONGO from _any_ command
window in any directory, then you would encounter this error. If you
had "c:\program files\mongo\bin\" in your PATH environment variable
and PATH_TO_MONGO was "mongodb.exe", then it would work.

The code solution would be to take the executable path (argv[0])
detect if it was relative, and resolve its absolute path before
sending it to CreateService.

I believe it would be appropriate to use GetFullPathName():
http://msdn.microsoft.com/en-us/library/aa364963(VS.85).aspx

You would have to figure out how you would detect your absolute path
(occurrence of drive letter in path "C:\" etc.) in terms of desired
operation.

Cheers,

ee


This can be done via the

On Jan 21, 11:47 am, Dwight Merriman <dwi...@10gen.com> wrote:
> i'm no expert on windows services -- if someone knows them well and wants to
> tell me the change needed in the util/ntservice.cpp mongodb source file, I
> can make it.
>
>
>
> On Thu, Jan 21, 2010 at 12:26 PM, Marinho Brandao <mari...@gmail.com> wrote:
> > Hi folks
>
> > actually, I solved the problem running mongod.exe with
> > --dbpath="\"c:\Program Files\etc...\db\"" --install
>

> > 2010/1/21 Marinho Brandão <mari...@gmail.com>:

> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>


> > .
> > >> > > > For more options, visit this group athttp://
> > groups.google.com/group/mongodb-user?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > > To post to this group, send email to mongod...@googlegroups.com.
> > > To unsubscribe from this group, send email to

> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>


> > .
> > > For more options, visit this group at
> >http://groups.google.com/group/mongodb-user?hl=en.
>
> > --
> > Marinho Brandão (José Mário)
> >http://marinhobrandao.com/
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "mongodb-user" group.
> > To post to this group, send email to mongod...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > mongodb-user...@googlegroups.com<mongodb-user%2Bunsubscribe@google groups.com>

Tom DeMille

unread,
Mar 3, 2010, 10:57:51 AM3/3/10
to mongodb-user
I believe the problem is this:

one can type

C:\mongodb-win32-x86_64-1.2.4\bin\mongod.exe --install

OR

C:\mongodb-win32-x86_64-1.2.4\bin\mongod.exe -install

and the installation works, however the installer must be replacing
only --install with --service

so if you run the latter command, the registry key mentioned above
ends up being

C:\mongodb-win32-x86_64-1.2.4\bin\mongod.exe -install

when it should be

C:\mongodb-win32-x86_64-1.2.4\bin\mongod.exe --service

so the code should look for -install as well

once I edited the registry key and changed to the line above it worked

tk

unread,
Mar 24, 2010, 4:19:14 PM3/24/10
to mongodb-user
@Tom

Your solution is spot on. I made the change in registry key from
'mongodb.exe --install' to mongodb.exe --service' and it worked.

Thanks!

tk

Reply all
Reply to author
Forward
0 new messages