[mariadb/el6] Remove systemd unit file and use init script instead

Honza Horak hhorak at fedoraproject.org
Wed Feb 20 15:12:16 UTC 2013


commit 62da23f8d9435b42e2f50b3939233ff63894d86c
Author: Honza HorĂ¡k <hhorak at redhat.com>
Date:   Wed Feb 20 16:11:09 2013 +0100

    Remove systemd unit file and use init script instead

 mariadb.spec          |   82 ++++----------------
 mariadb.tmpfiles.d    |    1 -
 mysql.init            |  209 +++++++++++++++++++++++++++++++++++++++++++++++++
 mysqld-prepare-db-dir |   82 -------------------
 mysqld-wait-ready     |   56 -------------
 mysqld.service        |   43 ----------
 6 files changed, 224 insertions(+), 249 deletions(-)
---
diff --git a/mariadb.spec b/mariadb.spec
index 719c5bb..2b3a557 100644
--- a/mariadb.spec
+++ b/mariadb.spec
@@ -1,6 +1,6 @@
 Name: mariadb
 Version: 5.5.29
-Release: 5%{?dist}
+Release: 6%{?dist}
 
 Summary: A community developed branch of MySQL
 Group: Applications/Databases
@@ -27,10 +27,7 @@ Source6: README.mysql-docs
 Source7: README.mysql-license
 Source8: libmysql.version
 Source9: mysql-embedded-check.c
-Source10: mariadb.tmpfiles.d
-Source11: mysqld.service
-Source12: mysqld-prepare-db-dir
-Source13: mysqld-wait-ready
+Source11: mysql.init
 Source14: rh-skipped-tests-base.list
 Source15: rh-skipped-tests-arm.list
 # mysql_plugin is missing in mariadb tar ball
@@ -56,7 +53,7 @@ Patch14: mariadb-buffer.patch
 
 BuildRequires: perl, readline-devel, openssl-devel
 BuildRequires: cmake, ncurses-devel, zlib-devel, libaio-devel
-BuildRequires: systemd-units, systemtap-sdt-devel
+BuildRequires: systemtap-sdt-devel
 # make test requires time and ps
 BuildRequires: time procps
 # perl modules needed to run regression tests
@@ -66,8 +63,6 @@ BuildRequires: perl(Data::Dumper), perl(Test::More)
 Requires: real-%{name}-libs%{?_isa} = %{version}-%{release}
 Requires: grep, fileutils, bash
 
-%{?systemd_requires: %systemd_requires}
-
 # MySQL (with caps) is upstream's spelling of their own RPMs for mysql
 Conflicts: MySQL
 # MariaDB replaces mysql packages
@@ -127,16 +122,6 @@ Requires: real-%{name}%{?_isa} = %{version}-%{release}
 Requires: real-%{name}-libs%{?_isa} = %{version}-%{release}
 Requires: sh-utils
 Requires(pre): /usr/sbin/useradd
-# We require this to be present for %%{_prefix}/lib/tmpfiles.d
-Requires: systemd-units
-# Make sure it's there when scriptlets run, too
-Requires(post): systemd-units
-Requires(preun): systemd-units
-Requires(postun): systemd-units
-# This is actually needed for the %%triggerun script but Requires(triggerun)
-# is not valid.  We can use %%post because this particular %%triggerun script
-# should fire just after this package is installed.
-Requires(post): systemd-sysv
 # mysqlhotcopy needs DBI/DBD support
 Requires: perl-DBI, perl-DBD-MySQL
 Conflicts: MySQL-server
@@ -453,14 +438,9 @@ install -m 0755 -d $RPM_BUILD_ROOT/var/lib/mysql
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}
 install -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 -m 644 %{SOURCE11} ${RPM_BUILD_ROOT}%{_unitdir}/
-install -m 755 %{SOURCE12} ${RPM_BUILD_ROOT}%{_libexecdir}/
-install -m 755 %{SOURCE13} ${RPM_BUILD_ROOT}%{_libexecdir}/
-
-mkdir -p $RPM_BUILD_ROOT%{_prefix}/lib/tmpfiles.d
-install -m 0644 %{SOURCE10} $RPM_BUILD_ROOT%{_prefix}/lib/tmpfiles.d/%{name}.conf
+# install init script for handling server startup
+mkdir -p $RPM_BUILD_ROOT/etc/rc.d/init.d
+install -m 755 %{SOURCE11} ${RPM_BUILD_ROOT}%{_sysconfdir}/rc.d/init.d/mysqld
 
 # Fix funny permissions that cmake build scripts apply to config files
 chmod 644 ${RPM_BUILD_ROOT}%{_datadir}/mysql/config.*.ini
@@ -530,62 +510,30 @@ rm -f ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/mysql
 %post libs -p /sbin/ldconfig
 
 %post server
