# Start pt-heartbeat from systemd? SOLVED

**URL:** <https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112>\
**Category:** MySQL & MariaDB\
**Created:** [June 29, 2021, 2:46pm UTC](https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112 "2021-06-29T14:46:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![j4nd3r53n](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@j4nd3r53n](https://forums.percona.com/u/j4nd3r53n)\
**Post date:** [June 29, 2021, 2:46pm UTC](https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112/1 "2021-06-29T14:46:43Z")

</div>

I want to start pt-heartbeat as a systemd service, but it doesn’t work. Here is what I have done so far:

I created a database, _heartbeat_, and a user, _heart_ with password _heartbeat_ (or something…).

I can start pt-heartbeat with _pt-heartbeat -D heartbeat --daemonize --update --ask-pass --utc_, and I can see the command in the process list. But of course, I can only do this manually, and I want to start it from a systemd service. I’ve tried different variants of:

`pt-heartbeat -D heartbeat --daemonize --update --utc -u heart -pheartbeat`

This failed at first with:

> DBD::mysql::db selectrow\_hashref failed: Access denied; you need (at least one of) the SUPER, REPLICATION CLIENT privilege(s) for this operation [for Statement “SHOW MASTER STATUS”] at /usr/bin/pt-heartbeat line 6189.

This means that a connection was successful, but a privilege were missing, so I granted that. Now I get no error, but it also doesn’t turn up in the process list, and the table is not updated.

What am I doing wrong here?

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [June 29, 2021, 3:12pm UTC](https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112/2 "2021-06-29T15:12:46Z")

</div>

Can you share your entire unit file?

---

<div class="post-metadata">

**Author:** ![j4nd3r53n](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@j4nd3r53n](https://forums.percona.com/u/j4nd3r53n)\
**Post date:** [June 30, 2021, 7:09am UTC](https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112/3 "2021-06-30T07:09:08Z")

</div>

I can:

```auto
rgs-mi-db-1 root = cat /etc/systemd/system/heartbeat.service
[Unit]
Description=Percona Heartbeat Service
After=mysql.service
Documentation=https://www.percona.com/doc/percona-toolkit/2.1/pt-heartbeat.html

[Service]
Type=simple
ExecStart=/usr/bin/pt-heartbeat -D heartbeat --update -u heart -pheartbeat --utc --daemonize
ExecStop=/usr/bin/pt-heartbeat --stop
StandardOutput=null
Restart=on-failure

[Install]
Alias=heartbeat.service

```

But I don’t think this is relevant - when I run the command manually, it simply doesn’t fork off a child process, although it clearly connects with the database.

_ **Edit** _

I’ve run a few more experiments - all failed: I’ve tried various combinations of not specifying the user, using --ask-pass etc, and it seems that no versions work now, not even the one I had working at first:

```auto
 /usr/bin/pt-heartbeat -D heartbeat --update --ask-pass --utc --daemonize

```

Unfortunately I don’t do perl, so although I canread the code, there’s a lot of cnnstruction in there that I don’t quite get.

---

<div class="post-metadata">

**Author:** ![j4nd3r53n](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@j4nd3r53n](https://forums.percona.com/u/j4nd3r53n)\
**Post date:** [June 30, 2021, 8:36am UTC](https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112/4 "2021-06-30T08:36:40Z")

</div>

After reading the man page carefully, it turns out that it is in fact the `ExecStop` clause in the service file:

```auto
ExecStop=/usr/bin/pt-heartbeat --stop

```

`--stop` creates a sentinel file, which then hangs around indefinitely and stops the script from daemonizing. I’ll have to look for another way to shut down, I suppose.

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [June 30, 2021, 3:13pm UTC](https://forums.percona.com/t/start-pt-heartbeat-from-systemd-solved/11112/5 "2021-06-30T15:13:43Z")

</div>

I would use `--pid` option to create a pid file and supply that to the unit file. That way systemd can control the script with simple KILL signals.
