Daemon helper scripts sanity changes and spec files clean-up

This commit is contained in:
Honza Horak 2014-02-25 15:56:53 +01:00
parent d283b05085
commit fff9c6f05a
6 changed files with 119 additions and 84 deletions

16
mariadb-check-socket Normal file
View File

@ -0,0 +1,16 @@
#!/bin/sh
# We check if there is already a process using the socket file,
# since otherwise the systemd service file could report false
# positive result when starting and mysqld_safe could remove
# a socket file, which is actually being used by a different daemon.
source ./mariadb-scripts-common
if fuser "$socketfile" &>/dev/null ; then
echo "Socket file $socketfile exists." >&2
echo "Is another MySQL daemon running with the same unix socket?" >&2
exit 1
fi
exit 0

View File

@ -3,33 +3,14 @@
# This script creates the mysql data directory during first service start.
# In subsequent starts, it does nothing much.
# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="$3"
fi
}
# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld_safe log-error "/var/log/mariadb/mariadb.log"
errlogfile="$result"
get_mysql_option mysqld socket "$datadir/mysql.sock"
socketfile="$result"
source ./mariadb-scripts-common
# Absorb configuration settings from the specified systemd service file,
# or the default "mysqld" service if not specified
# or the default "mariadb" service if not specified
SERVICE_NAME="$1"
if [ x"$SERVICE_NAME" = x ]
then
SERVICE_NAME=mysqld.service
SERVICE_NAME=mariadb.service
fi
myuser=`systemctl show -p User "${SERVICE_NAME}" |
@ -52,16 +33,6 @@ chown "$myuser:$mygroup" "$errlogfile"
chmod 0640 "$errlogfile"
[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
# We check if there is already a process using the socket file,
# since otherwise this systemd service file could report false
# positive result when starting and mysqld_safe could remove
# a socket file, which actually uses a different daemon.
if fuser "$socketfile" &>/dev/null ; then
echo "Socket file $socketfile exists." >&2
echo "Is another MySQL daemon already running with the same unix socket?" >&2
exit 1
fi
# Make the data directory
if [ ! -d "$datadir/mysql" ] ; then
# First, make sure $datadir is there with correct permissions

54
mariadb-scripts-common Executable file
View File

@ -0,0 +1,54 @@
#!/bin/sh
# Some useful functions used in other MySQL helper scripts
# This scripts defines variables datadir, errlogfile, socketfile
export LC_ALL=C
# extract value of a MySQL option from config files
# Usage: get_mysql_option VARNAME DEFAULT SECTION [ SECTION, ... ]
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
if [ $# -ne 3 ] ; then
echo "get_mysql_option requires 3 arguments: section option default_value"
return
fi
sections="$1"
option_name="$2"
default_value="$3"
result=`/usr/bin/my_print_defaults $sections | sed -n "s/^--${option_name}=//p" | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="${default_value}"
fi
}
# Defaults here had better match what mysqld_safe will default to
# The option values are generally defined on three important places
# on the default installation:
# 1) default values are hardcoded in the code of mysqld daemon or
# mysqld_safe script
# 2) configurable values are defined in /etc/my.cnf
# 3) default values for helper scripts are specified bellow
# So, in case values are defined in my.cnf, we need to get that value.
# In case they are not defined in my.cnf, we need to get the same value
# in the daemon, as in the helper scripts. Thus, default values here
# must correspond with values defined in mysqld_safe script and source
# code itself.
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
# if there is log_error in the my.cnf, my_print_defaults still
# returns log-error
get_mysql_option mysqld_safe log-error "`hostname`.err"
errlogfile="$result"
get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock"
socketfile="$result"
get_mysql_option mysqld_safe pid-file "`hostname`.pid"
pidfile="$result"

View File

