How to stop mongo DB in one command

前端 未结 18 1220
小蘑菇
小蘑菇 2020-12-04 05:21

I need to be able to start/stop MongoDB on the cli. It is quite simple to start:

./mongod

But to stop mongo DB, I need to run open m

相关标签:
18条回答
  • 2020-12-04 05:25

    My special case is:

    previously start mongod by:

    sudo -u mongod mongod -f /etc/mongod.conf
    

    now, want to stop mongod.

    and refer official doc Stop mongod Processes, has tried:

    (1) shutdownServer but failed:

    > use admin
    switched to db admin
    > db.shutdownServer()
    2019-03-06T14:13:15.334+0800 E QUERY    [thread1] Error: shutdownServer failed: {
            "ok" : 0,
            "errmsg" : "shutdown must run from localhost when running db without auth",
            "code" : 13
    } :
    _getErrorWithCode@src/mongo/shell/utils.js:25:13
    DB.prototype.shutdownServer@src/mongo/shell/db.js:302:1
    @(shell):1:1
    

    (2) --shutdown still failed:

    # mongod --shutdown
    There doesn't seem to be a server running with dbpath: /data/db
    

    (3) previous start command adding --shutdown:

    sudo -u mongod mongod -f /etc/mongod.conf --shutdown
    killing process with pid: 30213
    failed to kill process: errno:1 Operation not permitted
    

    (4) use service to stop:

    service mongod stop
    

    and

    service mongod status
    

    show expected Active: inactive (dead) but mongod actually still running, for can see process from ps:

    # ps -edaf | grep mongo | grep -v grep
    root     30213     1  0 Feb04 ?        03:33:22 mongod --port PORT --dbpath=/var/lib/mongo
    

    and finally, really stop mongod by:

    # sudo mongod -f /etc/mongod.conf --shutdown
    killing process with pid: 30213
    

    until now, root cause: still unknown ...

    hope above solution is useful for your.

    0 讨论(0)
  • 2020-12-04 05:26

    mongod --dbpath /path/to/your/db --shutdown

    More info at official: http://docs.mongodb.org/manual/tutorial/manage-mongodb-processes/

    0 讨论(0)
  • 2020-12-04 05:26

    Use mongod --shutdown

    According to the official doc : manage-mongodb-processes/

    :D

    0 讨论(0)
  • 2020-12-04 05:27

    in the terminal window on your mac, press control+c

    0 讨论(0)
  • 2020-12-04 05:29

    One liners to start or stop mongodb service using command line;

    1. To start the service use: NET START MONGODB
    2. To stop the service use: NET STOP MONGODB

    I use this myself, it does work.

    0 讨论(0)
  • 2020-12-04 05:29

    CTRL + C

    on the windows command line

    0 讨论(0)
提交回复
热议问题