Added mysql snap. (#2)

This commit is contained in:
Pete Vander Giessen 2018-09-25 21:04:40 +02:00 committed by GitHub
parent b6db5853a9
commit 10d7a788bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 292 additions and 86 deletions

50
scripts/mysql-show-help Executable file
View File

@ -0,0 +1,50 @@
#!/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

32
scripts/mysql-start-client Executable file
View File

@ -0,0 +1,32 @@
#!/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
if [ -f "${SNAP_USER_COMMON}/conf/my.cnf" ];
then
MYSQL_CONFFILE="${SNAP_USER_COMMON}/conf/my.cnf"
elif [ -f "${SNAP_COMMON}/conf/my.cnf" ];
then
MYSQL_CONFFILE="${SNAP_COMMON}/conf/my.cnf"
else
echo "WARNING: Can't find config file. Did you run mysql.startup?"
fi
if [ -f ${MYSQL_CONFFILE} ];
then
echo "Using config file: ${MYSQL_CONFFILE}"
MYSQL_CONFPARAM="--defaults-file=${MYSQL_CONFFILE}"
fi
mysql "${MYSQL_CONFPARAM}" $@

28
scripts/mysql-start-server Executable file
View File

@ -0,0 +1,28 @@
#!/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} $@

75
scripts/mysql-startup Executable file
View File

@ -0,0 +1,75 @@
#!/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

@ -7,24 +7,21 @@ description: |
here.
grade: devel
confinement: classic
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
OS_PLACEMENT_CONFIG_DIR: $SNAP/etc/nova/
apps:
# Keystone
keystone-uwsgi:
command: snap-openstack keystone-uwsgi
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network-bind
keystone-manage:
command: snap-openstack keystone-manage
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
@ -32,113 +29,64 @@ apps:
nova-uwsgi:
command: snap-openstack nova-uwsgi
daemon: simple
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
OS_PLACEMENT_CONFIG_DIR: $SNAP/etc/nova/
plugs:
- network-bind
nova-api:
command: snap-openstack nova-api-os-compute
daemon: simple
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network-bind
conductor:
command: snap-openstack nova-conductor
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network
scheduler:
command: snap-openstack nova-scheduler
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network
consoleauth:
command: snap-openstack nova-consoleauth
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network
nova-manage:
command: snap-openstack nova-manage
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
# Neutron
neutron-api:
command: snap-openstack neutron-server
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network-bind
neutron-manage:
command: snap-openstack neutron-db-manage
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
# Glance
glance-api:
command: snap-openstack glance-api
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network-bind
registry:
command: snap-openstack glance-registry
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
plugs:
- network
- network-bind
glance-manage:
command: snap-openstack glance-manage
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
# Openstack Shared Services
nginx:
command: snap-openstack nginx
environment:
LD_LIBRARY_PATH: $SNAP/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: forking
plugs:
- network-bind
@ -147,10 +95,6 @@ apps:
ovs-vswitchd:
command: ovs-wrapper $SNAP/share/openvswitch/scripts/ovs-ctl --no-ovsdb-server --no-monitor --system-id=random start
stop-command: ovs-wrapper $SNAP/share/openvswitch/scripts/ovs-ctl --no-ovsdb-server stop
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: forking
plugs:
- network
@ -161,10 +105,6 @@ apps:
- system-trace
ovsdb-server:
command: ovs-wrapper $SNAP/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd --no-monitor --system-id=random start
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
stop-command: ovs-wrapper $SNAP/share/openvswitch/scripts/ovs-ctl --no-ovs-vswitchd stop
daemon: forking
plugs:
@ -176,44 +116,24 @@ apps:
- system-trace
ovs-vsctl:
command: ovs-wrapper $SNAP/bin/ovs-vsctl
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
ovs-appctl:
command: ovs-wrapper $SNAP/bin/ovs-appctl
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
ovs-ofctl:
command: ovs-wrapper $SNAP/bin/ovs-ofctl
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
ovs-dpctl:
command: ovs-wrapper $SNAP/bin/ovs-dpctl
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
plugs:
- network
# Libvirt/Qemu
libvirt-bin:
command: bin/launch-libvirtd
environment:
LD_LIBRARY_PATH: $SNAP/lib:$SNAP/usr/lib
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
daemon: simple
virsh:
command: bin/virsh
@ -221,6 +141,28 @@ apps:
PATH: $SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH
LC_ALL: C
# MySQL
mysql-startup:
command: mysql-startup
plugs:
- process-control
- network
- network-bind
mysql-server:
command: mysql-start-server
plugs:
- process-control
- network
- network-bind
mysql-client:
command: mysql-start-client
plugs:
- process-control
- network
- network-bind
mysql-help:
command: mysql-show-help
parts:
# Keystone
keystone:
@ -533,3 +475,48 @@ parts:
# runtime
# * is not used to avoid directory merge conflicts
snap/microstack/current/: ./
# MySQL
mysql-server:
prepare: ./stage_binaries.sh
build-packages: [libaio-dev, libmecab-dev, libnuma-dev, libncurses5-dev, wget, zlib1g-dev]
plugin: dump
source: ./
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

34
stage_binaries.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/sh
# 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
SNAPDIR=$(pwd)
SNAPTMP=$(mktemp -d)
cd ${SNAPTMP}
MYSQL_VERSION_MAJOR=5.7
MYSQL_VERSION_FULL=5.7.17-1ubuntu16.04
FILENAME="mysql-server_${MYSQL_VERSION_FULL}_amd64.deb-bundle.tar"
wget "http://dev.mysql.com/get/Downloads/MySQL-{MYSQL_VERSION_MAJOR}/${FILENAME}"
tar -xvf "${FILENAME}"
ar x mysql-community-client_${MYSQL_VERSION_FULL}_amd64.deb
tar -xvf data.tar.xz
rm data.tar.xz
ar x mysql-community-server_${MYSQL_VERSION_FULL}_amd64.deb
tar -xvf data.tar.xz
mkdir staging-files
mv usr staging-files/
rm -rf ${SNAPDIR}/staging-files
mv staging-files ${SNAPDIR}
cd ${SNAPDIR}