Description:
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:
/etc/logrotate.d/mysqlrouter:
/var/log/mysqlrouter/mysqlrouter.log {
create 600 mysqlrouter mysqlrouter
notifempty
daily
rotate 5
missingok
compress
postrotate
# only if mysqlrouter is really running
if [ -f "/run/mysqlrouter/mysqlrouter.pid" ]
then
kill -HUP `cat /run/mysqlrouter/mysqlrouter.pid`
fi
endscript
}
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 $?
1
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.