Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB - shutting down with code 48

Tags:

mongodb

I am trying to start MongoDB but the terminal returns the following error:

2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] MongoDB starting : pid=25184 port=27017 dbpath=/data/db 64-bit host=Janiss-MacBook-Pro.local
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] db version v3.4.1
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2k  26 Jan 2017
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] allocator: system
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] modules: none
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] build environment:
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten]     distarch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2017-02-06T16:26:27.037+0000 I CONTROL  [initandlisten] options: {}
2017-02-06T16:26:27.038+0000 E NETWORK  [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK  [initandlisten]   addr already in use
2017-02-06T16:26:27.038+0000 E NETWORK  [initandlisten] Failed to set up sockets during startup.
2017-02-06T16:26:27.038+0000 E STORAGE  [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-02-06T16:26:27.038+0000 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-02-06T16:26:27.038+0000 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-02-06T16:26:27.039+0000 I CONTROL  [initandlisten] now exiting
2017-02-06T16:26:27.039+0000 I CONTROL  [initandlisten] shutting down with code:48

I am using Laravel Valet if that matters.

like image 302
ignite-me Avatar asked Feb 06 '17 16:02

ignite-me


3 Answers

It seems like you have already a process running on the port where you want to start mongodb:

listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-02-06T16:26:27.038+0000 E NETWORK  [initandlisten]   addr already in use

you could try to kill the process that runs on that port with this command: sudo kill sudo lsof -t -i:27017

or define another port for mongodb if you have another program using that port.
to run mongodb on a port other than its default port (27017) use the --port 27018 argument when starting mongodb from the terminal

like image 128
matyas Avatar answered Oct 27 '22 10:10

matyas


If you are using mac then you can simply kill the process running on port 27017 which is mongodb process in most cases.

Simply run the command.

npx kill-port 27017

After that you can run the mongod command as you normally do.

Or if you are using windows follow these steps

  • Run command line as Admin
  • netstat -ano | findstr :27017
  • you will get pid in the end that is the process id to kill
  • taskkill /PID <typeyourPIDhere> /F
  • after successful termination of process you can run mongod as you usually do!

Enjoy!

like image 12
Vivek Maru Avatar answered Oct 27 '22 10:10

Vivek Maru


Basically you just need to force quit the mongo, you can do this just by typing

sudo pkill -f mongod

and now you can start the server again with

mongod
like image 4
Heitor Freitas Avatar answered Oct 27 '22 12:10

Heitor Freitas