Files
microstack/snap-wrappers/mysql/mysql-start-server
Pete Vander Giessen 1a25e50a17 Made horizon, rabbit and mysql ports configurable
Addresses requests to make it easier to avoid conflicts between the
Horizon dashboard and http services that might already be running on
the machine.

Configurable via snap config. Exposing via arguments to .init and
testing post init configuration is left for a separate PR.

Eventually, these may move to non standard ports by default. This PR
sets the stage for that, but further discussion is needed before we
decide whether to implement.

(This commit also contains a sneaky fix for the username display at the
end of the launch script.)

Closes-Bug: 1814829
Change-Id: If728d6ec8024bca4d3e809637fbdcc03ed4e6934
2019-11-27 15:27:54 +00:00

84 lines
2.2 KiB
Bash
Executable File

#!/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() {
# Write out config.
# Include 'client' section for pymysql client.
# TODO: is [mysql] section necessary?
mkdir -p "${CONFDIR}"
echo "Generating config file in ${CONFFILE}..."
cat > ${CONFFILE} <<EOF
[mysqld]
pid-file=${RUNDIR}/mysqld.pid
socket=${RUNDIR}/mysqld.sock
port=${PORT}
datadir=${DATADIR}
log-error=${LOGDIR}/error.log
secure-file-priv=${FILESDIR}
basedir=${BASEDIR}
[mysql]
socket=${RUNDIR}/mysqld.sock
port=${PORT}
[client]
socket=${RUNDIR}/mysqld.sock
port=${PORT}
[mysql_upgrade]
socket=${RUNDIR}/mysqld.sock
port=${PORT}
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"
PORT=$(snapctl get config.network.ports.mysql)
[ -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 $@