Bug #79229 mysql-5.7.9: included systemd service fails to start
Submitted: 11 Nov 2015 14:04 Modified: 11 Nov 2015 19:44
Reporter: Timo Gurr Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Packaging Severity:S3 (Non-critical)
Version:5.7.9 OS:Linux
Assigned to: CPU Architecture:Any

[11 Nov 2015 14:04] Timo Gurr
Description:
Running systemctl start mysqld I get:

Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.629259Z 0 [Warning] CA certificate ca.pem is self signed.
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.629292Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.629793Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.629821Z 0 [Note] IPv6 is available.
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.629828Z 0 [Note]   - '::' resolves to '::';
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.629834Z 0 [Note] Server socket created on IP: '::'.
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.636377Z 0 [Note] Event Scheduler: Loaded 0 events
Nov 11 14:30:36 lxhost mysqld[2458]: 2015-11-11T13:30:36.636676Z 0 [Note] /usr/x86_64-pc-linux-gnu/bin/mysqld: ready for connections.
Nov 11 14:30:36 lxhost mysqld[2458]: Version: '5.7.9'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Exherbo
Nov 11 14:30:36 lxhost systemd[1]: mysqld.service: PID file /run/mysqld/mysqld.pid not readable (yet?) after start: No such file or directory

Having a look in the service file /usr/x86_64-pc-linux-gnu/lib/systemd/system/mysqld.service there's a line:

PIDFile=/run/mysqld/mysqld.pid

which probably is for systemd itself and not used by mysqld. After adding --pid-file=/run/mysqld/mysqld.pid to the ExecStart in the mysqld.service file:

# Start main service
ExecStart=/usr/x86_64-pc-linux-gnu/bin/mysqld --daemonize $MYSQLD_OPTS --pid-file=/run/mysqld/mysqld.pid

systemctl start mysqld is working fine:

Nov 11 14:31:48 lxhost mysqld[2536]: 2015-11-11T13:31:48.007535Z 0 [Note] /usr/x86_64-pc-linux-gnu/bin/mysqld: ready for connections.
Nov 11 14:31:48 lxhost mysqld[2536]: Version: '5.7.9'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Exherbo
Nov 11 14:31:48 lxhost systemd[1]: Started MySQL Server.

How to repeat:
1. compile from sources
2. install
3. try to start mysql via the provided systemd service

Suggested fix:
Could you introduce a compile time option like e.g. -DMYSQL_PIDFILE:STRING=/run/mysqld/mysqld.pid to set a default for the pidfile just like it is already in place for other things like e.g. datadir (-DMYSQL_DATADIR:PATH=/var/lib/mysql)?

And/Or add --pid-file=@SYSTEMD_PID_DIR@/mysqld.pid to ExecStart in the mysqld.service.in file in the sources?
[11 Nov 2015 15:15] Timo Gurr
possible fix/workaround

Attachment: mysql-5.7.9-bug79229.patch (text/x-patch), 770 bytes.

[11 Nov 2015 19:37] Terje Røsten
Hi!

Thanks for your report.

We have discovered the same issue and applied the same fix, it will be
part of the next release.
[11 Nov 2015 19:44] Terje Røsten
Noted in 5.7.10, 5.8.0 changelogs.

The systemd unit file did not specify any --pidfile option for
mysqld, with the result that server startup could fail. The unit file
now includes a default --pidfile option in the ExecStart value. This
default can be overridden in the override.conf file by changing both
PIDFile and ExecStart to specify the PID file path name.

Documentation updated:

 https://dev.mysql.com/doc/refman/5.7/en/server-management-using-systemd.html