Skip to content

Instantly share code, notes, and snippets.

@tcooper
Created May 7, 2014 23:55
Show Gist options
  • Save tcooper/c854f8a1db3a2586e628 to your computer and use it in GitHub Desktop.
Save tcooper/c854f8a1db3a2586e628 to your computer and use it in GitHub Desktop.
Patch to 'fix' CentOS 6.5 mysql-server init script to allow use of non-standard user specified in /etc/my.cnf
--- /etc/init.d/mysqld.orig 2014-02-12 11:42:13.000000000 -0800
+++ /etc/init.d/mysqld 2014-05-07 16:48:24.426343648 -0700
@@ -50,6 +50,8 @@
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
+get_mysql_option mysqld user "mysql"
+user="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
@@ -86,7 +88,7 @@
action $"Starting $prog: " /bin/false
return 4
fi
- chown mysql:mysql "$errlogfile"
+ chown "$user":"$user" "$errlogfile"
chmod 0640 "$errlogfile"
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
if [ ! -d "$datadir/mysql" ] ; then
@@ -95,18 +97,18 @@
then
mkdir -p "$datadir" || exit 1
fi
- chown mysql:mysql "$datadir"
+ chown "$user":"$user" "$datadir"
chmod 0755 "$datadir"
[ -x /sbin/restorecon ] && /sbin/restorecon "$datadir"
# Now create the database
- action $"Initializing MySQL database: " /usr/bin/mysql_install_db --datadir="$datadir" --user=mysql
+ action $"Initializing MySQL database: " /usr/bin/mysql_install_db --datadir="$datadir" --user="$user"
ret=$?
- chown -R mysql:mysql "$datadir"
+ chown -R "$user":"$user" "$datadir"
if [ $ret -ne 0 ] ; then
return $ret
fi
fi
- chown mysql:mysql "$datadir"
+ chown "$user":"$user" "$datadir"
chmod 0755 "$datadir"
# We check if there is already a process using the socket file,
# since otherwise this init script could report false positive
@@ -126,7 +128,7 @@
# alarms, per bug #547485
$exec --datadir="$datadir" --socket="$socketfile" \
--pid-file="$mypidfile" \
- --basedir=/usr --user=mysql >/dev/null 2>&1 &
+ --basedir=/usr --user="$user" >/dev/null 2>&1 &
safe_pid=$!
# Spin for a maximum of N seconds waiting for the server to come up;
# exit the loop immediately if mysqld_safe process disappears.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment