diff options
author | layman <layman@localhost> | 2015-05-12 15:39:42 -0400 |
---|---|---|
committer | layman <layman@localhost> | 2015-05-12 15:39:42 -0400 |
commit | 61d458966df5cfc46055cd438e314b2416efd63e (patch) | |
tree | ca3f878129b2953ce0a5787de15c5c9a076009f0 | |
parent | [percona-server] Security version bump; drop vulnerable versions (diff) | |
download | mysql-61d458966df5cfc46055cd438e314b2416efd63e.tar.gz mysql-61d458966df5cfc46055cd438e314b2416efd63e.tar.bz2 mysql-61d458966df5cfc46055cd438e314b2416efd63e.zip |
[mysql-init-scripts] First attempt at s6 integration which OpenRC now supports. Still need to come up with a way to wait until mysql is ready
-rw-r--r-- | dev-db/mysql-init-scripts/files/init.d-s6 | 98 | ||||
-rw-r--r-- | dev-db/mysql-init-scripts/files/run-s6 | 18 | ||||
-rw-r--r-- | dev-db/mysql-init-scripts/metadata.xml | 3 | ||||
-rw-r--r-- | dev-db/mysql-init-scripts/mysql-init-scripts-2.1_alpha1.ebuild | 77 |
4 files changed, 196 insertions, 0 deletions
diff --git a/dev-db/mysql-init-scripts/files/init.d-s6 b/dev-db/mysql-init-scripts/files/init.d-s6 new file mode 100644 index 0000000..4c2424f --- /dev/null +++ b/dev-db/mysql-init-scripts/files/init.d-s6 @@ -0,0 +1,98 @@ +#!/sbin/openrc-run +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +depend() { + use net.lo + # localmount needed for $basedir + need localmount s6-svscan +} + +get_config() { + my_print_defaults --config-file="$1" mysqld | + sed -n -e "s/^--$2=//p" +} + +mysql_svcname() { + local ebextra= + case "${SVCNAME}" in + mysql*) ;; + *) ebextra=" (mysql)" ;; + esac + echo "${SVCNAME}${ebextra}" +} + +extra_commands="checkconfig" +supervisor=s6 +name=$(mysql_svcname) +#s6_svwait_options_start="-U -t $((1000*${STARTUP_EARLY_TIMEOUT:-1000}))" + +start_pre() { + # Check the config or die + checkconfig || return 1 + + MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}" + + if [ ! -r "${MY_CNF}" ] ; then + eerror "Cannot read the configuration file \`${MY_CNF}'" + return 1 + fi + + # tail -n1 is critical as these we only want the last instance of the option + local datadir=$(get_config "${MY_CNF}" datadir | tail -n1) + local pidfile=$(get_config "${MY_CNF}" pid-file | tail -n1) + local socket=$(get_config "${MY_CNF}" socket | tail -n1) + local chroot=$(get_config "${MY_CNF}" chroot | tail -n1) + + if [ -n "${chroot}" ] ; then + socket="${chroot}/${socket}" + pidfile="${chroot}/${pidfile}" + fi + + if [ ! -d "${datadir}" ] ; then + eerror "MySQL datadir \`${datadir}' is empty or invalid" + eerror "Please check your config file \`${MY_CNF}'" + return 1 + fi + + if [ ! -d "${datadir}"/mysql ] ; then + # find which package is installed to report an error + local EROOT=$(portageq envvar EROOT) + local DBPKG_P=$(portageq match ${EROOT} $(portageq expand_virtual ${EROOT} virtual/mysql)) + if [[ -z ${DBPKG_P} ]] ; then + eerror "You don't appear to have a server package installed yet." + else + eerror "You don't appear to have the mysql database installed yet." + eerror "Please run \`emerge --config =${DBPKG_P}\` to have this done..." + fi + return 1 + fi + + local piddir="${pidfile%/*}" + checkpath -d --owner mysql:mysql --mode 0755 "$piddir" + rc=$? + if [ $rc -ne 0 ]; then + eerror "Directory $piddir for pidfile does not exist and cannot be created" + return 1 + fi +} + +checkconfig() { + local basedir=$(get_config "${MY_CNF}" basedir | tail -n1) + ebegin "Checking mysqld configuration" + + # Suppress output to check the return value + "${basedir}"/sbin/mysqld --help --verbose &> /dev/null + + # If the above command does not return 0, + # then there is an error to echo to the user + if [ $? -ne 0 ] ; then + "${basedir}"/sbin/mysqld --help --verbose > /dev/null + fi + + eend $? "MySQL config check failed" +} + +# vim: filetype=gentoo-init-d sw=2 ts=2 sts=2 noet: + diff --git a/dev-db/mysql-init-scripts/files/run-s6 b/dev-db/mysql-init-scripts/files/run-s6 new file mode 100644 index 0000000..64a89c7 --- /dev/null +++ b/dev-db/mysql-init-scripts/files/run-s6 @@ -0,0 +1,18 @@ +#!/bin/sh +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +get_config() { + my_print_defaults --config-file="$1" mysqld | + sed -n -e "s/^--$2=//p" +} + +SVCNAME=$(cd `dirname $0` && pwd | awk -F/ '{ print $NF }' ) + +source "${ROOT:-/}etc/conf.d/${SVCNAME}" + +MY_CNF="${MY_CNF:-/etc/${SVCNAME}/my.cnf}" + +basedir=$(get_config "${MY_CNF}" basedir | tail -n1) +exec s6-notifywhenup -t ${STARTUP_TIMEOUT:-900} "${basedir}"/sbin/mysqld --defaults-file="${MY_CNF}" ${MY_ARGS} diff --git a/dev-db/mysql-init-scripts/metadata.xml b/dev-db/mysql-init-scripts/metadata.xml index abf3529..669c23b 100644 --- a/dev-db/mysql-init-scripts/metadata.xml +++ b/dev-db/mysql-init-scripts/metadata.xml @@ -2,4 +2,7 @@ <!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> <pkgmetadata> <herd>mysql</herd> + <use> + <flag name="s6">Install an OpenRC service that monitors using <package>sys-apps/s6</package> instead of using start-stop-daemon</flag> + </use> </pkgmetadata> diff --git a/dev-db/mysql-init-scripts/mysql-init-scripts-2.1_alpha1.ebuild b/dev-db/mysql-init-scripts/mysql-init-scripts-2.1_alpha1.ebuild new file mode 100644 index 0000000..232246d --- /dev/null +++ b/dev-db/mysql-init-scripts/mysql-init-scripts-2.1_alpha1.ebuild @@ -0,0 +1,77 @@ +# Copyright 1999-2015 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +EAPI=5 + +inherit systemd + +DESCRIPTION="Gentoo MySQL init scripts." +HOMEPAGE="http://www.gentoo.org/" +SRC_URI="" + +LICENSE="GPL-2" +SLOT="0" +KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~sparc-fbsd ~x86-fbsd" +IUSE="s6" + +DEPEND="" +# This _will_ break with MySQL 5.0, 4.x, 3.x +# It also NEEDS openrc for the save_options/get_options builtins. +RDEPEND=" + !<dev-db/mysql-5.1 + s6? ( >=sys-apps/openrc-0.16 sys-apps/s6 ) + " +# Need to set S due to PMS saying we need it existing, but no SRC_URI +S=${WORKDIR} + +src_install() { + newconfd "${FILESDIR}/conf.d-2.0" "mysql" + if use s6 ; then + newinitd "${FILESDIR}/init.d-s6" "mysql" + exeinto /etc/svc.d/mysql + newexe "${FILESDIR}/run-s6" "run" + else + newinitd "${FILESDIR}/init.d-2.0" "mysql" + fi + + # systemd unit installation + exeinto /usr/libexec + doexe "${FILESDIR}"/mysqld-wait-ready + systemd_dounit "${FILESDIR}/mysqld.service" + systemd_newunit "${FILESDIR}/mysqld_at.service" "mysqld@.service" + systemd_dotmpfilesd "${FILESDIR}/mysql.conf" + + insinto /etc/logrotate.d + newins "${FILESDIR}/logrotate.mysql" "mysql" +} + +pkg_postinst() { + grep -sq mysql_slot "${ROOT}"/etc/conf.d/mysql + old_conf_present=$? + grep -sq get_slot_config "${ROOT}"/etc/init.d/mysql + old_init_present=$? + + egrep -sq 'MY_CNF|MY_ARGS|(STARTUP|STOP)_TIMEOUT' "${ROOT}"/etc/conf.d/mysql + new_conf_present=$? + egrep -sq 'MY_ARGS|STOP_TIMEOUT' "${ROOT}"/etc/init.d/mysql + new_init_present=$? + + einfo "Please note that if you are using multiple internal 'slots' in the" + einfo "old conf.d file, you should use multiple init files now." + echo old $old_conf_present $old_init_present + echo new $new_conf_present $new_init_present + + # new scripts present + if [ $new_conf_present -eq 0 -a $new_init_present -eq 0 -a \ + $old_conf_present -eq 1 -a $old_init_present -eq 1 ]; then + : + elif [ $old_conf_present -eq 0 -a $old_init_present -eq 0 -a \ + $new_conf_present -eq 1 -a $new_init_present -eq 1 ]; then + ewarn "Old /etc/init.d/mysql and /etc/conf.d/mysql still present!" + ewarn "Update both of those files to the new versions!" + else + eerror "DANGER, mixed update of /etc/init.d/mysql and /etc/conf.d/mysql" + eerror "detected! You must update BOTH to the new versions" + fi +} |