0

I have issues starting a MariaDB service on a Centos 7 server, because the directory /var/run/mysqld/ is not created by default, as well as the /var/log/mysqld.log file.

Creating this directory and file with the correct permissions allow MariaDB to start properly, but on reboot, the directory is deleted and has to be recreated.

/etc/systemd/system/multi-user.target.wants/mariadb.service will start the script when running service mariadb start; according to that file, on start it execute /usr/libexec/mariadb-prepare-db-dir, where I have added the following:

touch /var/log/mysqld.log                
chown mysql:mysql /var/log/mysqld.log
mkdir /var/run/mysqld                    
chown mysql:mysql /var/run/mysqld        

The log file is properly created, but not the directory. Why ? How can I create it properly, when the service is started ? I thought about a permission problem, but I do not know where to find more information.

The mariadb is installed directly via yum, and it's version 5.5. Why it's not functional out of the box is beyond me.

user96649
  • 121
  • 2
  • 3
  • 1
    systemd is not supposed to create a pid file, that's the job of the application. See https://serverfault.com/questions/817552/systemd-drop-in-fails-to-create-pid-file – Gerald Schneider Aug 21 '18 at 09:18
  • Check you mariadb config file for the `pid-file` parameter. – Gerald Schneider Aug 21 '18 at 09:23
  • `pid-file=/var/run/mysqld/mysqld.pid` – user96649 Aug 21 '18 at 09:32
  • How can I make the application create this directory properly ? The pid-file can't be created because the directory doesn't exist. In the end it's all that is needed, a proper directory. Where am I supposed to create this directory, on each start ? – user96649 Aug 21 '18 at 09:33
  • The upstream mariadb got systemd mature in 10.1. Systemd services don't need pid-files and the error log should be left as stderr and go to the journal. I'd be raising a distro bug about this. Or alternately use a later mariadb version from [the mariadb repos](https://downloads.mariadb.org/mariadb/repositories/) – danblack Aug 21 '18 at 10:32
  • Possible duplicate of [Create a directory under /var/run at boot](https://serverfault.com/questions/779634/create-a-directory-under-var-run-at-boot) – Gerald Schneider Aug 21 '18 at 11:51
  • All of those steps wouldn't be necessary if the application was installed correctly in the first place. Which means either there is a bug in the software or you didn't install it correctly. I don't have any Centos systems to test out the installation procedure myself, but maybe it would help if you explained in your questions what steps you took to install it and get into such a bad shape. – kasperd Aug 22 '18 at 22:42

2 Answers2

1

Actually, Mairadb locate pid file in /var/run/mariadb.
Then,you needn't any other operation just set pid-file=/var/run/mariadb/mysqld.pid

kittygirl
  • 855
  • 4
  • 10
  • 29
0

I had a similar problem recently. My workaround was to add it to crontab as root:

$ crontab -e

add:

@reboot mkdir /var/run/mysqld && chown mysql:mysql /var/run/mysqld

There might be better locations to create the directory at startup, but for me this works.

Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • Adding an entry to `/usr/lib/sysusers.d/mariadb.conf` would be a much more standard way of doing this. – danblack Aug 21 '18 at 10:24
  • @danblack how would you do that? as far as I can tell (I never heard of this systemd feature) you only define system users along with their home directory there. – Gerald Schneider Aug 21 '18 at 10:29
  • Opps, not sysusers, tmpfile. Like ` /etc/tmpfiles.d/mariadb.conf` is the right place like the [Fedora packaging of it](https://src.fedoraproject.org/cgit/rpms/mariadb.git/tree/mysql.tmpfiles.d.in). tmpfiles AFAIK was picked up by a few different init system implementations leading to bugs like [mariadb issue 528](https://github.com/MariaDB/server/pull/528) – danblack Aug 21 '18 at 10:35
  • The canonical method for systemd to create directories is either a [`RuntimeDirectory=...` directive in the unit file, or a `tmpfiles.d` drop-in script](https://serverfault.com/a/779648/37681) – HBruijn Aug 21 '18 at 11:02
  • You always learn something new. I guess we can close the question as a duplicate then. – Gerald Schneider Aug 21 '18 at 11:51
  • Yeah, tmpfiles.d is the way to do this. Though mariadb as shipped with CentOS already should have this. – Michael Hampton Aug 21 '18 at 12:42