Snap Cannot Access /var/run

Hello,

I am attempting to create a snap that is requiring writing a socket file to /var/run/mysql.

022-11-15T13:09:34-05:00 systemd[1]: Started Service for snap application mysql-server.mysqld.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.378582Z 0 [Warning] [MY-010101] [Server] Insecure configuration for --secure-file-priv: Location is accessible to all OS users. Consider choosing a different directory.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.378691Z 0 [System] [MY-010116] [Server] /snap/mysql-server/x1/usr/sbin/mysqld (mysqld 8.0.31-0ubuntu0.22.04.1) starting as process 855079
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.391388Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.587776Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.793445Z 0 [ERROR] [MY-011300] [Server] Plugin mysqlx reported: 'Setup of socket: '/var/run/mysqld/mysqlx.sock' failed, can't create lock file /var/run/mysqld/mysqlx.sock.lock'
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.923237Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.923304Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.930884Z 0 [ERROR] [MY-010273] [Server] Could not create unix socket lock file /var/run/mysqld/mysqld.sock.lock.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.930916Z 0 [ERROR] [MY-010268] [Server] Unable to setup unix socket lock file.
2022-11-15T13:09:35-05:00 mysql-server.mysqld[855079]: 2022-11-15T18:09:35.930931Z 0 [ERROR] [MY-010119] [Server] Aborting

I have tried setting the config option in the mysqld config:

sock = /etc/mysql/mysqld.sock

I found this which seemed relevant, but the solution does not appear to work in this case.

here is the repo for reference

there seems to be an (old) mysql server snap in the store already at:

did you consider looking at that one and how they solved the problem (or asking the maintainer about it)

1 Like

@jardon I was the person struggling with this in the other thread. I haven’t worked on this recently, but I came away with the conclusion that trying to get write access to anything directly under /var/run/ is going to be an uphill struggle. Much better to just use /run/snap.<snap name>/ if you can, which your snap has access to by default.

I don’t really know what your needs are (as @ogra says, there’s already a MySQL server out there), but if your first aim to at least get MySQL running, then getting it to put the socket lock file in a location that’s writable to the snap will be important. /var/snap/<snap-name>/current/ (aka $SNAP_DATA) is another option, but /etc/mysql/mysqld.sock will also not be writable (since anything under /etc is not).

Hey @svet! thanks for jumping in. Whats weird is that changing the socket configuration doesn’t appear to do anything. I can set it to any directory, but mysqld will still look for it under /var/run/msyqld

@ogra I’ve looked through the repo for that and they dont build off of the deb packaging so things are very different. I could try to shoot him an email if he doesnt respond to a ping. @lars.tangvald i think is him.

As a follow up to this, for whatever reason, when running mysqld as root, the configuration defaults are dropped regardless of if you point mysqld directly to the config file using the CLI arg.

Running mysqld with the mysql user creates a different issue where I don’t seem to be able to write to $SNAP_COMMON using that account. Is there any work around for this that would allow the mysql user to write to $SNAP_COMMON?