1

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.

  • Where did you get this systemd unit? – Michael Hampton Oct 18 at 5:41
  • Both came standard with the zfs and mongod packages – Guy De Pauw Oct 19 at 5:59
1

I had a very similar issue with another service, which wanted to start before its files, which are on a ZFS dataset, became available.

I solved it with a very simple systemd override. You can do the same:

# cat /etc/systemd/system/mongod.service.d/zfs.conf 
[Unit]
Requires=zfs.target
After=zfs.target

After a sudo systemctl daemon-reload (or of course a reboot) this will take effect. Enjoy!

Remember not to edit the systemd unit shipped with the package, as your changes would not be preserved when you update the package. Use override files (e.g. as above) instead.

| improve this answer | |
  • Thanks, that looks like what I need. The systemd unit for mongo is in /etc/systemd/system/multi-user.target.wants though, which is a symlink to the one shipped with the package. So not sure where to add the requires and after directives – Guy De Pauw Oct 19 at 9:34
  • You put it exactly where I showed in the answer. – Michael Hampton Oct 19 at 18:29
  • Thanks, wasn't sure about adding the extra directory! – Guy De Pauw Oct 20 at 2:56
0

You need to use RequiresMountsFor; see

man systemd.directives

Option will be like RequiresMountsFor=[mountpoint] for example

RequiresMountsFor=/zfsmount
| improve this answer | |
  • Thanks, will give this a try – Guy De Pauw Oct 19 at 6:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.