Bug #108360 mysqlrouter logrotate not sending HUP
Submitted: 1 Sep 2022 13:00 Modified: 6 Dec 2022 10:33
Reporter: Jay Janssen Email Updates:
Status: Closed Impact on me:
Category:MySQL Router Severity:S3 (Non-critical)
Version:8.0.30 OS:Red Hat (el7-based (Amazon Linux 2))
Assigned to: CPU Architecture:Any

[1 Sep 2022 13:00] Jay Janssen
I am using mysqlrouter with systemd on a RHEL7-based OS (Amazon Linux 2).  I noticed that logrotate is rotating logs, but it is clearly not sending HUPs to the router process:

ls -alh /var/log/mysqlrouter/
total 20K
drwxr-xr-x 2 mysqlrouter mysqlrouter   64 Sep  1 03:41 .
drwxr-xr-x 8 root        root        4.0K Sep  1 03:41 ..
-rw------- 1 mysqlrouter mysqlrouter    0 Sep  1 03:41 mysqlrouter.log
-rw-r--r-- 1 mysqlrouter mysqlrouter  14K Aug 31 20:30 mysqlrouter.log-20220901.gz

I noticed that the package-installed logrotate config is looking for a PID file:

/var/log/mysqlrouter/mysqlrouter.log {
        create 600 mysqlrouter mysqlrouter
        rotate 5
      # only if mysqlrouter is really running
      if [ -f "/run/mysqlrouter/mysqlrouter.pid" ]
        kill -HUP `cat /run/mysqlrouter/mysqlrouter.pid`

But there is no pid file specified in the default router config file generated with --bootstrap

[root@ip-10-160-133-197 ~]# systemctl status mysqlrouter
● mysqlrouter.service - MySQL Router
   Loaded: loaded (/usr/lib/systemd/system/mysqlrouter.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-09-01 12:43:51 UTC; 14min ago
 Main PID: 5900 (mysqlrouter)
   Status: "running"
   CGroup: /system.slice/mysqlrouter.service
           └─5900 /usr/bin/mysqlrouter

Sep 01 12:43:48 ip-10-160-133-197.ec2.internal systemd[1]: Starting MySQL Router...
Sep 01 12:43:51 ip-10-160-133-197.ec2.internal systemd[1]: Started MySQL Router.
[root@ip-10-160-133-197 ~]# ls /run/mysqlrouter/mysqlrouter.pid
ls: cannot access /run/mysqlrouter/mysqlrouter.pid: No such file or directory
[root@ip-10-160-133-197 ~]# grep pid /etc/mysqlrouter/mysqlrouter.conf;  echo $?

How to repeat:
Install mysqlrouter package on Amazon linux and use --bootstrap to generate the configuration.  

Suggested fix:
The log rotate should use systemctl to determine if the router is running.
[5 Sep 2022 8:42] Terje Røsten
Thanks for your report!

Using systemct to HUP signal seems to the correct fix, something like this:

 /usr/bin/systemctl kill -s HUP mysqlrouter.service
[6 Dec 2022 10:33] Edward Gilmore
Posted by developer:
Added the following note to the MySQL Shell 8.0.32 release notes:

MySQL Router's logrotate did not send a HUP signal to the router process. 
As of this release, logrotate uses native systemctl commands when systemd is enabled.