Recommended graceful start and shutdown routine for systemd

Hello,

I ese a lot of variations of MySQLd / Percona XtraDB systemd service files on the internet and failed to deterine what the recommended one is, in order to ensure clean restarts of individual nodes in a three node cluster.

I am using the tar/binary release of the Percona XtraDB Cluster distribution. My current service file looks like this:

[Unit]
Description=Percona XtraDB Cluster Server
After=syslog.target network.target

[Service]
User=mysql
Group=mysql
Type=simple
PIDFile=/run/mysql/mysqld.pid
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf -h /var/lib/mysql --socket=/run/mysql/mysql.sock --pid-file=/run/mysql/mysqld.pid
RuntimeDirectory=mysql
TimeoutSec=300

[Install]
WantedBy=multi-user.target

My main concern is not having a ExecStop= definition. I found the following ExecStop variations on the internet:

ExecStop=/usr/bin/kill $MAINPID
ExecStop=/opt/mysql/bin/mysqladmin shutdown
ExecStop=mysqld-systemd stop

But also the ExecStart= definition seems to leave room for alternation:

ExecStart=/opt/mysql/bin/mysqld
ExecStart=mysqld-systemd start
ExecStart=/opt/mysql/bin/mysqladmin

Another concern is my low timeout and a missing Restart= declaration. I had issues where a node crash would timeout during SST, and then un-cleanly try to restart over and over again.

I found an example service file by Percona debian-percona-xtradb-cluster-5.6/mysqld.service at master · percona/debian-percona-xtradb-cluster-5.6 · GitHub, but it does not seem to indicate a recommendation, and looks more like a boilerplate.

There also seem to be some variations of pepole using the rc-init scripts as commands inside the systemd service, which does not look right.

Does someone have a recommended MySQLd systemd service file, or, alternatively does someone know what the recommended way to gracefully shutdown and start a node (in an already bootstrapped cluster, not new nodes) on a systemd system is?

Thanks a lot!

1 Like

Hi @gecko
What version of PXC are you using?
For 5.6 and 5.7 we haven’t implemented systemd support.
For PXC-8.0 we have full systemd support but please note it was done only for packages not for binary tarballs. You can take unit file here: percona-xtradb-cluster/mysql.service at 8.0 · percona/percona-xtradb-cluster · GitHub

1 Like

So we should use init.d for PXC 5.6 and 5.7? This is on RHEL/Centos 7
5.7 installs systemd scripts. problem is I need systemd scripts that support multiple instances. The mysql@ provided seems to be just for cluster initialization.

1 Like