3

I need to do something like this to run MongoDB

$numactl --interleave=all /usr/bin/mongod --config /etc/mongod.conf &

What should I change to be able to run the mongo daemon with the options above?

3

It depends from how you are managing your services.

With a daemontools-family service manager, just that.

Your current run program will in essence boil down to

#!/bin/nosh
chdir /
setuidgid mongodb
mongod

This is in fact the very basic MongoDB run program that comes in the regular services bundle of my nosh suite, which doesn't use a shell as a script interpreter. shell-interpreted run scripts for daemontools-managed services like the one used by contegix or Yoshiaki Kawazu's one may look more complex but all end up having an exec setuidgid mongodb mongod command somewhere, even if it is hidden behind shell variable expansions.

With daemontools-family service managers, run programs such as these are in essence simple sequences of chain-loading commands. The numactl program is a chain-loading command too, that modifies settings of its own process then chains to a program named on its command line. It fits right in with daemontools tools such as setuidgid.

So you just add numactl into the chain there, which would be

#!/bin/nosh
chdir /
numactl --interleave=all --
setuidgid mongodb
mongod
in a nosh script or
exec \
numactl --interleave=all -- \
setuidgid mongodb \
mongod
in a shell script. (In a shell script, you can make the script try to auto-detect the presence of numactl. Just nick the mechanism from the upstart folk, below.)

Then just restart the service with (nosh only)

system-control condrestart mongod.service
or with

svc -t /service/mongodb
if you are using the old conventional daemontools /service directory.

With systemd, just that.

In your mongod.service unit file there will be a section that has

[Service]
User=mongodb
ExecStart=/usr/local/bin/mongod $OPTIONS run

This is what you will find in the systemd service unit that comes supplied with mongodb, which is slightly but not much more complex.

So you just do as you suggested and modify the ExecStart setting:

ExecStart=/usr/bin/numactl --interleave=all -- /usr/local/bin/mongod $OPTIONS run

Either put this in a replacement /etc/systemd/service/mongod.service unit file to completely override the package-supplied unit file, or retain the package-supplied unit file and use an override for just that setting in (say) /etc/systemd/service/mongod.service.d/numactl.conf.

Then just reload the service unit from file(s) with

systemctl daemon-reload
and restart the service with

systemctl condrestart mongod.service

With upstart, nothing at all.

The answers at https://askubuntu.com/questions/293468/ over on AskUbuntu are approaching 2 years old, now. In the meantime, numactl capability has been placed into the package-supplied upstart job file.

So your system, presuming that it is up to date, should already be doing this and you shouldn't even need a

initctl restart mongodb

Further reading

  • Not sure why this was down-voted. Can anyone give me more details on why it was done? – Andrew Young Aug 29 '16 at 20:14

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.