This is the most unusual thing. I'm trying to start up mysqld with a different my.cnf (so I can have two MySQL daemons running without conflict). The file is /etc/mysql/my2.cnf but mysql won't open it.
When I run this command:
sudo -u mysql strace /usr/sbin/mysqld --defaults-file=/etc/mysql/my2.cnf
I see this in the output:
stat("/etc/mysql/my2.cnf", {st_mode=S_IFREG|0644, st_size=3574, ...}) = 0
open("/etc/mysql/my2.cnf", O_RDONLY) = -1 EACCES (Permission denied)
However, when I change the command to:
sudo -u mysql strace cat /etc/mysql/my2.cnf > /dev/null
I see this in the output:
fstat(1, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
open("/etc/mysql/my2.cnf", O_RDONLY) = 3
Same user - same kernel call - different results!
I checked file permissions - and extended permissions:
# ls -l $PWD/my2.cnf
-rw-r--r-- 1 root root 3574 2011-07-08 10:04 /etc/mysql/my2.cnf
# lsattr $PWD/my2.cnf
-----------------e- /etc/mysql/my2.cnf
Am I getting bit by some part of AppArmour or SELinux? I didn't see anything like that in the logs (including daemon.log, syslog, or messages).
How do I fix this problem?
No one's answered, so I'll tell what I found out.
The problem in short is the following: when the file
/etc/mysql/my2.cnf
is accessed bycat
, we see this:However, when
mysqld
makes the same call, it gets a different answer:Thus, the answer lay in the kernel. Something in the kernel was differentiating between a call to open(2) by
cat
and bymysqld
. The only thing that came to mind was AppArmor.Searching the packages on the system turned up several related to AppArmor. Listing files in the packages turned up the command
apparmor_status
; running this showed thatmysqld
is indeed covered under AppArmor:Reading the man pages for apparmor(7) showed that profiles were stored in
/etc/apparmor.d
; looking at this directory turns up the fileusr.sbin.mysqld
. This turns out to be the file to modify.Modifying the file is straightforward, copying the entries for the original standard directories and files and making them into the new directories and files. Once this is done, activate the new configuration with a
service apparmor restart
.I never did see any messages in syslog about "audit" (from AppArmor). The reason for this was that the messages went to
/var/log/audit/audit.log
instead ofsyslog
ormessages
. This file contained entries like these:This proves my reasoning and investigation: AppArmor was rejecting the open(2) requests.
Now that I knew what to look for I found blog entries relating to this - one article from all the way back in 2008.