Creating directory at startup for proxy unix sockets

I would like to forward a mysql unix socket from the container to the host. It doesn’t work if the directory doesn’t already exist:

$ incus config device add librenms mysql proxy listen=unix:/run/mysqld/mysqld.sock connect=unix:/run/mysqld/mysqld.sock bind=instance
Error: Failed to start device "mysql": Error occurred when starting proxy device: Error: Failed to listen on /run/mysqld/mysqld.sock: listen unix /run/mysqld/mysqld.sock: bind: no such file or directory

If I manually create the directory before adding the proxy device, it’s fine. But I want this to work at container startup.

I put this in /etc/tmpfiles.d/mysql-sock.conf:

#Type Path            Mode UID      GID        Age Argument
d     /run/mysqld     0755 root     root       -   -

Then added the device, restarted the container, and it seems to work.

My question is: is this safe, or is there a race condition here? i.e. is it guaranteed that the systemd-tmpfiles service will have completed before incus tries to create the /run/mysqld/mysqld.sock socket?

Thanks, Brian.

Shouldn’t you use bind=host instead of bind=instance?

No. The application is in the container, and the (shared) database is on the host. I need to listen on the container side, not the host side.