• GNU/Linux Gamers

    Hello. Yesterday I updated my NodeBB from 1.18.0 to .3 and restarted the computer it runs on (Ubuntu 20.04 ish, regular laptop home hosted) and when I boot it back up I realize the mongodb service won’t start no matter what. I couldn’t figure this out, and NodeBB doesn’t start of course if database isn’t running.

    I looked around and realized that it wasn’t loading the confit file or something, because there error was that it couldn’t find a database at this path because it was hosted in a different path. (It thought it was in default db folder but I set config to a different
    Anyway I can get it to work if I open a terminal and sudo mongodb -dbpath my/correct/path

    But I would rather not keep it in a terminal window and instead have it be a service

  • Topic has been marked as a question  dunlix dunlix 
  • Community Rep

    @dunlix So you updated NodeBB only? No other system updates that may have touched mongodb, correct? Cuz, if so, then this just seems bizarre - why, oh why, would a NodeBB update/grade have anything to do with mongodb? Mongodb should still start regardless, independent, of any NodeBB changes. It is not like they are joined at the hip. One uses your pkg manager to update, whilst the other is.... other... depending on how you do it.

    If sudo is working for you, and assuming that you are otherwise utilizing systemd to launch mongodb, I suggest you either 1) examine the mongodb service file and tweak to point to correct path, or 2) relocate that mongodb data dir to where mongodb expects to find it. Then go from there.

    Hope this helps. But, like I said, unless you also ran some system wide updates, this seems rather bizarre.

    Good luck and have fun! o/ 🐕

    @dunlix said in Mongodb not working:

    realized that it wasn’t loading the confit file or something, because there error was that it couldn’t find a database at this path

    This needs to be investigated further. Logs??

  • GNU/Linux Gamers

    @gotwf I agree I’m the sense that this problem really isn’t a bug with NodeBB unless it messed with systemctl or something (I don’t even have NodeBB running as a service)
    Of course I would rather mongo not be in console window because of clutter, security, etc.

    The problem really is that Systemctl or services or whatever fail to try to start mongo with proper path and it doesn’t work ofc. But I don’t know how to fix this, even though it’s probably s simple fix.

    Also I didn’t run any updates other than NodeBB until after this problem started

  • GNU/Linux Gamers

    @gotwf also I can get logs later if you tell me where to find them
    I guess they will say the same thing that the path is invalid

  • Community Rep

    @dunlix Cannot speak for Ubuntu but on CentOS they are thus:

    [[email protected] mongodb]# pwd
    /var/log/mongodb
    [[email protected] mongodb]# ll
    total 11533
    -rw-r----- 1 mongod mongod 11753544 Sep 22 20:39 mongod.log
    
    

    Similarly, I expect your mongo.conf to be located under /etc:

    [[email protected] ~]# ll /etc/mongod.conf
    
    

    I expect same on Ubuntu but one never knows. Especially since your data dir appears to be in an atypical location.

    In any event, you should be able to scout mongod.conf for parameters such as system log and data dir paths.

    [[email protected] ~]# grep -i dbpath /etc/mongod.conf
      dbPath: /var/lib/mongo
    
    

    Then edit your nodebb config.json as appropriate.

    Seems like maybe, just maybe, your nodebb update/grade may have somehow overwritten your config.json? 🤔

    Have fun and good luck! o/

  • GNU/Linux Gamers

    @gotwf I know my NodeBB config wasn’t changed or anything because I actually checked in case I overwrote it.
    If all comes to loss then I could just move the db to its default location that it wants

  • Community Rep

    @dunlix Would not it be simpler to just tweak your nodebb config.js to point to the correct mongod datadir?

  • GNU/Linux Gamers

    @gotwf doesn’t NodeBB only connect to mongo through local host and default port? I didn’t think the data dir. is even a part of the NodeBB.config

  • Community Rep

    @dunlix Uh, duh!! Apologies for the brain fart on that one. !Aye, caramba!! 🤦

  • GNU/Linux Gamers

    @gotwf I have a little update on this.
    Everywhere I can find, config files say that my data is and should be stored in /var/lib/mongodb (it is) but when I type sudo mongod in a terminal this is what it gives me:

    @hp-laptop-nodebb:~$ sudo mongod
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] MongoDB starting : pid=201574 port=27017 dbpath=/data/db 64-bit host=hp-laptop-nodebb
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] db version v3.6.8
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1f  31 Mar 2020
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] allocator: tcmalloc
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] modules: none
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] build environment:
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten]     distarch: x86_64
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten]     target_arch: x86_64
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] options: {}
    2021-11-15T18:00:36.714-0500 I STORAGE  [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] now exiting
    2021-11-15T18:00:36.714-0500 I CONTROL  [initandlisten] shutting down with code:100
    

    Notice how it says NonExistentPath: Data directory /data/db not found yet all config files say it's in /var/lib/mongodb. This is so confusing.

    Furthermore, now the service (mongodb.service) starts fine on its own,

    @hp-laptop-nodebb:~$ sudo systemctl restart mongodb && sudo systemctl status mongodb
    ● mongodb.service - An object/document-oriented database
         Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
         Active: active (running) since Mon 2021-11-15 18:05:39 EST; 38ms ago
           Docs: man:mongod(1)
       Main PID: 201756 (mongod)
          Tasks: 1 (limit: 9367)
         Memory: 6.7M
         CGroup: /system.slice/mongodb.service
                 └─201756 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf
    
    
    

    only NodeBB can't connect to it

    2021-11-15T22:45:56.110Z [4567/140436] - info: [app] Database connection closed.
    2021-11-15T22:45:56.110Z [4567/140436] - info: [app] Shutdown complete.
    [cluster] Child Process (140436) has exited (code: 0, signal: null)
    2021-11-15T22:46:00.292Z [4567/199420] - error: MongoServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
        at Timeout._onTimeout (/var/www/nbb/node_modules/mongodb/lib/sdam/topology.js:325:38)
        at listOnTimeout (internal/timers.js:557:17)
        at processTimers (internal/timers.js:500:7)
    

    unless I have it open in a terminal window like before:

    2021-11-15T23:08:00.807Z [4567/201950] - info: NodeBB is now listening on: 0.0.0.0:4567
    

    if anyone would be interested in helping me and would like any additional logs, I'd be happy to provide them through PM's.

    Thanks for helping

  • Community Rep

    @dunlix Well, I do not use Ubuntu for long while now so cannot comment there. Mongodb Debian pkgs default to /var/lib/mongodb. The contents of wh/should look something akin to this:

    [email protected]:~# ll /var/lib/mongodb/
    total 421696
    drwxr-xr-x  4 mongodb mongodb      4096 Nov 16 00:26 .
    drwxr-xr-x 32 root    root         4096 Apr 12  2021 ..
    -rw-------  1 mongodb mongodb        47 Apr 11  2021 WiredTiger
    -rw-------  1 mongodb mongodb        21 Apr 11  2021 WiredTiger.lock
    -rw-------  1 mongodb mongodb      1455 Nov 16 00:26 WiredTiger.turtle
    -rw-------  1 mongodb mongodb    241664 Nov 16 00:26 WiredTiger.wt
    -rw-------  1 mongodb mongodb     36864 Nov 16 00:26 WiredTigerHS.wt
    -rw-------  1 mongodb mongodb     36864 Nov  3 01:53 _mdb_catalog.wt
    -rw-------  1 mongodb mongodb     36864 Nov  3 01:53 collection-0--6779710148686833028.wt
    -rw-------  1 mongodb mongodb      4096 Nov  3 01:52 collection-0--8716107555814307976.wt
    -rw-------  1 mongodb mongodb 114978816 Nov  3 01:51 collection-0-7297207552526326231.wt
    -rw-------  1 mongodb mongodb 223993856 Nov 16 00:26 collection-10--6779710148686833028.wt
    -rw-------  1 mongodb mongodb     36864 Nov  3 01:52 collection-11--6779710148686833028.wt
    -rw-------  1 mongodb mongodb     32768 Nov  3 01:52 collection-13--6779710148686833028.wt
    -rw-------  1 mongodb mongodb     32768 Nov  3 01:52 collection-15--6779710148686833028.wt
    -rw-------  1 mongodb mongodb     12288 Nov  3 01:52 collection-17--6779710148686833028.wt
    
    

    The db location is configured in /etc/mongod.conf:

    [email protected]:~# grep -i db /etc/mongod.conf 
    #   http://docs.mongodb.org/manual/reference/configuration-options/
      dbPath: /var/lib/mongodb
    
    

    I would expect Ubuntu to be same. Use systemctl to stop and start mongodb service. Check the mongo server via systemctl status.

    [email protected]:~# systemctl status mongod
    ● mongod.service - MongoDB Database Server
       Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
       Active: active (running) since Wed 2021-11-03 01:51:58 UTC; 1 weeks 5 days ago
         Docs: https://docs.mongodb.org/manual
     Main PID: 573 (mongod)
       Memory: 208.2M
       CGroup: /system.slice/mongod.service
               └─573 /usr/bin/mongod --config /etc/mongod.conf
    

    If running and all reports back dandy confirm it is listening on port 27017:

    [email protected]:~# netstat -na | grep 27017
    tcp        0      0 192.168.128.121:27017   0.0.0.0:*               LISTEN     
    tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN     
    tcp        0      0 192.168.128.121:38624   192.168.128.121:27017   ESTABLISHED
    tcp        0      0 192.168.128.121:37938   192.168.128.122:27017   ESTABLISHED
    tcp        0      0 192.168.128.121:27017   192.168.128.122:56238   ESTABLISHED
    tcp        0      0 192.168.128.121:33606   192.168.128.123:27017   ESTABLISHED
    
    

    But I got a feelin' that yours is not and only listening via unix socket. So please check mongo's "Net" settings in /etc/mongod.conf:

    # network interfaces
    net:
      port: 27017
      bindIp: 127.0.0.1
    

    NodeBB should now be able to talk to MongoDB. Start it from CLI with logging.

  • GNU/Linux Admin

    @dunlix I believe /data/db is just the default placeholder, so that is why it is trying to access it. You've executed mongod on its own with no flags, so it assumes the default config options, since it doesn't know where to locate the config file at /etc/mongod.conf 😄

    That said, on Ubuntu the logs are kept at /var/log/mongodb/mongodb.log

    Can you tail -F /var/log/mongodb/mongodb.log and then in another terminal sudo systemctl start mongodb?

  • Community Rep

    @dunlix said in Mongodb not working:

    I looked around and realized that it wasn’t loading the confit file or something,

    Hmmm..... I wonder... Reaching here but perchance might your mongod.conf file have become corrupted in some manner? You said all you did was a system upgrade and that should not have touched mongod.conf on a running system. But one never knows....

    Also, along related note, mongod.conf is ASCII text only. No UTF-8. So if your text editor somehow slipped a little utf-8 in there during some edit, but you did not reboot until the update, and then/now mongod can no longer read/load mongod.conf? Maybe, just maybe?

    But mainly in the main, need to confirm mongod is indeed listening on localhost port 27017.

  • GNU/Linux Gamers

    @gotwf said in Mongodb not working:

    But mainly in the main, need to confirm mongod is indeed listening on localhost port 27017.

    Yes it is cause when I start it the right way I only specify the dbpath and NodeBB can connect right away.

  • GNU/Linux Admin

    @dunlix logs logs logs from /var/log/mongodb/mongodb.log please...

    I'm assuming you installed mongo via mongodb-org from their apt repos. Not sure what mongo is like if you install it manually, etc.

  • GNU/Linux Gamers

    @julian I did use apt I’ll get the logs later today

  • GNU/Linux Admin

    @dunlix Thanks 😄 I think the clues may be there.

  • Community Rep

    @dunlix It would be beneficial to confirm APT-Sources, e.g.;

    APT-Sources: http://repo.mongodb.org/apt/debian buster/mongodb-org/4.4/main amd64 Packages
    Description: MongoDB shell client
    

    Note the repo.mongodb.org bit above. Preferential to use mongo built pkgs if available. And they should be for Ubuntu. But maybe not set as default? So just confirm this bit for me whilst at it, eh?

Suggested Topics

  • 3
  • 4
  • 1
  • 9
  • 4
| |