summaryrefslogtreecommitdiffstats
path: root/Services/mariadb
diff options
context:
space:
mode:
Diffstat (limited to 'Services/mariadb')
-rw-r--r--Services/mariadb/Dockerfile6
-rw-r--r--Services/mariadb/README.md16
-rw-r--r--Services/mariadb/docker-compose.yml4
-rw-r--r--Services/mariadb/run.sh45
4 files changed, 40 insertions, 31 deletions
diff --git a/Services/mariadb/Dockerfile b/Services/mariadb/Dockerfile
index 0e6c67f..75d5150 100644
--- a/Services/mariadb/Dockerfile
+++ b/Services/mariadb/Dockerfile
@@ -6,9 +6,9 @@ RUN dnf -y install mariadb-common mariadb-libs mariadb-config mariadb-errmsg ma
&& dnf clean all && \
mkdir -p /tmp/sql
ENV MY_CONF=/etc/my.cnf \
- STARTUPLOG=/data/logs/mariadb/startup.log \
- LOG_PATH=/data/logs/mariadb \
- DATA_PATH=/data/mariadb \
+ STARTUPLOG=/logs/startup.log \
+ LOG_PATH=/logs \
+ DATA_PATH=/data \
LOADSQL_PATH=/tmp/sql
COPY *.sh /bin/
COPY my.cnf $MY_CONF
diff --git a/Services/mariadb/README.md b/Services/mariadb/README.md
index f940414..454d004 100644
--- a/Services/mariadb/README.md
+++ b/Services/mariadb/README.md
@@ -35,8 +35,8 @@ service:
MYSQL_PASSWORD: "pwd-test"
MYSQL_DATABASE: "db_test"
volumes:
- - "/tmp/container/logs/mariadb:/data/logs/mariadb"
- - "/tmp/container/mariadb:/data/mariadb"
+ - "/tmp/container/logs/mariadb:/logs"
+ - "/tmp/container/mariadb:/data"
```
## Docker-compose in various situations
@@ -99,8 +99,8 @@ CMD ["/bin/run.sh"]
| MYSQL_DATABASE | `string` | `no` | If present, add a new database with this name
| LOADSQL_PATH | `string` | `auto` | Path used to find sql dump to import at startup
| HOSTNAME | `auto` | `auto` | Container unique id automatically assigned by docker daemon at startup
-| LOG_PATH | `auto` | `auto` | default set to /data/logs/mariadb and used as a volume mountpoint
-| DATA_PATH | `auto` | `auto` | default set to /data/mariadb and used as a volume mountpoint
+| LOG_PATH | `auto` | `auto` | default set to /logs and used as a volume mountpoint
+| DATA_PATH | `auto` | `auto` | default set to /data and used as a volume mountpoint
## Exposed port
@@ -112,8 +112,8 @@ CMD ["/bin/run.sh"]
| Container directory | Description |
|----------------------|--------------------------------------------------------------------------|
-| /data/logs/mariadb | log directory used to record container and mariadb logs
-| /data/mariadb | data directory served by mariadb. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes
+| /logs | log directory used to record container and mariadb logs
+| /data | data directory served by mariadb. If empty will be filled with database files on startup. In other case use content from mountpoint or data volumes
## Testing the service
@@ -134,8 +134,8 @@ You must have a working environment with the source code of this repository. Rea
1. Jump into the container directory with `cd Services/mariadb`
2. Build the container using `docker build -t sv-mariadb .`
3. Run this container
- 1. Interactively with `docker run -p 3306:3306 -v /data/logs/mariadb -it sv-mariadb`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...)
- 2. As a daemon with `docker run -p 3306:3306 -v /data/logs/mariadb -d sv-mariadb`
+ 1. Interactively with `docker run -p 3306:3306 -v /logs -it sv-mariadb`. If you add a second parameter (like `/bin/bash`) to will run this command instead of the default entrypoint. Usefull to interact with this container (ex: `/bin/bash`, `/bin/ps -a`, `/bin/df -h`,...)
+ 2. As a daemon with `docker run -p 3306:3306 -v /logs -d sv-mariadb`
### Build & run a container using `docker-compose`
diff --git a/Services/mariadb/docker-compose.yml b/Services/mariadb/docker-compose.yml
index f1a39ca..18df4ad 100644
--- a/Services/mariadb/docker-compose.yml
+++ b/Services/mariadb/docker-compose.yml
@@ -16,5 +16,5 @@ server:
MYSQL_PASSWORD: "pwd-test"
MYSQL_DATABASE: "db_test"
volumes:
- - "/tmp/container/logs/mariadb:/data/logs/mariadb"
- - "/tmp/container/mariadb:/data/mariadb" \ No newline at end of file
+ - "/tmp/container/logs/mariadb:/logs"
+ - "/tmp/container/mariadb:/data" \ No newline at end of file
diff --git a/Services/mariadb/run.sh b/Services/mariadb/run.sh
index c11f784..be35356 100644
--- a/Services/mariadb/run.sh
+++ b/Services/mariadb/run.sh
@@ -4,11 +4,11 @@ source /bin/sx-lib.sh
function check_mariadb_environment {
check_environment
if [ ! -v DATA_PATH ]; then
- DATA_PATH="/data/mariadb"
+ DATA_PATH="/data"
export DATA_PATH
fi
if [ ! -v LOG_PATH ]; then
- LOG_PATH="/data/logs/mariadb"
+ LOG_PATH="/logs"
export LOG_PATH
fi
}
@@ -80,6 +80,12 @@ function begin_config {
mysql_install_db --datadir=$DATA_PATH --defaults-file=$MY_CONF --user=mysql > /dev/null 2>&1
chown mysql:mysql -R $DATA_PATH
echo "Installing MariaDB in $DATA_PATH is DONE !"
+ config_startserver
+ config_createadmin
+ config_createuser
+ config_createdatabase
+ config_importsql
+ config_stopserver
else
echo "mariadb directory is initialized"
echo "Reusing MariaDB in $DATA_PATH ..."
@@ -203,27 +209,30 @@ function end_config {
echo "=> END MARIADB CONFIGURATION"
}
+function stop_mariadb_handler {
+ mysqladmin -uroot shutdown
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ echo "| Container $HOSTNAME is now STOPPED" | tee -a $STARTUPLOG
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ exit 143; # 128 + 15 -- SIGTERM
+}
+
# Start the mariadb server as a deamon and execute it inside
# the running shell
-function start_daemon {
- echo "=> Starting mariadb daemon ..." | tee -a $STARTUPLOG
- display_container_started | tee -a $STARTUPLOG
- exec mysqld_safe
+function start_service_mariadb {
+ trap 'kill ${!}; stop_mariadb_handler' SIGHUP SIGINT SIGQUIT SIGTERM SIGKILL SIGSTOP SIGCONT
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ echo "| Container $HOSTNAME is now RUNNING" | tee -a $STARTUPLOG
+ echo "+=====================================================" | tee -a $STARTUPLOG
+ exec mysqld_safe &
+ while true
+ do
+ tail -f /dev/null & wait ${!}
+ done
}
-
-if [[ "$0" == *"run.sh" && ! $1 = "" ]];then
- eval "$@";
-fi
-
check_mariadb_environment | tee -a $STARTUPLOG
display_container_mariadb_header | tee -a $STARTUPLOG
begin_config | tee -a $STARTUPLOG
-config_startserver | tee -a $STARTUPLOG
-config_createadmin | tee -a $STARTUPLOG
-config_createuser | tee -a $STARTUPLOG
-config_createdatabase | tee -a $STARTUPLOG
-config_importsql | tee -a $STARTUPLOG
-config_stopserver | tee -a $STARTUPLOG
end_config | tee -a $STARTUPLOG
-start_daemon
+start_service_mariadb