systemd – zfs is mounted after mongod starts: how do I set the boot order?


Fairly simple problem, I think, but I can’t seem to get my head around a fix.

I’m on Ubuntu 18.04.3 and mounting zfs volumes with mongo-data at boot correctly with the config below in /etc/systemd/system/multi-user.target.wants.

(Unit)
Description=ZFS startup target

(Install)
WantedBy=multi-user.target

Problem is that this happens after the mongod service is started, making mongod fail.

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

(Service)
User=root
Group=root
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
Restart=always
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

(Install)
WantedBy=multi-user.target

I read up about the WantedBy, Requires and After directives, but I’m not confident I understand them well enough to play around with them.