# Recommended graceful start and shutdown routine for systemd

**URL:** <https://forums.percona.com/t/recommended-graceful-start-and-shutdown-routine-for-systemd/12640>\
**Category:** Percona XtraDB Cluster 8.x\
**Created:** [October 19, 2021, 5:53pm UTC](https://forums.percona.com/t/recommended-graceful-start-and-shutdown-routine-for-systemd/12640 "2021-10-19T17:53:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gecko](https://avatars.discourse-cdn.com/v4/letter/g/c4cdca/32.png) [@gecko](https://forums.percona.com/u/gecko)\
**Post date:** [October 19, 2021, 5:53pm UTC](https://forums.percona.com/t/recommended-graceful-start-and-shutdown-routine-for-systemd/12640/1 "2021-10-19T17:53:31Z")

</div>

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:

```auto
[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:

```auto
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:

```auto
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](https://github.com/percona/debian-percona-xtradb-cluster-5.6/blob/master/packaging/rpm-oel/mysqld.service), 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!

---

<div class="post-metadata">

**Author:** ![Evgeniy\_Patlan](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/evgeniy_patlan/32/41_2.png) [@Evgeniy\_Patlan](https://forums.percona.com/u/Evgeniy_Patlan)\
**Post date:** [October 22, 2021, 10:24am UTC](https://forums.percona.com/t/recommended-graceful-start-and-shutdown-routine-for-systemd/12640/2 "2021-10-22T10:24:27Z")

</div>

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](https://github.com/percona/percona-xtradb-cluster/blob/8.0/build-ps/rpm/mysql.service)

---

<div class="post-metadata">

**Author:** ![gregl](https://avatars.discourse-cdn.com/v4/letter/g/c57346/32.png) [@gregl](https://forums.percona.com/u/gregl)\
**Post date:** [March 11, 2022, 1:27pm UTC](https://forums.percona.com/t/recommended-graceful-start-and-shutdown-routine-for-systemd/12640/3 "2022-03-11T13:27:49Z")

</div>

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.
