0

I'm using chef to install the default mysql-server package on Ubuntu 16.04. I'm doing it on a server that has no existing MySQL installation, but does have /var/lib/mysql set up already, as a mounted drive.

Thus, /var/lib/mysql has a lost+found directory in it.

If I install MySQL using very basic chef:

package 'mysql-server'

When /var/lib/mysql/lost+found exists, I get an error:

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.
dpkg: error processing package mysql-server-5.7 (--configure):
 subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
 mysql-server depends on mysql-server-5.7; however:
  Package mysql-server-5.7 is not configured yet.

dpkg: error processing package mysql-server (--configure):
 dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup error from a previous failure.
                                                                                                          Errors were encountered while processing:
 mysql-server-5.7
 mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

(This error also happens if I simply apt-get install mysql-server.)

However, if I remove the lost+found directory before doing the installation, everything works fine.

I imagine that mysql's installation process does something like assuming the lost+found directory is actually a database, and tries to upgrade it during the install, or something equally odd.

I've worked around this for now (and also proved to myself that the lost+found directory is definitely the cause) by deleting lost+found before the install, and recreating it afterwards:

directory '/var/lib/mysql/lost+found' do
  action :delete
end

package 'mysql-server'
package 'mysql-client'

execute 'mklost+found' do
  command 'mklost+found'
  cwd '/var/lib/mysql'
end 

This works fine, but I believe experts would probably rate it at around 8.2 on the standard Kludge-o-Rama scale.

Is there a better way to do the basic, package-default install of MySQL Server on Ubuntu using chef when /var/lib/mysql is already set up as a mounted drive?

Matt Gibson
  • 296
  • 2
  • 7

1 Answers1

1

Yes this is caused by (a) the existence /var/lib/mysql/lost+found, (b) this part of /var/lib/dpkg/info/mysql-server-5.7.postinst:

216     # If database doesn't exist we create it.
217     if [ ! "$(ls -A "${mysql_statedir}")" ] && [ -d "${mysql_filesdir}" ]; then
218       existingdatabase=0

where mysql_statedir is /var/lib/mysql, and (c) Ubuntu's (Debian's) brain-dead policy of starting services when the package is installed (but possibly not configured).

Thus the failure to start mysql:

Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
invoke-rc.d: initscript mysql, action "start" failed.

causes dpkg to error out.

So you fixed it by making (a) false. Let's look how you might make (b) or (c) false.

For (b), you can file a bug report saying line 217 of /var/lib/dpkg/info/mysql-server-5.7.postinst is non-optimal when /var/lib/mysql is a separate filesystem so it contains lost+found. Maybe it will get fixed.

For (c) you could convince the Ubuntu powers-that-be that starting services on package install is a bad idea. Their retort will be: use policy-rc.d. How would that go?

Create a /usr/sbin/policy-rc.d file that does nothing but return 0 when the init script is mysql-server. See the invokerc.d spec. However there are other parts of the script that rely on mysql actually starting. The correct code to return isn't 0; maybe 101?. However, any non-zero return code will result in the same outcome you are experienceing now. So policy-rc.d is not helpful to you. /shrug

I hope I have convinced you that your solution is the best.

Mark Wagner
  • 17,764
  • 2
  • 30
  • 47