Temp Files in RHEL7
I had an RHEL7 system that would not start mariadb server on boot. I could reinstall the server rpm and then it would work fine, but it would not start after a reboot. So I finally had some time to figure out what’s going on.
First of all, here’s the part of the journalctl -xe command that’s relevant:
[~]# journalctl -xe ... -- Unit mariadb.service has begun starting up. Oct 25 09:30:33 host systemd[14587]: Failed at step GROUP spawning /usr/libexec/mariadb-prepare-db-dir: No such process -- Subject: Process /usr/libexec/mariadb-prepare-db-dir could not be executed -- Defined-By: systemd -- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
The problem was always this line:
Failed at step GROUP spawning /usr/libexec/mariadb-prepare-db-dir: No such process
That file is a script that is always there. So I tried to run just that script and got this:
[~]# /usr/libexec/mariadb-prepare-db-dir chown: invalid group: ‘mysql:mysql’
My first problem was that my group mysql somehow disappeared. So I readded that and tried to start mariadb again. Looking at just the problem area:
-- Unit mariadb.service has begun starting up. Oct 25 09:32:32 host mysqld_safe[14744]: 161025 09:32:32 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. Oct 25 09:32:32 host mysqld_safe[14744]: 161025 09:32:32 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql Oct 25 09:32:34 host mysqld_safe[14744]: 161025 09:32:34 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended Oct 25 09:32:34 host systemd[1]: mariadb.service: control process exited, code=exited status=1 Oct 25 09:32:34 host systemd[1]: Failed to start MariaDB database server. -- Subject: Unit mariadb.service has failed
And now I immediately see the problem. It’s trying to get the pid file from /var/run/mariadb. However, as of RHEL7, /var/run is a TEMPFILE that gets recreated with each boot. So if you make a directory in /var/run (which installing the mariadb-server rpm probably does), that directory will be deleted on a reboot. In order to make that directory each time the system is booted, I need to create a file.
In /etc/tmpfiles.d, create mariadb.conf with the following contents:
[/etc/tmpfiles.d] $ cat mariadb.conf # mariadb needs a directory in /var/run to store its pid file and args file d /var/run/mariadb 0755 mysql mysql
Now reboot. And mariadb server starts up as it should.
On a related note, I had the same issue on a different server with openldap. There, I needed to add to /etc/tmpfiles.d, an openldap.conf file.
[/etc/tmpfiles.d]# more openldap.conf # slapd needs a directory in /var/run to store its pid file and args file d /var/run/openldap 0755 ldap ldap