I can't start mongodb server, because it status=2/INVALIDARGUMENT
What is your os?
What command you used to start the service?
Hi! My OS is Ubuntu.
I used these commands to install Mongo 4.4
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo “deb [ arch=amd64,arm64 ] MongoDB Repositories focal/mongodb-org/4.4 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install mongodb-org=4.4.8 mongodb-org-server=4.4.8 mongodb-org-shell=4.4.8 mongodb-org-mongos=4.4.8 mongodb-org-tools=4.4.8
systemctl start mongod
systemctl enable mongod
systemctl status mongod
I suspect two things for now:
- you haven’t created a “data” folder. the server will not start in this case. this one is the highest possible reason in my mind.
- along with the data folder, the default config file might be missing (can’t say why).
mongod --logpath ~/mongocrashes.log in the terminal. it should give a better log so we can examine it. use “upload” button in your answer and attach it.
The error message is
Error reading config file: No such file or directory
Usually the configuration file is /etc/mongodb.conf but since it could be different you can verify the actual name used by the service using:
systemctl cat mongodb | grep ExecStart
What ever is the file specified by -f or –config, that file needs to exist and be readable by the user specified in the service file. You may find the user with:
systemctl cat mongodb | grep User
Next time you publish logs, screens output or code, please doing using the formatting specified in Formatting code and log snippets in posts. This way we can cut-n-paste in our reply or experimentation rather than typing over.
I suspect since sudo is not used with systemctl command it is unable to start mongod(not able to read mongod.conf file)
That could be the case but my understanding a little bit different.
The configuration file is read by mongod, not by systemctl. The process mongod is started as the User specified in the service file, so only this user needs to have read access to the file.
But I will test your sudo theory once I am on my linux machine.
Here comes the result.
My bash prompt is
: steevej ;
: steevej ; systemctl status mongodb : steevej ; systemctl cat mongodb | grep ExecStart : steevej ; systemctl cat mongodb | grep User : steevej ; ls -l /etc/mongodb.conf : steevej ; systemctl start mongodb : steevej ; systemctl status mongodb : steevej ; systemctl status mongodb ○ mongodb.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; preset: disabled) Active: inactive (dead) Docs: https://docs.mongodb.org/manual Nov 25 08:55:36 xps13 systemd: Started MongoDB Database Server. Nov 25 08:58:10 xps13 systemd: Stopping MongoDB Database Server... Nov 25 08:58:10 xps13 systemd: mongodb.service: Deactivated successfully. Nov 25 08:58:10 xps13 systemd: Stopped MongoDB Database Server. Nov 25 08:58:10 xps13 systemd: mongodb.service: Consumed 2.309s CPU time. : steevej ; systemctl cat mongodb | grep ExecStart ExecStart=/usr/bin/mongod --config /etc/mongodb.conf : steevej ; systemctl cat mongodb | grep User User=mongodb : steevej ; ls -l /etc/mongodb.conf -rw------- 1 mongodb mongodb 678 Jul 13 10:42 /etc/mongodb.conf : steevej ; systemctl start mongodb ● mongodb.service - MongoDB Database Server Loaded: loaded (/usr/lib/systemd/system/mongodb.service; disabled; preset: disabled) Active: active (running) since Fri 2022-11-25 09:00:46 EST; 40ms ago Docs: https://docs.mongodb.org/manual Main PID: 192273 (mongod) Memory: 2.0M CPU: 23ms CGroup: /system.slice/mongodb.service └─192273 /usr/bin/mongod --config /etc/mongodb.conf Nov 25 09:00:46 xps13 systemd: Started MongoDB Database Server.
So even if only mongodb user has read access systemctl still starts correctly. As a note, when I do systemctl start|stop without sudo, I have a dialog that ask for my passwd. So it looks like systemctl does a sudo behind the scene.
More over, if I change the owner of /etc/mongodb.conf so that user mongodb does not have read access, it fails to start with the error Error opening config file: Permission denied.
If I remove the configuration, it fails with Error opening config file ‘/etc/mongodb.conf’: No such file or directory. The error message is a little bit more explicit but I am using a more recent version:
: steevej ; mongod --version db version v5.0.3
So the only conclusion I can make is that the configuration file does not exist.
@Mari_Mikhaleva , above command is the crucial part we need from your side. can you please provide us its output.
mongod.conf.txt (667 Bytes)
here is the default config file you can use. if you somehow deleted your config file, copy this one. but remember, you will still need the path we were asking for.
or, put this file where ever you want (and accessible by systemctl) and edit the following line in
/usr/lib/systemd/system/mongod.service (at least ubuntu 20 uses this path)
ExecStart=/usr/bin/mongod --config /etc/mongod.conf(again this is the default path)
This is my file mongocrashes.log
mongocrashes.log (1.2 KB)
the file itself gives an error. edit your last post, rename the file to have
txt extension, and upload/attach again.
docs.txt (1.3 KB)
Attempted to create a lock file on a read-only directory: /data/db
this one is now related to folder permissions over
/data/db. I am not a Linux guru, so please check how you give write access to
assuming it is your personal computer, just for the moment, give full access to it with
sudo chmod 777 /data/db so we can see if you get any more errors.
This is a output of command:
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
I am guessing you corrected config file issue because your new log file says you don’t have write permission for the path to store database files. please check my above post and share again if you still have errors.
hi again @Mari_Mikhaleva, forum posts behave a bit strangely about sending new posts. sometimes just gives notifications, sometimes sends posts in an email. your last one (the one you seems deleted) came in an email, and I checked the log file.
Initializing full-time diagnostic data capture with directory ‘/data/db/diagnostic.data’
waiting for connections on port 27017
this means your config file is now fine and the data folder has the correct permissions so that the server is good to go. it is something nice to see.
with that in hand, if you decide to reinstall mongodb you have now a way to check a few possible locations.
That is something you may configure in your account preferences. I was happy when I was able to configure my account to not receive email anymore.