Spotter-VM/mariadb.sh

29 lines
920 B
Bash
Raw Normal View History

2018-01-19 15:50:15 +01:00
#!/bin/sh
SOURCE_DIR=$(realpath $(dirname "${0}"))/mariadb
# Build Docker container
docker build -t mariadb ${SOURCE_DIR}
# Create MariaDB instance
2018-01-27 14:13:59 +01:00
mkdir -p /srv/mariadb/conf /srv/mariadb/data
2018-01-19 15:50:15 +01:00
chown 3306:3306 /srv/mariadb/data
docker run --rm --name mariadb -h mariadb -v /srv/mariadb/data:/var/lib/mysql mariadb mysql_install_db --user=mysql
# Configure MariaDB
2018-01-27 14:13:59 +01:00
cp ${SOURCE_DIR}/srv/mariadb/conf/my.cnf /srv/mariadb/conf/my.cnf
2018-01-19 15:50:15 +01:00
# Enable query logging. Only if the DEBUG environment variable is set
if [ ${DEBUG:-0} -eq 1 ]; then
2018-01-27 14:13:59 +01:00
sed -i 's/#general_log/general_log/g' /srv/mariadb/conf/my.cnf
2018-01-19 15:50:15 +01:00
fi
# Configure MariaDB service
cp ${SOURCE_DIR}/etc/init.d/mariadb /etc/init.d/mariadb
rc-update add mariadb boot
service mariadb start
# Configure MariaDB admin
2018-01-19 17:14:25 +01:00
docker exec -i mariadb sh -c 'until [ -x /run/mysqld/mysqld.sock ]; do usleep 100000; done'
2018-01-19 15:50:15 +01:00
cat ${SOURCE_DIR}/adminpwd.sql | docker exec -i mariadb mysql