-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb0a3f8
commit fcc04dc
Showing
11 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# The MySQL Server configuration file. | ||
# | ||
# For explanations see | ||
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html | ||
|
||
[mysqld] | ||
user = mysql | ||
pid-file = /var/run/mysqld/mysqld.pid | ||
socket = /var/run/mysqld/mysqld.sock | ||
port = 3306 | ||
secure-file-priv = NULL | ||
default-time-zone = SYSTEM | ||
|
||
# Make sure Data Dictionary is cross platform | ||
# https://dev.mysql.com/doc/refman/8.0/en/identifier-case-sensitivity.html | ||
lower_case_table_names = 1 | ||
|
||
# Custom config should go here | ||
!includedir /etc/mysql/conf.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/with-contenv bash | ||
|
||
# https://github.com/docker-library/mysql/issues/275#issuecomment-292208567 | ||
# > mysqld --verbose --help | grep bind-address | ||
|
||
file="${0##*/}" | ||
|
||
MYSQL_DATA_DIR=$APP_VOLUME/mysql | ||
MYSQL_PID_FILE=/var/run/mysqld/mysqld.pid | ||
|
||
# Remove stale MySQL PID file left behind when docker stops container | ||
if [[ -f $MYSQL_PID_FILE ]]; then | ||
rm -f $MYSQL_PID_FILE | ||
fi | ||
|
||
# Initialize MySQL data directory (if needed) | ||
# See https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html | ||
if [[ ! -d $MYSQL_DATA_DIR ]]; then | ||
|
||
echo "[cont-init.d] ${file}: An empty or uninitialized MySQL volume is detected in ${MYSQL_DATA_DIR}" | ||
echo "[cont-init.d] ${file}: Installing MySQL in ${MYSQL_DATA_DIR} ..." | ||
mkdir $MYSQL_DATA_DIR | ||
chown --reference=/var/lib/mysql $MYSQL_DATA_DIR | ||
chmod --reference=/var/lib/mysql $MYSQL_DATA_DIR | ||
cp -R -p /var/lib/mysql/* $MYSQL_DATA_DIR | ||
|
||
fi | ||
|
||
# Grant or revoke passwordless remote access | ||
/usr/bin/mysqld_safe --datadir=$MYSQL_DATA_DIR --user=mysql -D | ||
if [[ $APP_ENV = "development" ]] | ||
then | ||
echo "[cont-init.d] ${file}: Granting remote access of MySQL database from any IP address" | ||
/usr/bin/mysql -u root -e " | ||
CREATE USER IF NOT EXISTS 'root'@'%'; | ||
GRANT ALL ON *.* TO 'root'@'%'; | ||
FLUSH PRIVILEGES; | ||
" | ||
else | ||
echo "[cont-init.d] ${file}: Revoking remote access of MySQL database from any IP address" | ||
/usr/bin/mysql -u root -e -f " | ||
REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'root'@'%'; | ||
DROP USER IF EXISTS 'root'@'%'; | ||
" | ||
fi | ||
|
||
/usr/bin/mysqladmin -u root shutdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/with-contenv bash | ||
|
||
phpenmod -v 7.4 pdo_mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SIGQTERM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/execlineb -S1 | ||
#https://danyspin97.org/blog/getting-started-with-execline-scripting/ | ||
|
||
# @see https://github.com/just-containers/s6-overlay/issues/101 | ||
|
||
# Rely on container platform to restart this container on crash (marathon/docker-swarm/kubernetes) | ||
# BUT, when container is SIGNALLED to stop, don't interfere | ||
if { s6-test ${1} -ne 0 } | ||
if { s6-test ${1} -ne 256 } | ||
|
||
# When mysql process dies, the container should come down with it | ||
s6-svscanctl -t /var/run/s6/services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/execlineb -P | ||
|
||
sed "s/^/[mysql] /" --unbuffered |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
SIGUP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/execlineb -P | ||
#https://danyspin97.org/blog/getting-started-with-execline-scripting/ | ||
|
||
### Commands | ||
# https://dev.mysql.com/doc/refman/8.0/en/unix-signal-response.html#server-signal-response | ||
# https://skarnet.org/software/s6/s6-svc.html | ||
|
||
# SIGUP: Reload the grant tables and to flush tables, logs, the thread cache, and the host cache | ||
# > s6-svc -h /var/run/s6/services/mysql | ||
|
||
# SIGUSR2: Shutdown | ||
# > s6-svc -t /var/run/s6/services/mysql | ||
|
||
# Status | ||
# https://skarnet.org/software/s6/s6-svstat.html | ||
# > s6-svstat /var/run/s6/services/mysql | ||
|
||
# Explicitly load container environment | ||
with-contenv | ||
|
||
foreground | ||
{ | ||
importas -D production APP_ENV APP_ENV | ||
echo "Starting MySQL with environment:" $APP_ENV | ||
} | ||
|
||
fdmove -c 2 1 # redirect stderr into stdout | ||
|
||
trap -x | ||
{ | ||
term { mysqladmin -u root shutdown } | ||
} | ||
|
||
importas -D /mnt/www APP_VOLUME APP_VOLUME | ||
exec /usr/bin/mysqld_safe --datadir=${APP_VOLUME}/mysql --user=mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash -e | ||
|
||
#------------------------------------------------------------------- | ||
# Initialize mysql (if there is no datadir present). | ||
#------------------------------------------------------------------- | ||
|
||
MYSQL_DATA_DIR=${APP_VOLUME:=/mnt/www}/mysql | ||
MYSQL_RUN_DIR=/var/run/mysqld | ||
|
||
# Make sure lib dir exists | ||
if [[ ! -d $MYSQL_DATA_DIR ]]; then | ||
mkdir -p $MYSQL_DATA_DIR | ||
fi | ||
|
||
# Make sure run dir exists | ||
if [[ ! -d $MYSQL_RUN_DIR ]]; then | ||
mkdir -p $MYSQL_RUN_DIR | ||
fi | ||
|
||
# Ensure that /var/run/mysqld (used for socket and lock files) is writable | ||
chown -R mysql:mysql $MYSQL_RUN_DIR $MYSQL_DATA_DIR | ||
chmod 1777 $MYSQL_RUN_DIR $MYSQL_DATA_DIR | ||
|
||
# Initialize MySQL data directory (if needed) | ||
# See https://dev.mysql.com/doc/refman/8.0/en/data-directory-initialization.html | ||
/usr/bin/mysqld_safe --initialize-insecure --datadir=${MYSQL_DATA_DIR} --user=mysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters