0

I've tried to install MongoDB 5.0 Community edition on Ubuntu 18.04 from the Official doc: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Everything went fine until I tried to run mongod service:

$ systemctl start mongod

Failed to start mongod.service: Unit mongod.service is not loaded properly: Invalid argument. See system logs and 'systemctl status mongod.service' for details.

I tried to gather infos:

$ systemctl status mongod.service
● mongod.service
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

$ sudo systemd-analyze verify mongod.service mongod.service: Service lacks both ExecStart= and ExecStop= setting. Refusing. mongod.service: Failed to create mongod.service/start: Unit mongod.service is not loaded properly: Argument invalide. Attempted to remove disk file system, and we can't allow that.

If I try to enable the service instead, I have the following message:

$ systemctl enable mongod.service
The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

Indeed, if I read the output from systemctl list-unit-files, the mongod service is flagged as static.

Here's my /lib/systemd/system/mongod.service contents (automatically written by installing mongodb):

  GNU nano 2.9.3                       /lib/systemd/system/mongod.service

[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 --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

The /var/log/mongodb/ folder is empty though.

Note that I had a previous versions of MongoDB installed, so I ran through the steps on this post:Apt-get fails on 16.04 or 18.04 installing mongodb

And I tried to installed MongoDB 4.2 after that. And the issue persists.

It is indeed installed though, as I can see its version:

db version v4.2.18
git version: f65ce5e25c0b26a00d091a4d24eec1a8b3a4c016
OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: x86_64
    target_arch: x86_64

What do these systemctl errors mean? What should I try to do? Thank you for reading.

EDIT: Note that I need to run the mongod command through sudo to have it working from the terminal.

So I tested to modify the mongod.service file in two waYS:

  • First with User=root, Group=root
  • Then by adding mongodb to my sudo group and using:
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=sudo /usr/bin/mongod --config /etc/mongod.conf

Both resulted in the same error: Invalid argument

  • Follow the installation steps for Ubuntu 20.04 and MongoDB 5.0 for your 18.04 LTS installation: https://askubuntu.com/a/842599/231142 I just did it and it worked just fine for my 18.04 LTS VM install I have. – Terrance Feb 20 '22 at 17:03
  • Does this answer your question? Apt-get fails on 16.04 or 18.04 installing mongodb Adding this here because the answer(s) should help you. – Terrance Feb 20 '22 at 17:05
  • Sorry @Terrance, that's the steps I followed, but I just pasted the wrong link in my post (edited now). So no, this didn't help. But thank you for your quick answer. – raaaahman Feb 21 '22 at 08:53
  • You may want to see: https://serverfault.com/questions/986416/systemctl-complains-about-no-installation-config-but-it-exists As your service file may not be correct. Your original error states "Service lacks both ExecStart= and ExecStop= setting." and everything in it is case sensitive as well. – Terrance Feb 21 '22 at 14:23
  • Your .service file is different than mine. Maybe back yours up to another location and replace it with the one I have below. A few of the lines are different that I can see between yours and mine. – Terrance Feb 24 '22 at 14:24
  • I just tried that. Still the same issue.

    Thank you for taking time to help me though.

    – raaaahman Feb 24 '22 at 14:47
  • Everything looks correct then. Must be something else wrong like systemd might be messed up. I very highly doubt that it is MongoDB. Everything required is in the file and yet systemd cannot load it. Try reinstalling systemd sudo apt install --reinstall systemd. Else, I think you might be looking at a messed up 18.04 installation and you might need to reinstall the OS itself. – Terrance Feb 24 '22 at 14:50
  • Thank you for your advice. I can run it from the CLI though, and I've even switched to a docker container to not mess my OS further. I'm still interested in finding what's wrong though... – raaaahman Feb 25 '22 at 17:16

0 Answers0