Reputation: 1909
I am getting this error when trying to run the command
mongod --dbpath=/var/lib/mongodb
{"t":{"$date":"2021-01-23T11:23:41.733-07:00"},"s":"I", "c":"CONTROL", "id":51765, "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
{"t":{"$date":"2021-01-23T11:23:41.733-07:00"},"s":"I", "c":"CONTROL", "id":21951, "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"storage":{"dbPath":"/var/lib/mongodb"}}}}
{"t":{"$date":"2021-01-23T11:23:41.734-07:00"},"s":"E", "c":"STORAGE", "id":20568, "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}
I do see the issue is
"attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Address already in use"}}}
But I don't know how to resolve this?
I tried other suggestions from another SO post that says to kill the process and restart. I did that and it did not work for me.
I also tried running mongod on a different port
mongod --dbpath=/var/lib/mongodb --port 27019
which gives me this error
{"t":{"$date":"2021-01-23T11:27:29.535-07:00"},"s":"E", "c":"STORAGE", "id":20557, "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /var/lib/mongodb"}}
So it's a read only directory so I ran
sudo chmod -R 777 /var/lib/mongodb
Then I get this error in the log
"ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"DBPathInUse: Unable to lock the lock file: /var/lib/mongodb/mongod.lock (Resource temporarily unavailable). Another mongod instance is already running on the /var/lib/mongodb directory"}}
So I try to find out which other process is running
ps -eaf | grep mongod
mongodb 722732 1 0 11:09 ? 00:00:10 /usr/bin/mongod --config /etc/mongod.conf
srt 725772 720106 0 11:34 pts/2 00:00:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox mongod
But idk what to do from here.
Upvotes: 8
Views: 20204
Reputation: 31
sudo pkill -f mongod
sudo mongod
this solved my issue in my ubuntu 22.04 system
Upvotes: 1
Reputation: 11
I used sudo mongod then I got this error, Now I type **sudo pkill -f mongod ** to get rid of this error and it worked,
Now again can use sudo mongod to work.
Upvotes: 1
Reputation: 10737
You have already the default auto started mongod instance running that use the default /etc/mongod.conf file You may stop this instance via:
service mongod stop
or
kill -2 722732
or
mongo --port 27017
>use admin
>db.shutdownServer()
or
systemctl stop mongod
You can modify the /etc/mongod.conf file with your needs and start it again with
service mongod start
or:
systemctl start mongod
Upvotes: 11