WSL: MongoDB service failed to start (unrecognized service )
-
breif intro: MongoDB cannot be started as a service (with an error:
mongod: unrecognized service) but can be started manually withsudo mongod -
Expected results: Mongodb starts as a service.
-
Actual results (with terminal output if applicable)
sudo service mongod startmongod: 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
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 33 (2 by maintainers)
Commits related to this issue
- WIP2 https://github.com/microsoft/WSL/issues/1822#issuecomment-289477325 — committed to knocte/lnp2pBot by knocte 3 years ago
- WIP3 https://github.com/microsoft/WSL/issues/1822#issuecomment-683374762 — committed to knocte/lnp2pBot by knocte 3 years ago
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*sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6echo "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.listsudo apt-get updatesudo apt-get install mongodb***At this point the version installed by mongo is an older version… for me ie.sudo service mongodb startSo 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
After researching, I solved this problem by doing:
Create folders:
~# mkdir /data/db~# mkdir /data/db/logRun command
~# mongod --dbpath data/db --fork --logpath data/db/logAnd then run the server
~# mongodHi @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 mongodto start it manually, butsudo service mongodb start(note mongodb rather than mongod) to start it using an init script. So your command is missing ab.I have the same issue after following this tutorial
And when I type
mongod --version(not mongodb) I getdb version v3.4.3but when I run
sudo service mongod startI getmongod: unrecognized serviceHi folks! I’m a Senior Technical Writer at MongoDB and work with the server documentation. We were linked over to this pull, so I’m leaving a comment here.
Please note that the Windows Subsystem for Linux (WSL) is not an officially supported method for installing MongoDB. While Ubuntu 12, 14, and 18 are supported operating systems, we cannot guarantee that they will function as expected through the WSL. It’s worth noting that Ubuntu 18 only supports MongoDB 4.0 and later.
As noted on the WSL FAQ, WSL does not guarantee functionality of all Linux applications. Many of the issues here appear to be related to trying to start MongoDB as a service. Please see this comment by @therealkenc who has some workarounds for the missing
systemdsupport required for things to work as documented.User @Mikeysax posted a gist in #796 with instructions that may work for some users.
We’re always happy to see people trying out MongoDB, and would encourage users looking for MongoDB support in particular to check out the MongoDB Google Group for guidance. That said, running MongoDB within the WSL compatibility layer may produce unexpected behavior that we have limited insight or control over. If you want a sandbox to play in, you can always spin up a free MongoDB Atlas cluster as a sandbox to poke around with. Alternatively, spin up a Virtual Machine running a supported OS and install MongoDB using the available instructions.
One last note: Some platforms provide a
mongodbpackage you can install. These are unofficial packages and not maintained by MongoDB. Themongodb-orgpackage is the official package. If you’re not runningsudo apt-get install mongodb-org(or the equivalent for your desired linux OS), something is probably going to go wrong. Check our installation documentation if you’re in doubt!@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 startI get the error:mongodb: unrecognized service.Any other ideas?
For me: First install mongodb server by : sudo apt-get install mongodb-server
Then: sudo service mongodb start
This is how I solved the issues
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/restartinstead of killing the process manually. However, we still cannot solve the problem why we cannot start it viaservice mongod startas the tutorial says.By the way, mongo-org has already given us a config file in
/etc/mongod.conf. So we’d better usemongod --fork --config /etc/mongod.confto make it easier (to config the service).@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.
@Raju’s solution is discussed here as well : https://docs.microsoft.com/en-us/windows/wsl/tutorials/wsl-database#install-mongodb, and fortunately this script worked for me!
try this, it works on MongoDB version 4.20
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add - && echo “deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list && sudo apt-get update && sudo apt-get install -y mongodb-org
https://github.com/mongodb/mongo/blob/master/debian/init.d copy paste the above links content (init.d content) into a file called mongod in /etc/init.d/, if does not exist create one
then run sudo service mongod start/stop/status
if not working try sudo mongod --dbpath ~/mongodb/are
make sure to create ~/mongodb/db folders
Hullo. Same issue here.
service mongod startandsudo mongodb startboth giveunrecognised service.sudo mongodstarts, but then terminates because/data/dbisn’t found. Creating the db and log directories allows it to start viasudo mongod, but starting it as a service still doesn’t work.I removed mongo lock file first
sudo rm /var/lib/mongodb/mongod.lockthen started the mongod using the following commandsudo mongod --fork -f /etc/mongod.confAlternatively, you can create the service configuration file as pointed by @maticomp in the Digital Ocean article.
honestly…iv just about had it with this
why cant things be easier XD
!! service mongod start Failed to start mongod.service: Unit mongod.service not found. !!
I tried @ojoaofernandes’ config but that didn’t work. I got the error
Failed to connect to bus: No such file or directorySo I kind of hacked around it by installing both versions:
Windows updated with everything from windows update windows version 1803 (OS Build 17134.48)
Above doesn’t work for me.
servicesimply doesn’t work formongo.I finnaly made my WSL support
systemd, and it worked for me like a charm! https://learn.microsoft.com/en-us/windows/wsl/systemd#how-to-enable-systemdAs pointed by @xtianus79 and to my surprise, on Ubuntu Xenial doing
4- sudo apt-get install mongodbworks like magicThank you. This worked like a charm
I had this problem. The
mongodcommand worked fine. The problem was in the mogodb service. At the end I found that somentimes the installer fails to assing the correct owner to some dirs and files that are necessary to start the service under the mongodb user (this user is used in the start service script by default).So I changed the ownership from these dirs:
finally just launch the service with:
sudo service /etc/init.d/mongodbThis work in windows 11 with WSL2 ubuntu 20.04.
You can find more information in mongodb community
I hope this helps to someone.
@sarvjot this solution did not work for me unfortunately . sudo service mongodb start fail
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.
I had the same problem with unrecognized service.
I did as zealseeker suggested and started with: mongod --fork --config /etc/mongod.conf