Start mongod service at system startup

19,338

Solution 1

You can either put the command in your /etc/bashrc script under and if condition i.e. if the mongod process is not already running, then start it.

Other way is to modify your /etc/rc.local and add the command to start mongod in that file. It will start at bootup.

Solution 2

Use the following command to autostart mongodb when system start.

systemctl enable mongod.service
Share:
19,338

Related videos on Youtube

Don Diego
Author by

Don Diego

Passion for programming and frontend in general, degree in Computer Science

Updated on June 07, 2022

Comments

  • Don Diego
    Don Diego almost 2 years

    I recently updated mongodb, and I run Linux Mint (an Ubuntu based system) and every time I start it up, i cannot use Robomongo because the service mongod is not automatically started; every time I need to open up a terminal and use

    sudo service mongod start
    

    Is there a way to start mongod automatically at system start?

    • molaga
      molaga over 7 years
      sudo systemctl enable mongod && sudo systemctl start mongod
  • Don Diego
    Don Diego over 7 years
    at last I used the second option, since I opened /etc/bash.bashrc (I don't have a bashrc file) and I found it way too complex to edit. Thanks!
  • Don Diego
    Don Diego over 7 years
    that's strange, it works on reboot, but ater turning off the pc and restarting it the day after, it doesn't work anymore. Don't know why!
  • Don Diego
    Don Diego about 6 years
    there's no systemctl on ubuntu (mint)
  • Harshal Yeole
    Harshal Yeole over 5 years
    Works for debian
  • Don Diego
    Don Diego about 4 years
    Yeah, but I asked for linux mint, not for debian.
  • Navid
    Navid almost 4 years
    I used this command but it seems run without any error message, however I typed "mongo" I got this error:MongoDB shell version v4.2.8 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServic‌​eName=mongodb 2020-07-12T19:33:16.990+0430 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
  • hdoitc
    hdoitc about 3 years
    @PredatorX systemctl start mongod and after that: mongo
  • Eric
    Eric almost 3 years
    @Don Diego I'm using ubuntu (mint), it has the systemctl command.
  • Don Diego
    Don Diego almost 2 years
    @Eric yeah thank you, I asked it 5 years ago.