WSL icon indicating copy to clipboard operation
WSL copied to clipboard

MongoDB service failed to start (unrecognized service )

Open valorad opened this issue 9 years ago • 33 comments

  • breif intro: MongoDB cannot be started as a service (with an error: mongod: unrecognized service ) but can be started manually with sudo mongod

  • Expected results: Mongodb starts as a service.

  • Actual results (with terminal output if applicable)

sudo service mongod start mongod: unrecognized service

  • Your Windows build number 15058

  • Steps / All commands required to reproduce the error from a brand new installation -- Install mongodb following the official ubuntu guide -- run sudo service mongod start

  • Strace of the failing command sudo service mongod start

  • Required packages and commands to install

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

sudo echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt-get update

sudo apt-get install -y mongodb-org

sudo service mongod start

valorad avatar Mar 27 '17 13:03 valorad

ah i just saw #796, sorry for the redundancy

valorad avatar Mar 27 '17 13:03 valorad

Hi @wcxaaa -- you're correct about #796 , but there's another issue here, a typo in your command: The mongodb package is confusing because you do sudo mongod to start it manually, but sudo service mongodb start (note mongodb rather than mongod) to start it using an init script. So your command is missing a b.

aseering avatar Mar 27 '17 14:03 aseering

@aseering Much appreciated! That works! I just copied and pasted command on official guide not knowing what was going on.

valorad avatar Mar 27 '17 14:03 valorad

There's one more thing I've found. The name of config file located in /etc should be mongodb.conf instad of mongod.conf.

valorad avatar Mar 28 '17 01:03 valorad

I have the same issue after following this tutorial

And when I type mongod --version (not mongodb) I get db version v3.4.3

but when I run sudo service mongod start I get mongod: unrecognized service

lobosan avatar Apr 10 '17 15:04 lobosan

