Anthony
Anthony

Reputation: 14279

Can't start mongodb through systemctl, error logs won't show up

I cannot boot MongoDB via systemctl.

When I try, I get an error, but nothing comes through the log.

When I try and run it manually via $ /usr/bin/mongod --config /etc/mongod.conf no error message comes through the log.

When I turn off logging in mongod.conf, an error message comes out that I don't have rights to the directory with the data (which is to be expected).

However, I can boot the process with sudo such as: $ sudo /usr/bin/mongod --config /etc/mongod.conf, the process runs but it is tied to my terminal so if my session closes so does MongoDB. Hence why I am trying to run it with systemctl.

Then when I try and run with sudo in my service such as: ExecStart=/usr/bin/sudo /usr/bin/mongod --config /etc/mongod.conf

Then it doesn't start and no error log comes through.

My conf file:

# mongod.conf

# for documentation of all options, see:

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

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

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

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

My service:

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

[Service]
Restart=always
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/sudo /usr/bin/mongod --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 mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings

So it becomes an impossible question. When I try and boot it through systemctl no error log comes through /var/log/mongodb/mongod.log. If I run it manually I get an error saying that I don't have access to the data folder since the data folder is owned by the mongodb user, which is expected.

What can I do to see what is causing my service above to fail? I don't want to use sudo in my ExecStart command but whether I do or I don't I get the same problem: the service fails to start and no logs come through my Mongo log file.

Upvotes: 0

Views: 3604

Answers (1)

Check of your service is failed

systemctl is-failed mongodb.service

Get failure logs

Journalctl is a utility for querying and displaying logs from journald, systemd's logging service.

get latest 20 lines of logs which will you failure details

journalctl | grep mongod | tail -n20

enter image description here


Use journalctl -u service and tail to get top 20 logs

journalctl -u mongodb.service | tail -n20

Get list of all failed services

systemctl list-units --failed

enter image description here

Read - https://www.cyberciti.biz/faq/systemd-systemctl-list-all-failed-units-services-on-linux/

Upvotes: 2

Related Questions