Bug #90042 systemd support for ndbmtd
Submitted: 13 Mar 2018 8:25 Modified: 14 Mar 2018 4:38
Reporter: Daniël van Eeden (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Packaging Severity:S4 (Feature request)
Version:7.6.4 OS:Any
Assigned to: CPU Architecture:Any
Tags: ndbd, ndbmtd, systemd

[13 Mar 2018 8:25] Daniël van Eeden
Description:
ndbmtd is packaged in mysql-cluster-community-data-node and doesn't have a systemd unit file or rc script.

$ rpm -ql mysql-cluster-community-data-node-7.6.4-1.el7.x86_64
/usr/sbin/ndbd
/usr/sbin/ndbmtd
/usr/share/doc/mysql-cluster-community-data-node-7.6.4
/usr/share/doc/mysql-cluster-community-data-node-7.6.4/COPYING
/usr/share/doc/mysql-cluster-community-data-node-7.6.4/README
/usr/share/man/man8/ndbd.8.gz
/usr/share/man/man8/ndbmtd.8.gz

When I use salt to start ndbmtd on the data nodes it results in this:
 ps -o pid,comm,cgroup -C ndbmtd
  PID COMMAND         CGROUP
28908 ndbmtd          1:name=systemd:/system.slice/salt-minion.service
28909 ndbmtd          1:name=systemd:/system.slice/salt-minion.service

A "systemctl status salt-minion" also shows ndbmtd as part of the cgroup.

This is not salt specific, but can happen with various other services.

systemd uses cgroups to group all processes of a specific service together and uses that
to ensure all processes are killed when restarting a service.

A salt-minion restart results in:
2018-03-12 22:40:44 [ndbd] INFO     -- Received signal 15. Performing stop.
2018-03-12 22:40:44 [ndbd] INFO     -- Received signal 15. Performing stop.
2018-03-12 22:40:44 [ndbd] INFO     -- The data node run-time environment has been stopped
2018-03-12 22:40:44 [ndbd] INFO     -- Shutdown initiated
2018-03-12 22:40:44 [ndbd] INFO     -- Shutdown completed - exiting
2018-03-12 22:41:01 [ndbd] INFO     -- Angel shutting down
2018-03-12 22:41:01 [ndbd] INFO     -- Node 4: Node shutdown completed. Initiated by signal 15.

How to repeat:
Use salt or other similar services to start ndbmtd on a systemd capable system (OEL7, CO7, RHEL7). And check in which cgroup it is placed. Then restart that service and see if it impacts ndbmtd.

Suggested fix:
Ship a unit file for systemd. This ensures ndbmtd is placed in its own cgroup.

Currently ndbmtd has two processes, an angel process and a worker process. It *might* make sense to not have the angel process but leave that function to systemd.
[13 Mar 2018 9:16] Daniël van Eeden
== Example ndbmtd.unit
[Unit]
Description=MySQL Cluster Data Node
After=network.target
Documentation=man:ndbmtd(8)
Documentation=https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster.html

[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/ndbmtd
ExecStart=/usr/sbin/ndbmtd $NDBMTD_OPTIONS
Restart=no

[Install]
WantedBy=multi-user.target

== Example sysconfig
NDBMTD_OPTIONS="--ndb-connectstring=mymgmtnode.example.com"
[13 Mar 2018 9:17] Daniël van Eeden
Using --foreground might make sense to allow more integration with journald (e.g. journalctl -u ndbmtd)
[14 Mar 2018 4:38] MySQL Verification Team
Hello Daniël,

Thank you for the report and feature request!

Thanks,
Umesh