Trouble launching mongoDB on a Rasberry Pi with systemd

I am having a problem with starting mongoDB on a Rasberry Pi with systemd, using Raspberry Pi OS 64 bits.

This is my environment:

root@raspberrypi:~ # uname -a
Linux raspberrypi 5.10.17-v8+ #1403 SMP PREEMPT Mon Feb 22 11:37:54 GMT 2021 aarch64 GNU/Linux
root@raspberrypi:~ # 
root@raspberrypi:~ # mongo --version
MongoDB shell version v4.4.4
Build Info: {
    "version": "4.4.4",
    "gitVersion": "8db30a63db1a9d84bdcad0c83369623f708e0397",
    "openSSLVersion": "OpenSSL 1.1.1d  10 Sep 2019",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu1804",
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}
root@raspberrypi:~ # 

And this is the configuration file for the mongod server:

root@raspberrypi:~# cat /home/mongodb/mongo-One.cfg
storage:
  dbPath: /mnt/mongoDB-One/DB_Data
  journal:
    enabled: true
net:
  #bindIp: 192.168.10.114
  port: 22330
systemLog:
  destination: file
  path: /mnt/mongoDB-One/DB_Data/mongod.log
  logAppend: true
replication:
  replSetName: mngoRepSet
root@raspberrypi:~# 

This is the systemd service file:

root@raspberrypi:~# cat /lib/systemd/system/mongod-One.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target
Requires=network-online.target

[Service]
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/mongod --config /home/mongodb/mongo-One.cfg
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
Type=idle


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

[Install]
WantedBy=multi-user.target
root@raspberrypi:~# 

In this configuration the server starts as expected (note that the bindIp line in the server configuration is commented out). But troubles come when I remove the comment on the bindIp line.

I then get this error in the logs:

{"t":{"$date":"2021-03-20T12:51:15.862+09:00"},"s":"E", "c":"STORAGE", "id":20568, "ctx":"initandlisten","msg":"Error setting up listener","attr":{"error":{"code":9001,"codeName":"SocketException","errmsg":"Cannot assign requested address"}}}

It seems to show a network issue, but I have done everything I can think of in the systemd service file to make sure the network would be ready when starting the service. Can someone see something I am missing?

I can also confirm that after failing at boot time, the service can be manually started using:

root@raspberrypi:~ # systemctl start mongod-One

The IP isn’t there yet to bind to.

A systemd/init issue. There seems to be quite a few hits on google regarding this, so there is bound to be one that solves this.

Are you addressing more than 1 ip/interface on this host? If not I would just bind_ip_all.

No I am not addressing more than one ip/interface on this host.

I used bind_ip_all as you suggest and it works.

Since I don’t know yet what it implies to use this instead of what I was doing before, I cannot tell if this is a good solution on the long term. But at least on the short term, it solves my problem. The server starts at boot time and then I can initiate a replica set and use mongoDB normally.

The thing to be aware of is that any interface added to the system, or any ip added to an existing interface, will be listening on the mongod port too.

If adequate system and/or database protections are in place this really isn’t an issue.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.