@ -1,59 +1,43 @@
#!/bin/sh
source ./mariadb-scripts-common
# This script waits for mysqld to be ready to accept connections
# (which can be many seconds or even minutes after launch, if there's
# a lot of crash-recovery work to do).
# Running this as ExecStartPost is useful so that services declared as
# "After mysqld" won't be started until the database is really ready.
if [ $# -ne 1 ] ; then
echo "You need to pass daemon pid as an argument for this script."
exit 20
fi
# Service file passes us the daemon's PID (actually, mysqld_safe's PID)
daemon_pid="$1"
# extract value of a MySQL option from config files
# Usage: get_mysql_option SECTION VARNAME DEFAULT
# result is returned in $result
# We use my_print_defaults which prints all options from multiple files,
# with the more specific ones later; hence take the last match.
get_mysql_option(){
result=`/usr/bin/my_print_defaults "$1" | sed -n "s/^--$2=//p" | tail -n 1`
if [ -z "$result" ]; then
# not found, use default
result="$3"
fi
}
# Defaults here had better match what mysqld_safe will default to
get_mysql_option mysqld datadir "/var/lib/mysql"
datadir="$result"
get_mysql_option mysqld socket "/var/lib/mysql/mysql.sock"
socketfile="$result"
# Wait for the server to come up or for the mysqld process to disappear
ret=0
while /bin/true; do
MYSQLDRUNNING=0
if [ -d "/proc/${daemon_pid}" ] ; then
MYSQLDRUNNING=1
# Check process still exists
if ! [ -d "/proc/${daemon_pid}" ] ; then
ret=1
break
fi
RESPONSE=`/usr/bin/mysqladmin --no-defaults --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
mret=$?
if [ $mret -eq 0 ] && [ $MYSQLDRUNNING -eq 1 ]; then
if [ $mret -eq 0 ] ; then
break
fi
# exit codes 1, 11 (EXIT_CANNOT_CONNECT_TO_SERVICE) are expected,
# anything else suggests a configuration error
if [ $mret -ne 1 -a $mret -ne 11 ]; then
ret=1
ret=$mret
break
fi
# "Access denied" also means the server is alive
echo "$RESPONSE" | grep -q "Access denied for user" && break
# Check process still exists
if ! /bin/kill -0 $daemon_pid 2>/dev/null; then
ret=1
break
fi
sleep 1
done

View File

@ -33,6 +33,7 @@ Type=simple
User=mysql
Group=mysql
ExecStartPre=/usr/libexec/mariadb-check-socket
ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485

View File

@ -7,7 +7,7 @@
Name: mariadb
Version: 5.5.35
Release: 4%{?dist}
Release: 5%{?dist}
Epoch: 1
Summary: A community developed branch of MySQL
@ -46,9 +46,11 @@ Source10: mariadb.tmpfiles.d
Source11: mariadb.service
Source12: mariadb-prepare-db-dir
Source13: mariadb-wait-ready
Source14: rh-skipped-tests-base.list
Source15: rh-skipped-tests-arm.list
Source14: mariadb-check-socket
Source15: mariadb-scripts-common
Source16: mysqld.service
Source51: rh-skipped-tests-base.list
Source52: rh-skipped-tests-arm.list
# Working around perl dependency checking bug in rpm FTTB. Remove later.
Source999: filter-requires-mysql.sh
@ -276,10 +278,10 @@ MariaDB is a community developed branch of MySQL.
rm -f mysql-test/t/ssl_8k_key-master.opt
# generate a list of tests that fail, but are not disabled by upstream
cat %{SOURCE14} > mysql-test/rh-skipped-tests.list
cat %{SOURCE51} > mysql-test/rh-skipped-tests.list
# disable some tests failing on ARM architectures
%ifarch %{arm} aarch64
cat %{SOURCE15} >> mysql-test/rh-skipped-tests.list
cat %{SOURCE52} >> mysql-test/rh-skipped-tests.list
%endif
# disable some tests failing on ppc and s390
%ifarch ppc ppc64 ppc64p7 s390 s390x aarch64
@ -444,16 +446,16 @@ mv ${RPM_BUILD_ROOT}%{_pkgdocdir}/MariaDB-server-%{version}/INFO_SRC ${RPM_BUILD
mv ${RPM_BUILD_ROOT}%{_pkgdocdir}/MariaDB-server-%{version}/INFO_BIN ${RPM_BUILD_ROOT}%{_libdir}/mysql/
rm -rf ${RPM_BUILD_ROOT}%{_pkgdocdir}/MariaDB-server-%{version}/
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/mariadb
chmod 0750 $RPM_BUILD_ROOT%{_localstatedir}/log/mariadb
touch $RPM_BUILD_ROOT%{_localstatedir}/log/mariadb/mariadb.log
ln -s %{_localstatedir}/log/mariadb/mariadb.log $RPM_BUILD_ROOT%{_localstatedir}/log/mysqld.log
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/log/%{name}
chmod 0750 $RPM_BUILD_ROOT%{_localstatedir}/log/%{name}
touch $RPM_BUILD_ROOT%{_localstatedir}/log/%{name}/%{name}.log
ln -s %{_localstatedir}/log/%{name}/%{name}.log $RPM_BUILD_ROOT%{_localstatedir}/log/mysqld.log
# current setting in my.cnf is to use /var/run/mariadb for creating pid file,
# however since my.cnf is not updated by RPM if changed, we need to create mysqld
# as well because users can have od settings in their /etc/my.cnf
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/mysqld
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/mariadb
mkdir -p $RPM_BUILD_ROOT%{_localstatedir}/run/%{name}
install -m 0755 -d $RPM_BUILD_ROOT%{_localstatedir}/lib/mysql
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}
@ -462,9 +464,11 @@ install -p -m 0644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/my.cnf
# install systemd unit files and scripts for handling server startup
mkdir -p ${RPM_BUILD_ROOT}%{_unitdir}
install -p -m 644 %{SOURCE11} ${RPM_BUILD_ROOT}%{_unitdir}/
install -p -m 644 %{SOURCE16} ${RPM_BUILD_ROOT}%{_unitdir}/mysqld.service
install -p -m 644 %{SOURCE16} ${RPM_BUILD_ROOT}%{_unitdir}/`basename %{SOURCE16}`
install -p -m 755 %{SOURCE12} ${RPM_BUILD_ROOT}%{_libexecdir}/
install -p -m 755 %{SOURCE13} ${RPM_BUILD_ROOT}%{_libexecdir}/
install -p -m 755 %{SOURCE14} ${RPM_BUILD_ROOT}%{_libexecdir}/
install -p -m 644 %{SOURCE15} ${RPM_BUILD_ROOT}%{_libexecdir}/
mkdir -p $RPM_BUILD_ROOT%{_tmpfilesdir}
install -p -m 0644 %{SOURCE10} $RPM_BUILD_ROOT%{_tmpfilesdir}/%{name}.conf
@ -508,8 +512,8 @@ rm -f ${RPM_BUILD_ROOT}%{_bindir}/mytop
# put logrotate script where it needs to be
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d
mv ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-log-rotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/mariadb
chmod 644 $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/mariadb
mv ${RPM_BUILD_ROOT}%{_datadir}/mysql/mysql-log-rotate $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}
chmod 644 $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/%{name}
mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/ld.so.conf.d
echo "%{_libdir}/mysql" > $RPM_BUILD_ROOT%{_sysconfdir}/ld.so.conf.d/%{name}-%{_arch}.conf
@ -560,11 +564,11 @@ fi
%posttrans server
if [ -f %mysqld_enabled_flag_file ] ; then
/bin/systemctl enable mariadb.service >/dev/null 2>&1 || :
/bin/systemctl enable %{name}.service >/dev/null 2>&1 || :
rm -f %mysqld_enabled_flag_file >/dev/null 2>&1 || :
fi
if [ -f %mysqld_running_flag_file ] ; then
/bin/systemctl start mariadb.service >/dev/null 2>&1 || :
/bin/systemctl start %{name}.service >/dev/null 2>&1 || :
rm -f %mysqld_running_flag_file >/dev/null 2>&1 || :
fi
@ -572,7 +576,7 @@ fi
%post libs -p /sbin/ldconfig
%post server
%systemd_post mariadb.service
%systemd_post %{name}.service
/bin/chmod 0755 %{_localstatedir}/lib/mysql
%{_sbindir}/update-alternatives --install %{_bindir}/mysqlbug \
@ -586,12 +590,12 @@ if [ $1 -eq 0 ] ; then
fi
%preun server
%systemd_preun mariadb.service
%systemd_preun %{name}.service
%postun libs -p /sbin/ldconfig
%postun server
%systemd_postun_with_restart mariadb.service
%systemd_postun_with_restart %{name}.service
if [ $1 -eq 0 ] ; then
%{_sbindir}/update-alternatives --remove mysqlbug %{_libdir}/mysql/mysqlbug
fi
@ -757,18 +761,20 @@ fi
%{_datadir}/mysql/config.*.ini
%{_unitdir}/mysqld.service
%{_unitdir}/mariadb.service
%{_unitdir}/%{name}.service
%{_libexecdir}/mariadb-prepare-db-dir
%{_libexecdir}/mariadb-wait-ready
%{_libexecdir}/mariadb-scripts-common
%{_libexecdir}/mariadb-check-socket
%{_tmpfilesdir}/%{name}.conf
%attr(0755,mysql,mysql) %dir %{_localstatedir}/run/mysqld
%attr(0755,mysql,mysql) %dir %{_localstatedir}/run/mariadb
%attr(0755,mysql,mysql) %dir %{_localstatedir}/run/%{name}
%attr(0755,mysql,mysql) %dir %{_localstatedir}/lib/mysql
%attr(0750,mysql,mysql) %dir %{_localstatedir}/log/mariadb
%attr(0640,mysql,mysql) %config %ghost %verify(not md5 size mtime) %{_localstatedir}/log/mariadb/mariadb.log
%attr(0750,mysql,mysql) %dir %{_localstatedir}/log/%{name}
%attr(0640,mysql,mysql) %config %ghost %verify(not md5 size mtime) %{_localstatedir}/log/%{name}/%{name}.log
%attr(0640,mysql,mysql) %config %ghost %verify(not md5 size mtime) %{_localstatedir}/log/mysqld.log
%config(noreplace) %{_sysconfdir}/logrotate.d/mariadb
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
%files devel
%ghost %{_bindir}/mysql_config
@ -802,6 +808,9 @@ fi
%{_mandir}/man1/mysql_client_test.1*
%changelog
* Tue Feb 25 2014 Honza Horak <hhorak@redhat.com> 1:5.5.35-5
- Daemon helper scripts sanity changes and spec files clean-up
* Tue Feb 11 2014 Honza Horak <hhorak@redhat.com> 1:5.5.35-4
- Fix typo in mysqld.service
Resolves: #1063981