skip to Main Content

Mongo has suddenly stopped working within my Ubuntu 16.04 machine, so I am trying to restart it I’ am getting again and again though errors like the below:

 mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Τρι 2022-03-22 12:19:53 EET; 3h 46min ago
     Docs: https://docs.mongodb.org/manual
  Process: 27559 ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf (code=exited, status=1/FAILURE)
 Main PID: 27559 (code=exited, status=1/FAILURE)

systemd[1]: Started MongoDB Database Server.
systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: mongod.service: Unit entered failed state.
systemd[1]: mongod.service: Failed with result 'exit-code'.

I have revised the mongod.conf file, which is located in /etc and includes the below:

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
# engine: wiredTiger
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 23654
  bindIp: 0.0.0.0


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

security:
  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

Also the mongod.service located in /lib/systemd/system:

[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target

[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --auth --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

I have also changed ownership using the below commands according to this post:

sudo chown -R mongodb:mongodb /var/lib/mongodb
sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo chown mongodb:mongodb /tmp/mongodb-23654.sock
sudo chown -R mongodb:mongodb /var/log/mongodb

I have checked the folders and removed .lock files from /var/lib/mongodb/ which now looks like below:

 /var/lib/mongodb$ ls
    collection-0-2356690320700739995.wt   collection-2-2356690320700739995.wt  collection-8-5563536140699528517.wt  index-15-5563536140699528517.wt  index-5-5563536140699528517.wt  _mdb_catalog.wt    WiredTiger.wt
    collection-0-5563536140699528517.wt   collection-2-5563536140699528517.wt  diagnostic.data                      index-1-5563536140699528517.wt   index-6-2356690320700739995.wt  sizeStorer.wt
    collection-10-5563536140699528517.wt  collection-4-2356690320700739995.wt  index-10-2356690320700739995.wt      index-21-5563536140699528517.wt  index-7-5563536140699528517.wt  storage.bson
    collection-12-5563536140699528517.wt  collection-4-5563536140699528517.wt  index-11-5563536140699528517.wt      index-3-2356690320700739995.wt   index-9-2356690320700739995.wt  WiredTiger
    collection-14-5563536140699528517.wt  collection-6-5563536140699528517.wt  index-1-2356690320700739995.wt       index-3-5563536140699528517.wt   index-9-5563536140699528517.wt  WiredTigerLAS.wt
    collection-20-5563536140699528517.wt  collection-8-2356690320700739995.wt  index-13-5563536140699528517.wt      index-5-2356690320700739995.wt   journal                         WiredTiger.turtle

According to a previous post I had once enabled wiredTiger engine from mongod.conf but have now changed it back to the .conf shared above. Should I remove these files as well from this directory?

Finally, I have also checked the firewall for this port I am trying to use, it seems active.
Have no idea what I should fix I have read lots of related posts but haven’t done yet…

2

Answers


  1. sudo chown -R mongodb:mongodb /var/lib/mongodb
    sudo chown mongodb:mongodb /tmp/mongodb-27017.sock
    sudo chown mongodb:mongodb /tmp/mongodb-23654.sock
    sudo chown -R mongodb:mongodb /var/log/mongodb
    

    have you user mongodb? check it cat /etc/passwd |grep mongod

    sudo chown -R mongod:mongod /var/lib/mongodb
    sudo chown mongod:mongod /tmp/mongodb-27017.sock
    sudo chown mongod:mongod /tmp/mongodb-23654.sock
    sudo chown -R mongod:mongod /var/log/mongodb
    

    may be you need to chown them like this-> mongod.

    Login or Signup to reply.
  2. Had the same issue running MongoDB on centOS and reoccurred on restart, process should be similar on Ubuntu;

    run cat /etc/mongod.conf and ensure all referenced paths are available and owned by the MongoDB user

    In my case the missing directory/file was

    pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
    

    create files and folders where missing e.g

    sudo mkdir -p /var/run/mongodb
    sudo touch /var/run/mongodb/mongod.pid
    

    give correct ownership

    sudo chown -R mongod:mongod /var/run/mongodb
    

    start and check status

    sudo systemctl start mongod
    sudo systemctl status mongod  
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search