Rework mysql-server parts (#8)

* Rework mysql-server parts

Use packages from distribution and combine mysql parts into a single
part.

* Rework mysql, run as root
This commit is contained in:
James Page 2018-10-30 14:03:10 -06:00 committed by Pete Vander Giessen
parent 7dda1c24f4
commit 4999a02de5
6 changed files with 87 additions and 208 deletions

View File

@ -1,50 +0,0 @@
#!/bin/bash
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
cat << EOF
= MySQL Snap Image =
The MySQL snap image is an experimental release of MySQL for the snap universal Linux package system (http://snapcraft.io/).
This image should be used for testing only, and is not suitable for a production environment.
== Commands ==
- mysql.client: Runs the MySQL client
- mysql.server: Runs the MySQL server
- mysql.startup: Initializes database if necessary, then starts the server
- mysql.help: Shows this document
== Usage guide ==
The MySQL snap requires access to the process-control interface. You connect it by running:
snap connect mysql:process-control core:process-control
=== Running the snap ===
* Install the snap as usual
* Run sudo snap connect mysql:process-control ubuntu-core:process-control
* Run mysql.startup to initialize and start the server
* Run mysql.client -uroot -p
=== Running the snap a system service ===
Running MySQL as a system service requires root access, but the server itself should never run as root, so it drops privileges to a dedicated user. This user must own the server files and directories. Currently snapd blocks access to creating users and changing process user, so the only way to do this is to disable the restrictions by installing the snap with the --devmode argument.
=== Files and directories ===
The first time you run mysql.startup, it will generate the following in $HOME/snap/mysql/common (if run as root, /var/snap/mysql/common is used instead):
- conf/my.cnf: Basic configuration file
- data/: Data directoriy
- files/: Default location for the secure-file-priv option
- log/: Location of error log
- run/: Location of sock and pid files
EOF

View File

@ -1,28 +0,0 @@
#!/bin/bash
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
USERID=$(id -u)
if [ "${USERID}" = "0" ];
then
MYSQL_SNAPDIR=${SNAP_COMMON}
VARS="--user=mysql"
else
MYSQL_SNAPDIR=${SNAP_USER_COMMON}
VARS=""
fi
echo "Starting server..."
mysqld --defaults-file="${MYSQL_SNAPDIR}/conf/my.cnf" ${VARS} $@

View File

@ -1,75 +0,0 @@
#!/bin/bash
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
set -e
init_config() {
mkdir "${CONFDIR}"
echo "Generating config file in ${CONFFILE}..."
touch "${CONFFILE}"
echo "[mysqld]" >> ${CONFFILE}
echo "pid-file=${RUNDIR}/mysqld.pid" >> ${CONFFILE}
echo "socket=${RUNDIR}/mysqld.sock" >> ${CONFFILE}
echo "datadir=${DATADIR}" >> ${CONFFILE}
echo "log-error=${LOGDIR}/error.log" >> ${CONFFILE}
echo "secure-file-priv=${FILESDIR}" >> ${CONFFILE}
echo "basedir=${BASEDIR}" >> ${CONFFILE}
echo "[mysql]" >> ${CONFFILE}
echo "socket=${RUNDIR}/mysqld.sock" >> ${CONFFILE}
echo "Done"
}
init_database() {
echo "Initializing new database in ${DATADIR}..."
mkdir "${DATADIR}"
mysqld --defaults-file="${CONFFILE}" --initialize
echo "Done"
cat ${LOGDIR}/error.log | grep "temporary password"
}
USERID=$(id -u)
if [ "${USERID}" = "0" ];then
MYSQL_SNAPDIR="${SNAP_COMMON}"
else
MYSQL_SNAPDIR="${SNAP_USER_COMMON}"
fi
DATADIR="${MYSQL_SNAPDIR}/data"
RUNDIR="${MYSQL_SNAPDIR}/run"
LOGDIR="${MYSQL_SNAPDIR}/log"
CONFDIR="${MYSQL_SNAPDIR}/conf"
CONFFILE="${CONFDIR}/my.cnf"
FILESDIR="${MYSQL_SNAPDIR}/files"
BASEDIR="${SNAP}/usr"
[ -d "${LOGDIR}" ] || mkdir "${LOGDIR}"
[ -f "${LOGDIR}/error.log" ] || touch "${LOGDIR}/error.log"
[ -d "${FILESDIR}" ] || mkdir "${FILESDIR}"
[ -d "${RUNDIR}" ] || mkdir "${RUNDIR}"
[ -d "${CONFDIR}" ] || init_config
[ -d "${DATADIR}" ] || init_database
if [ "${USERID}" = "0" ];
then
# Ensure mysql user exists and that the correct permissions are set on various directories
adduser --system --disabled-login --ingroup mysql --home /nonexistent --gecos "MySQL Server" --shell /bin/false mysql >/dev/null
chown -R mysql:mysql "${LOGDIR}" "${FILESDIR}" "${DATADIR}" "${RUNDIR}"
chmod 750 "${LOGDIR}" "${DATADIR}"
chmod 770 "${FILESDIR}"
chmod 755 "${RUNDIR}"
VARS="--user=mysql"
fi
echo "Starting server..."
mysqld --defaults-file="${CONFFILE}" ${VARS} $@

View File

@ -14,19 +14,19 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
if [ -f "${SNAP_USER_COMMON}/conf/my.cnf" ];
if [ -f "${SNAP_USER_COMMON}/etc/mysql/my.cnf" ];
then
MYSQL_CONFFILE="${SNAP_USER_COMMON}/conf/my.cnf"
elif [ -f "${SNAP_COMMON}/conf/my.cnf" ];
MYSQL_CONFFILE="${SNAP_USER_COMMON}/etc/mysql/my.cnf"
elif [ -f "${SNAP_COMMON}/etc/mysql/my.cnf" ];
then
MYSQL_CONFFILE="${SNAP_COMMON}/conf/my.cnf"
MYSQL_CONFFILE="${SNAP_COMMON}/etc/mysql/my.cnf"
else
echo "WARNING: Can't find config file. Did you run mysql.startup?"
echo "WARNING: Can't find conf file. Did you run mysql-startup?"
fi
if [ -f ${MYSQL_CONFFILE} ];
then
echo "Using config file: ${MYSQL_CONFFILE}"
echo "Using conf file: ${MYSQL_CONFFILE}"
MYSQL_CONFPARAM="--defaults-file=${MYSQL_CONFFILE}"
fi
mysql "${MYSQL_CONFPARAM}" $@

View File

@ -0,0 +1,72 @@
#!/bin/bash
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
set -e
init_config() {
mkdir -p "${CONFDIR}"
echo "Generating config file in ${CONFFILE}..."
cat > ${CONFFILE} <<EOF
[mysqld]
pid-file=${RUNDIR}/mysqld.pid
socket=${RUNDIR}/mysqld.sock
datadir=${DATADIR}
log-error=${LOGDIR}/error.log
secure-file-priv=${FILESDIR}
basedir=${BASEDIR}
[mysql]
socket=${RUNDIR}/mysqld.sock
[mysql_upgrade]
socket=${RUNDIR}/mysqld.sock
EOF
}
init_database() {
echo "Initializing new database in ${DATADIR}..."
mkdir -p ${DATADIR}
mysqld --defaults-file=${CONFFILE} --initialize-insecure --user=root
echo "Done"
}
USERID=$(id -u)
if [ "${USERID}" = "0" ];then
MYSQL_SNAPDIR="${SNAP_COMMON}"
else
MYSQL_SNAPDIR="${SNAP_USER_COMMON}"
fi
DATADIR="${MYSQL_SNAPDIR}/lib/mysql"
RUNDIR="${MYSQL_SNAPDIR}/run/mysql"
LOGDIR="${MYSQL_SNAPDIR}/log/mysql"
CONFDIR="${MYSQL_SNAPDIR}/etc/mysql"
CONFFILE="${CONFDIR}/my.cnf"
FILESDIR="${MYSQL_SNAPDIR}/lib/mysql-files"
BASEDIR="${SNAP}/usr"
[ -d "${LOGDIR}" ] || mkdir -p ${LOGDIR}
[ -f "${LOGDIR}/error.log" ] || touch ${LOGDIR}/error.log
[ -d "${FILESDIR}" ] || {
mkdir -p ${FILESDIR}
chmod 0700 ${FILESDIR}
}
[ -d "${RUNDIR}" ] || mkdir -p ${RUNDIR}
[ -d "${CONFDIR}" ] || init_config
[ -d "${DATADIR}" ] || init_database
echo "Starting server..."
exec mysqld --defaults-file=${CONFFILE} --user=root $@

View File

@ -142,26 +142,19 @@ apps:
LC_ALL: C
# MySQL
mysql-startup:
command: mysql-startup
plugs:
- process-control
- network
- network-bind
mysql-server:
# MySQL
mysqld:
command: mysql-start-server
daemon: simple
plugs:
- process-control
- network
- network-bind
mysql-client:
mysql:
command: mysql-start-client
plugs:
- process-control
- network
- network-bind
mysql-help:
command: mysql-show-help
# RabbitMQ
rabbitmq-server:
@ -538,47 +531,14 @@ parts:
# MySQL
mysql-server:
prepare: ./stage_binaries.sh
build-packages: [libaio-dev, libmecab-dev, libnuma-dev, libncurses5-dev, wget, zlib1g-dev]
plugin: dump
source: ./
source: ./scripts/mysql
stage-packages:
- mysql-server
- mysql-client
organize:
staging-files/usr: usr/
snap:
- usr/lib/mysql/plugin/mysql_no_login.so
- usr/lib/mysql/plugin/innodb_engine.so
- usr/lib/mysql/plugin/mypluglib.so
- usr/lib/mysql/plugin/locking_service.so
- usr/lib/mysql/plugin/adt_null.so
- usr/lib/mysql/plugin/rewriter.so
- usr/lib/mysql/plugin/keyring_udf.so
- usr/lib/mysql/plugin/libmemcached.so
- usr/lib/mysql/plugin/auth_socket.so
- usr/lib/mysql/plugin/validate_password.so
- usr/lib/mysql/plugin/semisync_slave.so
- usr/lib/mysql/plugin/semisync_master.so
- usr/lib/mysql/plugin/keyring_file.so
- usr/lib/mysql/plugin/mysqlx.so
- usr/lib/mysql/plugin/version_token.so
- usr/lib/mysql/plugin/libpluginmecab.so
- usr/lib/mysql/plugin/group_replication.so
- usr/sbin/mysqld
- usr/bin/mysqlpump
- usr/bin/mysql
- usr/bin/mysql_ssl_rsa_setup
- usr/bin/my_print_defaults
- usr/bin/mysqldump
- usr/bin/mysql_tzinfo_to_sql
- usr/bin/mysql_upgrade
- usr/share/mysql/*
mysql-scripts:
plugin: dump
source: ./scripts
organize:
mysql-show-help: bin/mysql-show-help
mysql-start-server: bin/mysql-start-server
mysql-start-client: bin/mysql-start-client
mysql-startup: bin/mysql-startup
# RabbitMQa
rabbitmq-server: