How to start MongoDB server on system start?












67















I have to start my MongoDB server every time the system restarts. How do I configure it to start with my OS? I am on Ubuntu 11.04.










share|improve this question













migrated from stackoverflow.com Sep 15 '11 at 7:08


This question came from our site for professional and enthusiast programmers.














  • 1





    I wonder why noone recommends using upstart here.

    – Tom
    Mar 9 '12 at 17:37
















67















I have to start my MongoDB server every time the system restarts. How do I configure it to start with my OS? I am on Ubuntu 11.04.










share|improve this question













migrated from stackoverflow.com Sep 15 '11 at 7:08


This question came from our site for professional and enthusiast programmers.














  • 1





    I wonder why noone recommends using upstart here.

    – Tom
    Mar 9 '12 at 17:37














67












67








67


28






I have to start my MongoDB server every time the system restarts. How do I configure it to start with my OS? I am on Ubuntu 11.04.










share|improve this question














I have to start my MongoDB server every time the system restarts. How do I configure it to start with my OS? I am on Ubuntu 11.04.







mongodb






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Sep 11 '11 at 2:14







Pankaj











migrated from stackoverflow.com Sep 15 '11 at 7:08


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com Sep 15 '11 at 7:08


This question came from our site for professional and enthusiast programmers.










  • 1





    I wonder why noone recommends using upstart here.

    – Tom
    Mar 9 '12 at 17:37














  • 1





    I wonder why noone recommends using upstart here.

    – Tom
    Mar 9 '12 at 17:37








1




1





I wonder why noone recommends using upstart here.

– Tom
Mar 9 '12 at 17:37





I wonder why noone recommends using upstart here.

– Tom
Mar 9 '12 at 17:37










11 Answers
11






active

oldest

votes


















98














I had the same "problem" on Debian jessie, and my simple solution is:



systemctl enable mongod.service


I think in Ubuntu it's the same.






share|improve this answer





















  • 9





    Worked for me on Ubuntu Mate 16.04.2 LTS

    – Muhammad Gelbana
    Feb 18 '17 at 12:50











  • This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

    – dragosrsupercool
    May 25 '17 at 7:20






  • 2





    Pity there is no info in official documentation about starting the service.

    – UpTheCreek
    Jan 9 '18 at 12:31






  • 2





    may need to (sudo) systemctl start mongod to start the mongd service

    – Jeff Xiao
    Apr 3 '18 at 11:47






  • 1





    Also works on ubuntu 18.04 LTS

    – 89n3ur0n
    Aug 21 '18 at 16:08



















36














If you install MongoDB using the Advanced Packaging Tool (apt) then it'll configure your startup scripts to automatically run Mongo when the system boots.



The steps are as follows, first configure apt to be able to download the Mongo package:



sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo nano /etc/apt/sources.list


Add this line to sources.list then save:



deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen


Then download and install Mongo with the apt-get utility:



sudo apt-get update
sudo apt-get upgrade
sudo apt-get install mongodb-10gen


If you want to make any changes to config, edit your mongodb.conf and restart: 



sudo nano /etc/mongodb.conf
sudo service mongod restart





share|improve this answer





















  • 4





    If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

    – kynan
    Dec 5 '12 at 12:08



















11














Controlling all the init.d service links should be done with the update-rc.d tool



i.e. to turn on the mongod daemon in the default runlevels (i.e. turn it on at boot):



update-rc.d mongodb defaults


See https://help.ubuntu.com/community/UbuntuBootupHowto for more information. This link tells you everything you want to know about how to set programs at boot.






share|improve this answer





















  • 2





    The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

    – kynan
    Dec 5 '12 at 12:04











  • do i need to do this?

    – tofutim
    Mar 11 '18 at 1:53



















5














I am using crontab for Ubuntu. It works fine. To be able to edit file



Sudo crontab –e 


Add this line to the file



@reboot sudo service mongod start &


The "&" sigh at the end help it to work background.



Ctrl + x for exit, press "Y" once prompted. And keep the file name as "crontab".






share|improve this answer

































    4














    If you have installed the MongoDB Community Edition (which is the recommended way since it receives more frequent updates than the package distributed in the Ubuntu package repository) you configure the start / stop behaviour of mongod via the upstart init script /etc/init/mongod.conf, which defaults to start the daemon automatically on boot



    start on runlevel [2345]
    stop on runlevel [06]


    If you do not want it to start automatically, replace those 2 lines with



    stop on runlevel [023456]





    share|improve this answer


























    • Will this start the server before anyone logs into the system?

      – Gabriel Fair
      Mar 17 '18 at 16:13











    • @GabrielFair Yes

      – kynan
      Aug 5 '18 at 11:24





















    2














    If you have Ubuntu 16.04 LTS, you can enable mongo to start on boot typing this in your console:
    sudo systemctl enable mongod
    I have used this approach with MongoDB Community Edition 3.6 and it works. Reboot your machine and test if mongo is running typing:
    sudo service mongod status






    share|improve this answer































      1














      chkconfig --levels 235 mongod on?



      where mongodb is the name of your service






      share|improve this answer



















      • 2





        The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

        – kynan
        Dec 5 '12 at 12:16











      • @kynan Edit it how? What do I change / add to the mongod.conf file?

        – Kieveli
        Apr 28 '16 at 13:48













      • @Kieveli: see this answer

        – kynan
        Apr 29 '16 at 22:46



















      1














      I have consistently used this post as a starting point to get a new sharding rig up and running. It includes a section on configuring upstart that I've also used.



      http://joslynesser.com/blog/archives/2010/09/28/mongodb-sharding-guide-server-setup-on-ubuntu-ec2/






      share|improve this answer



















      • 1





        Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

        – rigved
        Dec 23 '11 at 6:39





















      1














      If you install MongoDB with apt-get as described in the MongoDB Ubuntu installation guide, it will come with a basic startup script and config file. (use of a config file is highly recommended)



      You can also take a look here for an old post that links to an init.d script.



      In either case, the basic premise is that you're setting up a service and then configuring to start-stop with the computer. This is pretty common technique for servers, there are lots of tutorials around for doing exactly this.






      share|improve this answer





















      • 2





        no longer the case in 16.04

        – chovy
        Dec 10 '16 at 6:59



















      1














      You can use systemctl command to enable your mongo service at run at system boot.



      Create a service such that



      sudo nano /etc/systemd/system/mongodb.service


      Place content in the file



      [Unit]
      Description=MongoDB Database Service
      Wants=network.target
      After=network.target

      [Service]
      ExecStart=/usr/bin/mongod --config /etc/mongod.conf
      ExecReload=/bin/kill -HUP $MAINPID
      Restart=always
      User=mongodb
      Group=mongodb
      StandardOutput=syslog
      StandardError=syslog


      after that you will be able to use service commands like



      sudo service mongod start|stop|restart


      and then if you want to make it up at machine boot, you can create mongod file under /etc/init.d/






      share|improve this answer































        0














        sudo service mongod start



        Enter Password






        share|improve this answer








        New contributor




        Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "89"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f61503%2fhow-to-start-mongodb-server-on-system-start%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown
























          11 Answers
          11






          active

          oldest

          votes








          11 Answers
          11






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          98














          I had the same "problem" on Debian jessie, and my simple solution is:



          systemctl enable mongod.service


          I think in Ubuntu it's the same.






          share|improve this answer





















          • 9





            Worked for me on Ubuntu Mate 16.04.2 LTS

            – Muhammad Gelbana
            Feb 18 '17 at 12:50











          • This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

            – dragosrsupercool
            May 25 '17 at 7:20






          • 2





            Pity there is no info in official documentation about starting the service.

            – UpTheCreek
            Jan 9 '18 at 12:31






          • 2





            may need to (sudo) systemctl start mongod to start the mongd service

            – Jeff Xiao
            Apr 3 '18 at 11:47






          • 1





            Also works on ubuntu 18.04 LTS

            – 89n3ur0n
            Aug 21 '18 at 16:08
















          98














          I had the same "problem" on Debian jessie, and my simple solution is:



          systemctl enable mongod.service


          I think in Ubuntu it's the same.






          share|improve this answer





















          • 9





            Worked for me on Ubuntu Mate 16.04.2 LTS

            – Muhammad Gelbana
            Feb 18 '17 at 12:50











          • This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

            – dragosrsupercool
            May 25 '17 at 7:20






          • 2





            Pity there is no info in official documentation about starting the service.

            – UpTheCreek
            Jan 9 '18 at 12:31






          • 2





            may need to (sudo) systemctl start mongod to start the mongd service

            – Jeff Xiao
            Apr 3 '18 at 11:47






          • 1





            Also works on ubuntu 18.04 LTS

            – 89n3ur0n
            Aug 21 '18 at 16:08














          98












          98








          98







          I had the same "problem" on Debian jessie, and my simple solution is:



          systemctl enable mongod.service


          I think in Ubuntu it's the same.






          share|improve this answer















          I had the same "problem" on Debian jessie, and my simple solution is:



          systemctl enable mongod.service


          I think in Ubuntu it's the same.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 12 '17 at 9:19

























          answered Dec 19 '16 at 10:15









          BiberBiber

          1,08144




          1,08144








          • 9





            Worked for me on Ubuntu Mate 16.04.2 LTS

            – Muhammad Gelbana
            Feb 18 '17 at 12:50











          • This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

            – dragosrsupercool
            May 25 '17 at 7:20






          • 2





            Pity there is no info in official documentation about starting the service.

            – UpTheCreek
            Jan 9 '18 at 12:31






          • 2





            may need to (sudo) systemctl start mongod to start the mongd service

            – Jeff Xiao
            Apr 3 '18 at 11:47






          • 1





            Also works on ubuntu 18.04 LTS

            – 89n3ur0n
            Aug 21 '18 at 16:08














          • 9





            Worked for me on Ubuntu Mate 16.04.2 LTS

            – Muhammad Gelbana
            Feb 18 '17 at 12:50











          • This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

            – dragosrsupercool
            May 25 '17 at 7:20






          • 2





            Pity there is no info in official documentation about starting the service.

            – UpTheCreek
            Jan 9 '18 at 12:31






          • 2





            may need to (sudo) systemctl start mongod to start the mongd service

            – Jeff Xiao
            Apr 3 '18 at 11:47






          • 1





            Also works on ubuntu 18.04 LTS

            – 89n3ur0n
            Aug 21 '18 at 16:08








          9




          9





          Worked for me on Ubuntu Mate 16.04.2 LTS

          – Muhammad Gelbana
          Feb 18 '17 at 12:50





          Worked for me on Ubuntu Mate 16.04.2 LTS

          – Muhammad Gelbana
          Feb 18 '17 at 12:50













          This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

          – dragosrsupercool
          May 25 '17 at 7:20





          This worked for me (Ubuntu 16.04 LTS, MongoDB 3.4.4)

          – dragosrsupercool
          May 25 '17 at 7:20




          2




          2





          Pity there is no info in official documentation about starting the service.

          – UpTheCreek
          Jan 9 '18 at 12:31





          Pity there is no info in official documentation about starting the service.

          – UpTheCreek
          Jan 9 '18 at 12:31




          2




          2





          may need to (sudo) systemctl start mongod to start the mongd service

          – Jeff Xiao
          Apr 3 '18 at 11:47





          may need to (sudo) systemctl start mongod to start the mongd service

          – Jeff Xiao
          Apr 3 '18 at 11:47




          1




          1





          Also works on ubuntu 18.04 LTS

          – 89n3ur0n
          Aug 21 '18 at 16:08





          Also works on ubuntu 18.04 LTS

          – 89n3ur0n
          Aug 21 '18 at 16:08













          36














          If you install MongoDB using the Advanced Packaging Tool (apt) then it'll configure your startup scripts to automatically run Mongo when the system boots.



          The steps are as follows, first configure apt to be able to download the Mongo package:



          sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
          sudo nano /etc/apt/sources.list


          Add this line to sources.list then save:



          deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen


          Then download and install Mongo with the apt-get utility:



          sudo apt-get update
          sudo apt-get upgrade
          sudo apt-get install mongodb-10gen


          If you want to make any changes to config, edit your mongodb.conf and restart: 



          sudo nano /etc/mongodb.conf
          sudo service mongod restart





          share|improve this answer





















          • 4





            If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:08
















          36














          If you install MongoDB using the Advanced Packaging Tool (apt) then it'll configure your startup scripts to automatically run Mongo when the system boots.



          The steps are as follows, first configure apt to be able to download the Mongo package:



          sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
          sudo nano /etc/apt/sources.list


          Add this line to sources.list then save:



          deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen


          Then download and install Mongo with the apt-get utility:



          sudo apt-get update
          sudo apt-get upgrade
          sudo apt-get install mongodb-10gen


          If you want to make any changes to config, edit your mongodb.conf and restart: 



          sudo nano /etc/mongodb.conf
          sudo service mongod restart





          share|improve this answer





















          • 4





            If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:08














          36












          36








          36







          If you install MongoDB using the Advanced Packaging Tool (apt) then it'll configure your startup scripts to automatically run Mongo when the system boots.



          The steps are as follows, first configure apt to be able to download the Mongo package:



          sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
          sudo nano /etc/apt/sources.list


          Add this line to sources.list then save:



          deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen


          Then download and install Mongo with the apt-get utility:



          sudo apt-get update
          sudo apt-get upgrade
          sudo apt-get install mongodb-10gen


          If you want to make any changes to config, edit your mongodb.conf and restart: 



          sudo nano /etc/mongodb.conf
          sudo service mongod restart





          share|improve this answer















          If you install MongoDB using the Advanced Packaging Tool (apt) then it'll configure your startup scripts to automatically run Mongo when the system boots.



          The steps are as follows, first configure apt to be able to download the Mongo package:



          sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
          sudo nano /etc/apt/sources.list


          Add this line to sources.list then save:



          deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen


          Then download and install Mongo with the apt-get utility:



          sudo apt-get update
          sudo apt-get upgrade
          sudo apt-get install mongodb-10gen


          If you want to make any changes to config, edit your mongodb.conf and restart: 



          sudo nano /etc/mongodb.conf
          sudo service mongod restart






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jun 16 '17 at 3:38









          stenci

          264312




          264312










          answered Sep 11 '11 at 8:58







          Chris Fulstow















          • 4





            If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:08














          • 4





            If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:08








          4




          4





          If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

          – kynan
          Dec 5 '12 at 12:08





          If you want to later change it to not automatically start MongoDB on startup, edit /etc/init/mongodb.conf.

          – kynan
          Dec 5 '12 at 12:08











          11














          Controlling all the init.d service links should be done with the update-rc.d tool



          i.e. to turn on the mongod daemon in the default runlevels (i.e. turn it on at boot):



          update-rc.d mongodb defaults


          See https://help.ubuntu.com/community/UbuntuBootupHowto for more information. This link tells you everything you want to know about how to set programs at boot.






          share|improve this answer





















          • 2





            The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:04











          • do i need to do this?

            – tofutim
            Mar 11 '18 at 1:53
















          11














          Controlling all the init.d service links should be done with the update-rc.d tool



          i.e. to turn on the mongod daemon in the default runlevels (i.e. turn it on at boot):



          update-rc.d mongodb defaults


          See https://help.ubuntu.com/community/UbuntuBootupHowto for more information. This link tells you everything you want to know about how to set programs at boot.






          share|improve this answer





















          • 2





            The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:04











          • do i need to do this?

            – tofutim
            Mar 11 '18 at 1:53














          11












          11








          11







          Controlling all the init.d service links should be done with the update-rc.d tool



          i.e. to turn on the mongod daemon in the default runlevels (i.e. turn it on at boot):



          update-rc.d mongodb defaults


          See https://help.ubuntu.com/community/UbuntuBootupHowto for more information. This link tells you everything you want to know about how to set programs at boot.






          share|improve this answer















          Controlling all the init.d service links should be done with the update-rc.d tool



          i.e. to turn on the mongod daemon in the default runlevels (i.e. turn it on at boot):



          update-rc.d mongodb defaults


          See https://help.ubuntu.com/community/UbuntuBootupHowto for more information. This link tells you everything you want to know about how to set programs at boot.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 16 '13 at 10:18









          Vladtn

          1033




          1033










          answered Dec 23 '11 at 6:17









          Ben WaldingBen Walding

          21123




          21123








          • 2





            The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:04











          • do i need to do this?

            – tofutim
            Mar 11 '18 at 1:53














          • 2





            The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

            – kynan
            Dec 5 '12 at 12:04











          • do i need to do this?

            – tofutim
            Mar 11 '18 at 1:53








          2




          2





          The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

          – kynan
          Dec 5 '12 at 12:04





          The 10gen MongoDB distribution does not use System-V style init scripts, you need to edit /etc/init/mongodb.conf.

          – kynan
          Dec 5 '12 at 12:04













          do i need to do this?

          – tofutim
          Mar 11 '18 at 1:53





          do i need to do this?

          – tofutim
          Mar 11 '18 at 1:53











          5














          I am using crontab for Ubuntu. It works fine. To be able to edit file



          Sudo crontab –e 


          Add this line to the file



          @reboot sudo service mongod start &


          The "&" sigh at the end help it to work background.



          Ctrl + x for exit, press "Y" once prompted. And keep the file name as "crontab".






          share|improve this answer






























            5














            I am using crontab for Ubuntu. It works fine. To be able to edit file



            Sudo crontab –e 


            Add this line to the file



            @reboot sudo service mongod start &


            The "&" sigh at the end help it to work background.



            Ctrl + x for exit, press "Y" once prompted. And keep the file name as "crontab".






            share|improve this answer




























              5












              5








              5







              I am using crontab for Ubuntu. It works fine. To be able to edit file



              Sudo crontab –e 


              Add this line to the file



              @reboot sudo service mongod start &


              The "&" sigh at the end help it to work background.



              Ctrl + x for exit, press "Y" once prompted. And keep the file name as "crontab".






              share|improve this answer















              I am using crontab for Ubuntu. It works fine. To be able to edit file



              Sudo crontab –e 


              Add this line to the file



              @reboot sudo service mongod start &


              The "&" sigh at the end help it to work background.



              Ctrl + x for exit, press "Y" once prompted. And keep the file name as "crontab".







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited May 11 '17 at 11:35









              Sumeet Deshmukh

              4,42653071




              4,42653071










              answered May 11 '17 at 11:15









              CodeGenchCodeGench

              15111




              15111























                  4














                  If you have installed the MongoDB Community Edition (which is the recommended way since it receives more frequent updates than the package distributed in the Ubuntu package repository) you configure the start / stop behaviour of mongod via the upstart init script /etc/init/mongod.conf, which defaults to start the daemon automatically on boot



                  start on runlevel [2345]
                  stop on runlevel [06]


                  If you do not want it to start automatically, replace those 2 lines with



                  stop on runlevel [023456]





                  share|improve this answer


























                  • Will this start the server before anyone logs into the system?

                    – Gabriel Fair
                    Mar 17 '18 at 16:13











                  • @GabrielFair Yes

                    – kynan
                    Aug 5 '18 at 11:24


















                  4














                  If you have installed the MongoDB Community Edition (which is the recommended way since it receives more frequent updates than the package distributed in the Ubuntu package repository) you configure the start / stop behaviour of mongod via the upstart init script /etc/init/mongod.conf, which defaults to start the daemon automatically on boot



                  start on runlevel [2345]
                  stop on runlevel [06]


                  If you do not want it to start automatically, replace those 2 lines with



                  stop on runlevel [023456]





                  share|improve this answer


























                  • Will this start the server before anyone logs into the system?

                    – Gabriel Fair
                    Mar 17 '18 at 16:13











                  • @GabrielFair Yes

                    – kynan
                    Aug 5 '18 at 11:24
















                  4












                  4








                  4







                  If you have installed the MongoDB Community Edition (which is the recommended way since it receives more frequent updates than the package distributed in the Ubuntu package repository) you configure the start / stop behaviour of mongod via the upstart init script /etc/init/mongod.conf, which defaults to start the daemon automatically on boot



                  start on runlevel [2345]
                  stop on runlevel [06]


                  If you do not want it to start automatically, replace those 2 lines with



                  stop on runlevel [023456]





                  share|improve this answer















                  If you have installed the MongoDB Community Edition (which is the recommended way since it receives more frequent updates than the package distributed in the Ubuntu package repository) you configure the start / stop behaviour of mongod via the upstart init script /etc/init/mongod.conf, which defaults to start the daemon automatically on boot



                  start on runlevel [2345]
                  stop on runlevel [06]


                  If you do not want it to start automatically, replace those 2 lines with



                  stop on runlevel [023456]






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Apr 29 '16 at 22:46

























                  answered Apr 29 '16 at 22:35









                  kynankynan

                  1,66011723




                  1,66011723













                  • Will this start the server before anyone logs into the system?

                    – Gabriel Fair
                    Mar 17 '18 at 16:13











                  • @GabrielFair Yes

                    – kynan
                    Aug 5 '18 at 11:24





















                  • Will this start the server before anyone logs into the system?

                    – Gabriel Fair
                    Mar 17 '18 at 16:13











                  • @GabrielFair Yes

                    – kynan
                    Aug 5 '18 at 11:24



















                  Will this start the server before anyone logs into the system?

                  – Gabriel Fair
                  Mar 17 '18 at 16:13





                  Will this start the server before anyone logs into the system?

                  – Gabriel Fair
                  Mar 17 '18 at 16:13













                  @GabrielFair Yes

                  – kynan
                  Aug 5 '18 at 11:24







                  @GabrielFair Yes

                  – kynan
                  Aug 5 '18 at 11:24













                  2














                  If you have Ubuntu 16.04 LTS, you can enable mongo to start on boot typing this in your console:
                  sudo systemctl enable mongod
                  I have used this approach with MongoDB Community Edition 3.6 and it works. Reboot your machine and test if mongo is running typing:
                  sudo service mongod status






                  share|improve this answer




























                    2














                    If you have Ubuntu 16.04 LTS, you can enable mongo to start on boot typing this in your console:
                    sudo systemctl enable mongod
                    I have used this approach with MongoDB Community Edition 3.6 and it works. Reboot your machine and test if mongo is running typing:
                    sudo service mongod status






                    share|improve this answer


























                      2












                      2








                      2







                      If you have Ubuntu 16.04 LTS, you can enable mongo to start on boot typing this in your console:
                      sudo systemctl enable mongod
                      I have used this approach with MongoDB Community Edition 3.6 and it works. Reboot your machine and test if mongo is running typing:
                      sudo service mongod status






                      share|improve this answer













                      If you have Ubuntu 16.04 LTS, you can enable mongo to start on boot typing this in your console:
                      sudo systemctl enable mongod
                      I have used this approach with MongoDB Community Edition 3.6 and it works. Reboot your machine and test if mongo is running typing:
                      sudo service mongod status







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Feb 5 '18 at 20:41









                      Mariusz WiazowskiMariusz Wiazowski

                      1211




                      1211























                          1














                          chkconfig --levels 235 mongod on?



                          where mongodb is the name of your service






                          share|improve this answer



















                          • 2





                            The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

                            – kynan
                            Dec 5 '12 at 12:16











                          • @kynan Edit it how? What do I change / add to the mongod.conf file?

                            – Kieveli
                            Apr 28 '16 at 13:48













                          • @Kieveli: see this answer

                            – kynan
                            Apr 29 '16 at 22:46
















                          1














                          chkconfig --levels 235 mongod on?



                          where mongodb is the name of your service






                          share|improve this answer



















                          • 2





                            The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

                            – kynan
                            Dec 5 '12 at 12:16











                          • @kynan Edit it how? What do I change / add to the mongod.conf file?

                            – Kieveli
                            Apr 28 '16 at 13:48













                          • @Kieveli: see this answer

                            – kynan
                            Apr 29 '16 at 22:46














                          1












                          1








                          1







                          chkconfig --levels 235 mongod on?



                          where mongodb is the name of your service






                          share|improve this answer













                          chkconfig --levels 235 mongod on?



                          where mongodb is the name of your service







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 11 '11 at 2:20







                          Benjamin Udink ten Cate















                          • 2





                            The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

                            – kynan
                            Dec 5 '12 at 12:16











                          • @kynan Edit it how? What do I change / add to the mongod.conf file?

                            – Kieveli
                            Apr 28 '16 at 13:48













                          • @Kieveli: see this answer

                            – kynan
                            Apr 29 '16 at 22:46














                          • 2





                            The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

                            – kynan
                            Dec 5 '12 at 12:16











                          • @kynan Edit it how? What do I change / add to the mongod.conf file?

                            – Kieveli
                            Apr 28 '16 at 13:48













                          • @Kieveli: see this answer

                            – kynan
                            Apr 29 '16 at 22:46








                          2




                          2





                          The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

                          – kynan
                          Dec 5 '12 at 12:16





                          The 10gen MongoDB distribution does not use System-V style init scripts by default (though one is provided), edit /etc/init/mongodb.conf instead.

                          – kynan
                          Dec 5 '12 at 12:16













                          @kynan Edit it how? What do I change / add to the mongod.conf file?

                          – Kieveli
                          Apr 28 '16 at 13:48







                          @kynan Edit it how? What do I change / add to the mongod.conf file?

                          – Kieveli
                          Apr 28 '16 at 13:48















                          @Kieveli: see this answer

                          – kynan
                          Apr 29 '16 at 22:46





                          @Kieveli: see this answer

                          – kynan
                          Apr 29 '16 at 22:46











                          1














                          I have consistently used this post as a starting point to get a new sharding rig up and running. It includes a section on configuring upstart that I've also used.



                          http://joslynesser.com/blog/archives/2010/09/28/mongodb-sharding-guide-server-setup-on-ubuntu-ec2/






                          share|improve this answer



















                          • 1





                            Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

                            – rigved
                            Dec 23 '11 at 6:39


















                          1














                          I have consistently used this post as a starting point to get a new sharding rig up and running. It includes a section on configuring upstart that I've also used.



                          http://joslynesser.com/blog/archives/2010/09/28/mongodb-sharding-guide-server-setup-on-ubuntu-ec2/






                          share|improve this answer



















                          • 1





                            Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

                            – rigved
                            Dec 23 '11 at 6:39
















                          1












                          1








                          1







                          I have consistently used this post as a starting point to get a new sharding rig up and running. It includes a section on configuring upstart that I've also used.



                          http://joslynesser.com/blog/archives/2010/09/28/mongodb-sharding-guide-server-setup-on-ubuntu-ec2/






                          share|improve this answer













                          I have consistently used this post as a starting point to get a new sharding rig up and running. It includes a section on configuring upstart that I've also used.



                          http://joslynesser.com/blog/archives/2010/09/28/mongodb-sharding-guide-server-setup-on-ubuntu-ec2/







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Sep 15 '11 at 2:07









                          csiefcsief

                          111




                          111








                          • 1





                            Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

                            – rigved
                            Dec 23 '11 at 6:39
















                          • 1





                            Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

                            – rigved
                            Dec 23 '11 at 6:39










                          1




                          1





                          Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

                          – rigved
                          Dec 23 '11 at 6:39







                          Please do not post "only external links". It is possible that the external link may go down in future and this answer would then be incomplete. In addition to the link, please post the relevant part of the article here: eg. post the part that shows "How to start MongoDB server on system start?" using upstart.

                          – rigved
                          Dec 23 '11 at 6:39













                          1














                          If you install MongoDB with apt-get as described in the MongoDB Ubuntu installation guide, it will come with a basic startup script and config file. (use of a config file is highly recommended)



                          You can also take a look here for an old post that links to an init.d script.



                          In either case, the basic premise is that you're setting up a service and then configuring to start-stop with the computer. This is pretty common technique for servers, there are lots of tutorials around for doing exactly this.






                          share|improve this answer





















                          • 2





                            no longer the case in 16.04

                            – chovy
                            Dec 10 '16 at 6:59
















                          1














                          If you install MongoDB with apt-get as described in the MongoDB Ubuntu installation guide, it will come with a basic startup script and config file. (use of a config file is highly recommended)



                          You can also take a look here for an old post that links to an init.d script.



                          In either case, the basic premise is that you're setting up a service and then configuring to start-stop with the computer. This is pretty common technique for servers, there are lots of tutorials around for doing exactly this.






                          share|improve this answer





















                          • 2





                            no longer the case in 16.04

                            – chovy
                            Dec 10 '16 at 6:59














                          1












                          1








                          1







                          If you install MongoDB with apt-get as described in the MongoDB Ubuntu installation guide, it will come with a basic startup script and config file. (use of a config file is highly recommended)



                          You can also take a look here for an old post that links to an init.d script.



                          In either case, the basic premise is that you're setting up a service and then configuring to start-stop with the computer. This is pretty common technique for servers, there are lots of tutorials around for doing exactly this.






                          share|improve this answer















                          If you install MongoDB with apt-get as described in the MongoDB Ubuntu installation guide, it will come with a basic startup script and config file. (use of a config file is highly recommended)



                          You can also take a look here for an old post that links to an init.d script.



                          In either case, the basic premise is that you're setting up a service and then configuring to start-stop with the computer. This is pretty common technique for servers, there are lots of tutorials around for doing exactly this.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Dec 5 '12 at 12:09









                          kynan

                          1,66011723




                          1,66011723










                          answered Sep 11 '11 at 5:38









                          Gates VPGates VP

                          1193




                          1193








                          • 2





                            no longer the case in 16.04

                            – chovy
                            Dec 10 '16 at 6:59














                          • 2





                            no longer the case in 16.04

                            – chovy
                            Dec 10 '16 at 6:59








                          2




                          2





                          no longer the case in 16.04

                          – chovy
                          Dec 10 '16 at 6:59





                          no longer the case in 16.04

                          – chovy
                          Dec 10 '16 at 6:59











                          1














                          You can use systemctl command to enable your mongo service at run at system boot.



                          Create a service such that



                          sudo nano /etc/systemd/system/mongodb.service


                          Place content in the file



                          [Unit]
                          Description=MongoDB Database Service
                          Wants=network.target
                          After=network.target

                          [Service]
                          ExecStart=/usr/bin/mongod --config /etc/mongod.conf
                          ExecReload=/bin/kill -HUP $MAINPID
                          Restart=always
                          User=mongodb
                          Group=mongodb
                          StandardOutput=syslog
                          StandardError=syslog


                          after that you will be able to use service commands like



                          sudo service mongod start|stop|restart


                          and then if you want to make it up at machine boot, you can create mongod file under /etc/init.d/






                          share|improve this answer




























                            1














                            You can use systemctl command to enable your mongo service at run at system boot.



                            Create a service such that



                            sudo nano /etc/systemd/system/mongodb.service


                            Place content in the file



                            [Unit]
                            Description=MongoDB Database Service
                            Wants=network.target
                            After=network.target

                            [Service]
                            ExecStart=/usr/bin/mongod --config /etc/mongod.conf
                            ExecReload=/bin/kill -HUP $MAINPID
                            Restart=always
                            User=mongodb
                            Group=mongodb
                            StandardOutput=syslog
                            StandardError=syslog


                            after that you will be able to use service commands like



                            sudo service mongod start|stop|restart


                            and then if you want to make it up at machine boot, you can create mongod file under /etc/init.d/






                            share|improve this answer


























                              1












                              1








                              1







                              You can use systemctl command to enable your mongo service at run at system boot.



                              Create a service such that



                              sudo nano /etc/systemd/system/mongodb.service


                              Place content in the file



                              [Unit]
                              Description=MongoDB Database Service
                              Wants=network.target
                              After=network.target

                              [Service]
                              ExecStart=/usr/bin/mongod --config /etc/mongod.conf
                              ExecReload=/bin/kill -HUP $MAINPID
                              Restart=always
                              User=mongodb
                              Group=mongodb
                              StandardOutput=syslog
                              StandardError=syslog


                              after that you will be able to use service commands like



                              sudo service mongod start|stop|restart


                              and then if you want to make it up at machine boot, you can create mongod file under /etc/init.d/






                              share|improve this answer













                              You can use systemctl command to enable your mongo service at run at system boot.



                              Create a service such that



                              sudo nano /etc/systemd/system/mongodb.service


                              Place content in the file



                              [Unit]
                              Description=MongoDB Database Service
                              Wants=network.target
                              After=network.target

                              [Service]
                              ExecStart=/usr/bin/mongod --config /etc/mongod.conf
                              ExecReload=/bin/kill -HUP $MAINPID
                              Restart=always
                              User=mongodb
                              Group=mongodb
                              StandardOutput=syslog
                              StandardError=syslog


                              after that you will be able to use service commands like



                              sudo service mongod start|stop|restart


                              and then if you want to make it up at machine boot, you can create mongod file under /etc/init.d/







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Oct 30 '18 at 6:39









                              Touseef MurtazaTouseef Murtaza

                              112




                              112























                                  0














                                  sudo service mongod start



                                  Enter Password






                                  share|improve this answer








                                  New contributor




                                  Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.

























                                    0














                                    sudo service mongod start



                                    Enter Password






                                    share|improve this answer








                                    New contributor




                                    Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.























                                      0












                                      0








                                      0







                                      sudo service mongod start



                                      Enter Password






                                      share|improve this answer








                                      New contributor




                                      Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.










                                      sudo service mongod start



                                      Enter Password







                                      share|improve this answer








                                      New contributor




                                      Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      share|improve this answer



                                      share|improve this answer






                                      New contributor




                                      Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      answered 23 mins ago









                                      Vibhanshu RanaVibhanshu Rana

                                      1




                                      1




                                      New contributor




                                      Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.





                                      New contributor





                                      Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.






                                      Vibhanshu Rana is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.






























                                          draft saved

                                          draft discarded




















































                                          Thanks for contributing an answer to Ask Ubuntu!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid



                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.


                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function () {
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f61503%2fhow-to-start-mongodb-server-on-system-start%23new-answer', 'question_page');
                                          }
                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          GameSpot

                                          日野市

                                          Tu-95轟炸機