@lobosan -- that tutorial unfortunately is incorrect; it has a minor typo that gives you the wrong command. (It's incorrect both for WSL and for regular Ubuntu Linux.) My previous comment contains the correct command, with the typo fixed.

aseering avatar Apr 10 '17 17:04 aseering

@aseering I read the whole post and I did try to do that but it didn't work for me and when I run sudo service mongodb start I get the error: mongodb: unrecognized service.

Any other ideas?

lobosan avatar Apr 12 '17 13:04 lobosan

After researching, I solved this problem by doing:

Create folders: ~# mkdir /data/db ~# mkdir /data/db/log

Run command ~# mongod --dbpath data/db --fork --logpath data/db/log

And then run the server ~# mongod

lobosan avatar Apr 12 '17 15:04 lobosan

Hi @lobosan . Though this way can start mongo by its "executable file, mongod", but it may not be safe and easy enough, I think. Because you have to manually start the service by this command everytime we reboot of the PC. "Service" is more helpful ( both in windows and in Ubuntu). For example, we can stop or restart the service via service mongod stop/restart instead of killing the process manually. However, we still cannot solve the problem why we cannot start it via service mongod start as the tutorial says.

By the way, mongo-org has already given us a config file in /etc/mongod.conf. So we'd better use mongod --fork --config /etc/mongod.conf to make it easier (to config the service).

zealseeker avatar May 15 '17 15:05 zealseeker

Hullo. Same issue here. service mongod start and sudo mongodb start both give unrecognised service. sudo mongod starts, but then terminates because /data/db isn't found. Creating the db and log directories allows it to start via sudo mongod, but starting it as a service still doesn't work.

danwhitston avatar Jul 11 '17 08:07 danwhitston

I had the same problem with unrecognized service.

I did as zealseeker suggested and started with: mongod --fork --config /etc/mongod.conf

thekep7 avatar Sep 07 '17 20:09 thekep7

Ok you shouldn't have to install the script any differently other than these few changes.... and you shouldn't have to make a directory... it's super odd to have to do it this way and where the break down is occurring I do not know but i will give instructions on how to install everything correctly at this time.

IMHO this is a large pile of hoo-diddy from someone and changes should be made... /rant.

Oh by the way, this is where i am altering the directions from.... https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

first I purged my mongo so I know everything is from scratch w/ this command: sudo apt-get purge mongodb-org*

  1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
  2. ubuntu 16.04: echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
  3. sudo apt-get update
  4. ***Not in mongo's directions: but rather something i got from reading above comments: sudo apt-get install mongodb ***At this point the version installed by mongo is an older version... for me ie.
mongod --version                                                                                                                             
db version v2.6.10
  1. sudo apt-get install -y mongodb-org ***Now, everything is installed correctly
mongod --version                                                                                                                             
db version v3.4.9
git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

  1. ***Lastly, per the op's @Zx-EvM && @aseering above states that instead of the start command of mongod you would use the following command to start mongo: sudo service mongodb start

So what does this do in summary?

It installs mongod DB on an ubuntu 16.0.4 linux Windows subsystem... Updates it... and runs it via the start command... hope this helps someone and everything in this thread was awesome but a little verbose and not to the point which is what this summary is for.

CP from this thread https://github.com/Microsoft/BashOnWindows/issues/796

xtianus79 avatar Sep 18 '17 04:09 xtianus79

As pointed by @xtianus79 and to my surprise, on Ubuntu Xenial doing 4- sudo apt-get install mongodb works like magic

siran avatar Sep 25 '17 01:09 siran

Alternatively, you can create the service configuration file as pointed by @maticomp in the Digital Ocean article.

  1. Save this few lines to: /etc/systemd/system/mongodb.service;
  2. Run: [sudo] systemctl start mongodb
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

ojoaofernandes avatar Oct 04 '17 04:10 ojoaofernandes

I tried @ojoaofernandes' config but that didn't work. I got the error Failed to connect to bus: No such file or directory

So I kind of hacked around it by installing both versions:

apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list

apt update && apt install mongodb-org #installs mongo 3.6.5

apt install mongodb # uninstalls mongo 3.6.5, installs 2.6.10
# this also installs the /etc/init.d/mongodb properly so back it up if you want, though i didn't need to

apt install mongodb-org # uninstalls mongo 2.6.10, installs 3.6.5 again

sudo service mongodb start # now works properly

Windows updated with everything from windows update windows version 1803 (OS Build 17134.48)

reorg-hle avatar May 27 '18 13:05 reorg-hle

Same here; one liner:

cp /usr/bin/mongod /etc/init.d/

This is the less hacky solution, but I think something is wrong with the installation as you normally should start daemon as services (*d) not the app itself (mongodb) ( which doesn't even exist on debian form what I'm seeing). There are other oddities as /etc/mongod.conf doesn't get read so you have to create /data/db as default place to save data or force load that config file.

Also if you went for apt-get install mongodb that's an unofficial unsupported debian version. mongodb-org is the "real" one.

Alternatively you can mongod --fork it but ideally it should start as daemon in init.d

I'm installing it on a docker debian 9 stretch container not sure if that causes any issues.

ziocleto avatar Jun 03 '18 20:06 ziocleto

screenshot from 2018-07-07 19 40 47 Hello everyone, I'm trying to install mongodb on my ubuntu version 14.04. when I'm trying to import the public key, I'm getting this error. I checked with the network as well, it's not blocked by the firewall.

It'll be a great help if you guys can help me out with this.

Thanks.

tej12shah avatar Jul 08 '18 02:07 tej12shah

when I'm trying to import the public key, I'm getting this error

That one is #3286 (not specific to MongoDB)

therealkenc avatar Jul 08 '18 03:07 therealkenc

@therealkenc okay. I'm new to this. so can you help me out with this as so what corrections/changes i need to do?

Thanks!

tej12shah avatar Jul 08 '18 04:07 tej12shah

After 6 hours of trying and trying, I can not for my life get MongoDB to start or run properly on Ubuntu 18 inside a docker-container on Codenvy.io. I followed xtianus79 instructions, and MongoDB did re-install and it seem to run when forced to manually start it. But it won't start and function like it suppose to. I followed to official instructions to begin with, but nothing seem to work.

Help would be appreciated! I'm using Codenvy.io (Eclipse/Che)

root@ecdd9f488e89:/# service mongod start
mongod: unrecognized service
root@ecdd9f488e89:/# mongo
MongoDB shell version v4.0.3
connecting to: mongodb://127.0.0.1:27017
2018-10-17T20:24:16.101+0200 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
root@ecdd9f488e89:/# cat /etc/issue
Ubuntu 18.04.1 LTS \n \l

ghost avatar Oct 17 '18 18:10 ghost