Generate distrobuilder LXD Ubuntu image with mysql-server package fails

Hi all,

I am trying to build an Ubuntu based image with distrobuilder and mysqld/php/apache2 on the image.
I grabbed the current Ubuntu image.yaml from the lxc-ci and stripped down for my needs, and built it with distrobuilder build-lxd mysqld.yaml .

The error message I get when running with distrobuilder is that dpkg cannot shut down the running MySQL process and fails the package installation.

    Setting up mysql-server-8.0 (8.0.22-0ubuntu0.20.04.3) ...
    invoke-rc.d: could not determine current runlevel
    invoke-rc.d: policy-rc.d denied execution of stop.
    update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
    Renaming removed key_buffer and myisam-recover options (if present)
    Error: Unable to shut down server with process id 1723
    dpkg: error processing package mysql-server-8.0 (--configure):
     installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1

A little bit of googling brought me to this workaround for lxc, but as I am building for LXD this doesn’t work.
Is there anyway to enable the same when using distrobuilder to build the images?
Any other workaround necessary for this to happen?

I don’t think the link you’re referring to applies here.
distrobuilder doesn’t operate in a container so isn’t restricted by apparmor.

It seems like this could be a packaging bug. We can clearly see distrobuilder’s policy-rc.d change at work which prevents any service from being started or stopped, yet mysql somehow still thinks it’s running and should be stopped?

Hum, seems that the package is not discovering properly the pid of the mysqld process.
If I check the processlist, the process is running:

tss      2218 34.1 16.2 1070252 164004 pts/0  Sl+  21:29   0:02 mysqld --initialize-insecure --user=mysql --init-file=/var/lib/mysql-files/tmp.pvEzRsUZrw

but dpkg reports:

Setting up mysql-server-8.0 (8.0.22-0ubuntu0.20.04.3) ...
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of stop.
update-alternatives: using /etc/mysql/mysql.cnf to provide /etc/mysql/my.cnf (my.cnf) in auto mode
Renaming removed key_buffer and myisam-recover options (if present)
mysqld will log errors to /var/log/mysql/error.log
mysqld is running as pid 1377
Error: Unable to shut down server with process id 1377

could not find anything running with PID 1377 on the host though.
I don’t know how the image itself s built by distrobuilder, is it within a chroot? Maybe I need to mount /proc “inside” the chroot?

FWIW, not sure if it is relevant, I get a couple of Z processes when its at the MySQL configuring step:

root      751  0.0  0.0  20144   284 pts/0    S+   22:07   0:00  |   \_ /snap/distrobuilder/314/bin/distrobuilder build-lxd ubuntu.yaml .
root      768  0.0  0.8 1165072 15420 pts/0   Sl+  22:07   0:00  |       \_ /snap/distrobuilder/314/bin/distrobuilder build-lxd ubuntu.yaml .
root      776  0.0  0.0      0     0 ?        Z    22:07   0:00  |           \_ [dirmngr] <defunct>
root      777  0.0  0.0      0     0 ?        Zs   22:07   0:00  |           \_ [dirmngr] <defunct>
root      780  0.0  0.0      0     0 ?        Z    22:07   0:00  |           \_ [gpg-agent] <defunct>
root      781  0.0  0.0      0     0 ?        Zs   22:07   0:00  |           \_ [gpg-agent] <defunct>
root      563  1.3  3.1  68012 59020 pts/0    S+   22:10   0:01  |           \_ apt-get -y install apt-transport-https fuse language-pack-en openssh-client openssh-server mysql-server vim cloud-init
root     2467  0.5  0.2   9108  4712 pts/0    S+   22:10   0:00  |           |   \_ /usr/bin/dpkg --status-fd 34 --configure --pending
root     3254  0.1  0.8  21048 16948 pts/0    S+   22:11   0:00  |           |       \_ /usr/bin/perl -w /usr/share/debconf/frontend /var/lib/dpkg/info/mysql-server-8.0.postinst configure
root     3259  0.1  0.2   5912  3868 pts/0    S+   22:11   0:00  |           |           \_ /bin/bash /var/lib/dpkg/info/mysql-server-8.0.postinst configure
root     3606  0.0  0.0   4260   592 pts/0    S+   22:12   0:00  |           |               \_ sleep 1
tss      3384  1.1  0.0      0     0 ?        Z    22:11   0:00  |           \_ [mysqld] <defunct>

It’s a chroot with its own PID namespace. It does have /proc mounted inside it.

In the end, the only option is to either download only the packages, or install mysql-server-core-8.0 and run the configuration steps at a later stage, since the configuration steps of the packages fail. For me, it is fine since one has to secure the MySQL installation anyway post image deployment.