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.

  • 1
    systemd is not supposed to create a pid file, that's the job of the application. See serverfault.com/questions/817552/… – Gerald Schneider Aug 21 '18 at 9:18
  • Check you mariadb config file for the pid-file parameter. – Gerald Schneider Aug 21 '18 at 9:23
  • pid-file=/var/run/mysqld/mysqld.pid – user96649 Aug 21 '18 at 9: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 9: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 – danblack Aug 21 '18 at 10:32
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

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.

  • 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. tmpfiles AFAIK was picked up by a few different init system implementations leading to bugs like mariadb issue 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 – 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.