-# As soon as Fedora 17, which doesn't know %%systemd_post macro,
-# is retired, we can remove the check for availability of the macro
-# and the alternative code.
-# Let's keep it there now for anyone trying to build the package
-# for F17 on his own.
-%if 0%{?systemd_post:1}
-%systemd_post mysqld.service
-%else
 if [ $1 = 1 ]; then
     # Initial installation
-    /bin/systemctl daemon-reload >/dev/null 2>&1 || :
+    /sbin/chkconfig --add mysqld
 fi
-%endif
+
 /bin/chmod 0755 /var/lib/mysql
 /bin/touch /var/log/mysqld.log
 
-# Handle upgrading from SysV initscript to native systemd unit.
-# We can tell if a SysV version of mysql was previously installed by
-# checking to see if the initscript is present.
-%triggerun server -- mysql-server
-if [ -f /etc/rc.d/init.d/mysqld ]; then
-    # Save the current service runlevel info
-    # User must manually run systemd-sysv-convert --apply mysqld
-    # to migrate them to systemd targets
-    /usr/bin/systemd-sysv-convert --save mysqld >/dev/null 2>&1 || :
-
-    # Run these because the SysV package being removed won't do them
-    /sbin/chkconfig --del mysqld >/dev/null 2>&1 || :
-    /bin/systemctl try-restart mysqld.service >/dev/null 2>&1 || :
-fi
-
 %post embedded -p /sbin/ldconfig
 
 %preun server
-%if 0%{?systemd_preun:1}
-%systemd_preun mysqld.service
-%else
 if [ $1 = 0 ]; then
     # Package removal, not upgrade
-    /bin/systemctl --no-reload disable mysqld.service >/dev/null 2>&1 || :
-    /bin/systemctl stop mysqld.service >/dev/null 2>&1 || :
+    /sbin/service mysqld stop >/dev/null 2>&1
+    /sbin/chkconfig --del mysqld
 fi
-%endif
 
 %postun libs -p /sbin/ldconfig
 
 %postun server
-%if 0%{?systemd_postun_with_restart:1}
-%systemd_postun_with_restart mysqld.service
-%else
-/bin/systemctl daemon-reload >/dev/null 2>&1 || :
 if [ $1 -ge 1 ]; then
     # Package upgrade, not uninstall
-    /bin/systemctl try-restart mysqld.service >/dev/null 2>&1 || :
+    /sbin/service mysqld condrestart >/dev/null 2>&1 || :
 fi
-%endif
 
 %postun embedded -p /sbin/ldconfig
 
@@ -749,11 +697,8 @@ fi
 %{_datadir}/mysql/my-*.cnf
 %{_datadir}/mysql/config.*.ini
 
-%{_unitdir}/mysqld.service
-%{_libexecdir}/mysqld-prepare-db-dir
-%{_libexecdir}/mysqld-wait-ready
+%{_sysconfdir}/rc.d/init.d/mysqld
 
-%{_prefix}/lib/tmpfiles.d/%{name}.conf
 %attr(0755,mysql,mysql) %dir /var/run/mysqld
 %attr(0755,mysql,mysql) %dir /var/lib/mysql
 %attr(0640,mysql,mysql) %config(noreplace) %verify(not md5 size mtime) /var/log/mysqld.log
@@ -788,6 +733,9 @@ fi
 %{_mandir}/man1/mysql_client_test.1*
 
 %changelog
+* Wed Feb 20 2013 Honza Horak <hhorak at redhat.com> 5.5.29-6
+- Remove systemd unit file and use init script instead
+
 * Wed Feb 13 2013 Honza Horak <hhorak at redhat.com> 5.5.29-5
 - Suppress warnings in tests and skip tests also on ppc64p7
 - Do not obsolete mysql
