-
Notifications
You must be signed in to change notification settings - Fork 200
Generate configuration file with envsubst #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| [mysqld] | ||
| user = mysql | ||
|
|
||
| datadir = ${MYSQL_DATADIR} | ||
| basedir = /opt/rh/mysql55/root/usr | ||
| plugin-dir = /opt/rh/mysql55/root/usr/lib64/mysql/plugin | ||
|
|
||
| general_log = ON | ||
|
|
||
| # Disable unix socket | ||
| socket = | ||
|
|
||
| # Disabling symbolic-links is recommended to prevent assorted security risks | ||
| symbolic-links = 0 | ||
|
|
||
| # http://www.percona.com/blog/2008/05/31/dns-achilles-heel-mysql-installation/ | ||
| skip_name_resolve | ||
|
|
||
| # | ||
| # Settings configured by the user | ||
| # | ||
|
|
||
| # Sets how the table names are stored and compared. Default: 0 | ||
| lower_case_table_names = ${MYSQL_LOWER_CASE_TABLE_NAMES} | ||
|
|
||
| # The maximum permitted number of simultaneous client connections. Default: 151 | ||
| max_connections = ${MYSQL_MAX_CONNECTIONS} | ||
|
|
||
| # The minimum length of the word to be included in a FULLTEXT index. Default: 4 | ||
| ft_min_word_len = ${MYSQL_FT_MIN_WORD_LEN} | ||
|
|
||
| # The maximum length of the word to be included in a FULLTEXT index. Default: 20 | ||
| ft_max_word_len = ${MYSQL_FT_MAX_WORD_LEN} | ||
|
|
||
| # In case the native AIO is broken. Default: 1 | ||
| # See http://help.directadmin.com/item.php?id=529 | ||
| innodb_use_native_aio = ${MYSQL_AIO} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,17 @@ source $HOME/.bashrc | |
| set -eu | ||
|
|
||
| # Data directory where MySQL database files live. The data subdirectory is here | ||
| # because .bashrc lives in /var/lib/mysql/ and we don't want a volume to | ||
| # override it. | ||
| MYSQL_DATADIR=/var/lib/mysql/data | ||
| MYSQL_DEFAULTS_FILE=/opt/openshift/etc/my.cnf | ||
| # because .bashrc and my.cnf both live in /var/lib/mysql/ and we don't want a | ||
| # volume to override it. | ||
| export MYSQL_DATADIR=/var/lib/mysql/data | ||
|
|
||
| # Configuration settings. | ||
| export MYSQL_DEFAULTS_FILE=$HOME/my.cnf | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the intent here? you later assume the file is really named my.cnf.template.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the template has the .template suffix. But the generated file is
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, it's just not named well... it's the mysql config file, right? it's not the default or template.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a defaults file (or option file) in MySQL nomenclature: https://dev.mysql.com/doc/refman/5.5/en/option-file-options.html#option_general_defaults-file
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. huh, ok, looks good then! :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bparees yeah, I was also a bit confused about the naming |
||
| export MYSQL_LOWER_CASE_TABLE_NAMES=${MYSQL_LOWER_CASE_TABLE_NAMES:-0} | ||
| export MYSQL_MAX_CONNECTIONS=${MYSQL_MAX_CONNECTIONS:-151} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rather than doing this, why not just default the values in the template file?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nm, i see envsubst doesn't support defaults. |
||
| export MYSQL_FT_MIN_WORD_LEN=${MYSQL_FT_MIN_WORD_LEN:-4} | ||
| export MYSQL_FT_MAX_WORD_LEN=${MYSQL_FT_MAX_WORD_LEN:-20} | ||
| export MYSQL_AIO=${MYSQL_AIO:-1} | ||
|
|
||
| # Be paranoid and stricter than we should be. | ||
| # https://dev.mysql.com/doc/refman/5.5/en/identifiers.html | ||
|
|
@@ -26,10 +33,20 @@ function usage() { | |
| echo " \$MYSQL_DATABASE (regex: '$mysql_identifier_regex')" | ||
| echo "Optional:" | ||
| echo " \$MYSQL_ROOT_PASSWORD (regex: '$mysql_password_regex')" | ||
| echo "Settings:" | ||
| echo " \$MYSQL_LOWER_CASE_TABLE_NAMES (default: 0)" | ||
| echo " \$MYSQL_MAX_CONNECTIONS (default: 151)" | ||
| echo " \$MYSQL_FT_MIN_WORD_LEN (default: 4)" | ||
| echo " \$MYSQL_FT_MAX_WORD_LEN (default: 20)" | ||
| echo " \$MYSQL_AIO (default: 1)" | ||
| exit 1 | ||
| } | ||
|
|
||
| function check_env_vars() { | ||
| if ! [[ -v MYSQL_USER && -v MYSQL_PASSWORD && -v MYSQL_DATABASE ]]; then | ||
| usage | ||
| fi | ||
|
|
||
| [[ "$MYSQL_USER" =~ $mysql_identifier_regex ]] || usage "Invalid MySQL username" | ||
| [ ${#MYSQL_USER} -le 16 ] || usage "MySQL username too long (maximum 16 characters)" | ||
| [[ "$MYSQL_PASSWORD" =~ $mysql_password_regex ]] || usage "Invalid password" | ||
|
|
@@ -60,9 +77,7 @@ function wait_for_mysql() { | |
| done | ||
| } | ||
|
|
||
| if [ "$1" = "mysqld" -a ! -d "$MYSQL_DATADIR/mysql" ]; then | ||
|
|
||
| shift | ||
| function initialize_database() { | ||
| check_env_vars | ||
|
|
||
| echo 'Running mysql_install_db' | ||
|
|
@@ -94,6 +109,18 @@ if [ "$1" = "mysqld" -a ! -d "$MYSQL_DATADIR/mysql" ]; then | |
| EOSQL | ||
| fi | ||
| mysqladmin $admin_flags flush-privileges shutdown | ||
| } | ||
|
|
||
| # New config is generated every time a container is created. | ||
| envsubst < ${MYSQL_DEFAULTS_FILE}.template > $MYSQL_DEFAULTS_FILE | ||
|
|
||
| if [ "$1" = "mysqld" ]; then | ||
|
|
||
| shift | ||
|
|
||
| if [ ! -d "$MYSQL_DATADIR/mysql" ]; then | ||
| initialize_database | ||
| fi | ||
|
|
||
| unset_env_vars | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,16 @@ The image recognizes following environment variables that you can set during ini | |
| | `MYSQL_DATABASE` | Database name | | ||
| | `MYSQL_ROOT_PASSWORD` | Password for the root user (optional) | | ||
|
|
||
| Following environment variables influence MySQL configuration file. They are all optional. | ||
|
|
||
| | Variable name | Description | Default | ||
| | :------------------------------ | ----------------------------------------------------------------- | ------------------------------- | ||
| | `MYSQL_LOWER_CASE_TABLE_NAMES` | Sets how the table names are stored and compared | 0 | ||
| | `MYSQL_MAX_CONNECTIONS` | The maximum permitted number of simultaneous client connections | 151 | ||
| | `MYSQL_FT_MIN_WORD_LEN` | The minimum length of the word to be included in a FULLTEXT index | 4 | ||
| | `MYSQL_FT_MAX_WORD_LEN` | The maximum length of the word to be included in a FULLTEXT index | 20 | ||
| | `MYSQL_AIO` | Controls the `innodb_use_native_aio` setting value in case the native AIO is broken. See http://help.directadmin.com/item.php?id=529 | 1 | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest reviewing v2 mysql cart for variables that might be useful.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I did that, but I'm not sure that's supposed to be part of this effort. I understood we only needed a system in place, we can add variables we'll want later.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah actually adding the config settings/env variables to the various DB carts should be part of this effort.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I add all of them?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would be a good start... they all exist in the v2 cart because users asked for them over time, so it's likely the popular set. |
||
| You can also set following mount points by passing `-v /host:/container` flag to docker. | ||
|
|
||
| | Volume mount point | Description | | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${MYSQL_MAX_CONNECTIONS:-123} doesn't work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
envsubst doesn't handle defaulting unfortunately. otherwise this whole thing could be much cleaner.