diff --git a/librespeed/container/etc/librespeed/librespeed.toml b/librespeed/container/etc/librespeed/librespeed.toml index a7d36f78..3a1d0c65 100644 --- a/librespeed/container/etc/librespeed/librespeed.toml +++ b/librespeed/container/etc/librespeed/librespeed.toml @@ -19,11 +19,11 @@ statistics_password = "eichacheakie" redact_ip_addresses = false # database type for statistics data, currently supports: bolt, mysql, postgresql -database_type = "bolt" -database_hostname = "" -database_name = "" -database_username = "" -database_password = "" +database_type = "mysql" +database_hostname = "tcp(mysql-main-master.backpack.test:3306)" +database_name = "librespeed" +database_username = "librespeed_gohsotahleit" +database_password = "thuchusohgie" # if you use `bolt` as database, set database_file to database file location -database_file = "/var/lib/librespeed/speedtest.db" +database_file = "" diff --git a/librespeed/init/initialize-database.sql b/librespeed/init/initialize-database.sql new file mode 100644 index 00000000..607429f9 --- /dev/null +++ b/librespeed/init/initialize-database.sql @@ -0,0 +1,20 @@ +CREATE DATABASE $DB_DATABASE; +USE $DB_DATABASE; +CREATE TABLE speedtest_users( -- https://github.com/librespeed/speedtest-go/blob/master/database/mysql/telemetry_mysql.sql + id int(11) NOT NULL AUTO_INCREMENT, + timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + ip text NOT NULL, + ispinfo text, + extra text, + ua text NOT NULL, + lang text NOT NULL, + dl text, + ul text, + ping text, + jitter text, + log longtext, + uuid text, + PRIMARY KEY (id) +); +CREATE USER IF NOT EXISTS '$DB_USERNAME'@'%' IDENTIFIED WITH mysql_native_password BY '$DB_PASSWORD'; +GRANT INSERT, SELECT ON $DB_DATABASE.speedtest_users TO '$DB_USERNAME'@'%'; diff --git a/librespeed/rm-v.sh b/librespeed/rm-v.sh index d99678af..51dfb18f 100755 --- a/librespeed/rm-v.sh +++ b/librespeed/rm-v.sh @@ -6,4 +6,3 @@ . settings.sh docker volume rm $CONTAINER_NAME-conf -docker volume rm $CONTAINER_NAME-data diff --git a/librespeed/run.sh b/librespeed/run.sh index 0a4f9759..f3f24062 100755 --- a/librespeed/run.sh +++ b/librespeed/run.sh @@ -1,15 +1,20 @@ #!/usr/bin/env bash -# Exit immediately if a pipeline, which may consist of a single simple command, -# a list, or a compound command returns a non-zero status -set -e - # Elevate privileges [ $UID -eq 0 ] || exec sudo bash "$0" "$@" . settings.sh . ../lib/lib.sh +readonly MYSQL="mysql --host=$DB_HOST --port=$DB_PORT --user=$DB_ROOT_USERNAME --password=$DB_ROOT_PASSWORD" + +initialize_database() { + echo Initializing database... + export DB_DATABASE DB_USERNAME DB_PASSWORD + $MYSQL <<< "$(envsubst < init/initialize-database.sql)" + echo ...database initialized +} + run() { docker run \ --name $CONTAINER_NAME \ @@ -17,7 +22,6 @@ run() { --detach \ --volume /etc/localtime:/etc/localtime:ro --volume /etc/timezone:/etc/timezone:ro \ --volume $CONTAINER_NAME-conf:/etc/librespeed \ - --volume $CONTAINER_NAME-data:/var/lib/librespeed \ --publish 8989:8989 \ $DEFAULT_GO_SETTINGS \ $DEFAULT_HEALTH_SETTINGS \ @@ -25,6 +29,17 @@ run() { $IMAGE_NAME } +$MYSQL --execute="USE $DB_DATABASE;" +readonly USE_DB_RETCODE=$? + +# Exit immediately if a pipeline, which may consist of a single simple command, +# a list, or a compound command returns a non-zero status +set -e + +if [ "$USE_DB_RETCODE" -ne 0 ]; then + initialize_database +fi + run wait_for_all_container_ports $CONTAINER_NAME $WAIT_TIMEOUT print_container_info $CONTAINER_NAME diff --git a/librespeed/settings.sh b/librespeed/settings.sh index e8a28390..075463c9 100644 --- a/librespeed/settings.sh +++ b/librespeed/settings.sh @@ -5,6 +5,14 @@ readonly CONTAINER_NAME=$BASE_NAME readonly HOST_NAME=$MONIKER.backpack.test readonly WAIT_TIMEOUT=600 +readonly DB_HOST=mysql-main-master.backpack.test +readonly DB_PORT=3306 +readonly DB_DATABASE=librespeed +readonly DB_ROOT_USERNAME=root +readonly DB_ROOT_PASSWORD=camycorymicu +readonly DB_USERNAME=librespeed_gohsotahleit +readonly DB_PASSWORD=thuchusohgie + . ../lib/settings/go.sh . ../lib/settings/health.sh . ../lib/settings/log.sh