diff --git a/mysql.init b/mysql.init
new file mode 100644
index 0000000..1661f3b
--- /dev/null
+++ b/mysql.init
@@ -0,0 +1,209 @@
+#!/bin/sh
+#
+# mysqld	This shell script takes care of starting and stopping
+#		the MySQL subsystem (mysqld).
+#
+# chkconfig: - 64 36
+# description:	MySQL database server.
+# processname: mysqld
+# config: /etc/my.cnf
+# pidfile: /var/run/mysqld/mysqld.pid
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+# Source networking configuration.
+. /etc/sysconfig/network
+
+
+exec="/usr/bin/mysqld_safe"
+prog="mysqld"
+
+# Set timeouts here so they can be overridden from /etc/sysconfig/mysqld
+STARTTIMEOUT=120
+STOPTIMEOUT=60
+
+[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
+
+lockfile=/var/lock/subsys/$prog
+
+
+# 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
+}
+
+get_mysql_option mysqld datadir "/var/lib/mysql"
+datadir="$result"
+get_mysql_option mysqld socket "$datadir/mysql.sock"
+socketfile="$result"
+get_mysql_option mysqld_safe log-error "/var/log/mysqld.log"
+errlogfile="$result"
+get_mysql_option mysqld_safe pid-file "/var/run/mysqld/mysqld.pid"
+mypidfile="$result"
+
+
+start(){
+    [ -x $exec ] || exit 5
+    # check to see if it's already running
+    RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1`
+    if [ $? = 0 ]; then
+	# already running, do nothing
+	action $"Starting $prog: " /bin/true
+	ret=0
+    elif echo "$RESPONSE" | grep -q "Access denied for user"
+    then
+	# already running, do nothing
+	action $"Starting $prog: " /bin/true
+	ret=0
+    else
+    	# prepare for start
+	touch "$errlogfile"
+	chown mysql:mysql "$errlogfile" 
+	chmod 0640 "$errlogfile"
+	[ -x /sbin/restorecon ] && /sbin/restorecon "$errlogfile"
+	if [ ! -d "$datadir/mysql" ] ; then
+	    # First, make sure $datadir is there with correct permissions
+	    if [ ! -e "$datadir" -a ! -h "$datadir" ]
+	    then
+		mkdir -p "$datadir" || exit 1
+	    fi
+	    chown mysql:mysql "$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
+	    ret=$?
+	    chown -R mysql:mysql "$datadir"
+	    if [ $ret -ne 0 ] ; then
+		return $ret
+	    fi
+	fi
+	chown mysql:mysql "$datadir"
+	chmod 0755 "$datadir"
+	# Pass all the options determined above, to ensure consistent behavior.
+	# In many cases mysqld_safe would arrive at the same conclusions anyway
+	# but we need to be sure.  (An exception is that we don't force the
+	# log-error setting, since this script doesn't really depend on that,
+	# and some users might prefer to configure logging to syslog.)
+	# Note: set --basedir to prevent probes that might trigger SELinux
+	# alarms, per bug #547485
+	$exec   --datadir="$datadir" --socket="$socketfile" \
+		--pid-file="$mypidfile" \
+		--basedir=/usr --user=mysql >/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.
+	# Rather than assuming we know a valid username, accept an "access
+	# denied" response as meaning the server is functioning.
+	ret=0
+	TIMEOUT="$STARTTIMEOUT"
+	while [ $TIMEOUT -gt 0 ]; do
+	    RESPONSE=`/usr/bin/mysqladmin --socket="$socketfile" --user=UNKNOWN_MYSQL_USER ping 2>&1` && break
+	    echo "$RESPONSE" | grep -q "Access denied for user" && break
+	    if ! /bin/kill -0 $safe_pid 2>/dev/null; then
+		echo "MySQL Daemon failed to start."
+		ret=1
+		break
+	    fi
+	    sleep 1
+	    let TIMEOUT=${TIMEOUT}-1
+	done
+	if [ $TIMEOUT -eq 0 ]; then
+	    echo "Timeout error occurred trying to start MySQL Daemon."
+	    ret=1
+	fi
+	if [ $ret -eq 0 ]; then
+	    action $"Starting $prog: " /bin/true
+	    touch $lockfile
+	else
+	    action $"Starting $prog: " /bin/false
+	fi
+    fi
+    return $ret
+}
+
+stop(){
+	if [ ! -f "$mypidfile" ]; then
+	    # not running; per LSB standards this is "ok"
+	    action $"Stopping $prog: " /bin/true
+	    return 0
+	fi
+	MYSQLPID=`cat "$mypidfile"`
+	if [ -n "$MYSQLPID" ]; then
+	    /bin/kill "$MYSQLPID" >/dev/null 2>&1
+	    ret=$?
+	    if [ $ret -eq 0 ]; then
+		TIMEOUT="$STOPTIMEOUT"
+		while [ $TIMEOUT -gt 0 ]; do
+		    /bin/kill -0 "$MYSQLPID" >/dev/null 2>&1 || break
+		    sleep 1
+		    let TIMEOUT=${TIMEOUT}-1
+		done
+		if [ $TIMEOUT -eq 0 ]; then
+		    echo "Timeout error occurred trying to stop MySQL Daemon."
+		    ret=1
+		    action $"Stopping $prog: " /bin/false
+		else
+		    rm -f $lockfile
+		    rm -f "$socketfile"
+		    action $"Stopping $prog: " /bin/true
+		fi
+	    else
+		action $"Stopping $prog: " /bin/false
+	    fi
+	else
+	    # failed to read pidfile, probably insufficient permissions
+	    action $"Stopping $prog: " /bin/false
+	    ret=4
+	fi
+	return $ret
+}
+ 
+restart(){
+    stop
+    start
+}
+
+condrestart(){
+    [ -e $lockfile ] && restart || :
+}
+
+
+# See how we were called.
+case "$1" in
+  start)
+    start
+    ;;
+  stop)
+    stop
+    ;;
+  status)
+    status $prog
+    ;;
+  restart)
+    restart
+    ;;
+  condrestart|try-restart)
+    condrestart
+    ;;
+  reload)
+    exit 3
+    ;;
+  force-reload)
+    restart
+    ;;
+  *)
+    echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
+    exit 2
+esac
+
+exit $?


More information about the scm-commits mailing list