Skip to content

Commit

Permalink
Link LibreSpeed with MySQL
Browse files Browse the repository at this point in the history
With workaround for librespeed/speedtest-go#12
  • Loading branch information
alexanderfefelov committed Oct 18, 2020
1 parent 8097274 commit bf62b1c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 12 deletions.
12 changes: 6 additions & 6 deletions librespeed/container/etc/librespeed/librespeed.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
20 changes: 20 additions & 0 deletions librespeed/init/initialize-database.sql
Original file line number Diff line number Diff line change
@@ -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'@'%';
1 change: 0 additions & 1 deletion librespeed/rm-v.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@
. settings.sh

docker volume rm $CONTAINER_NAME-conf
docker volume rm $CONTAINER_NAME-data
25 changes: 20 additions & 5 deletions librespeed/run.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,45 @@
#!/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 \
--hostname $HOST_NAME \
--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 \
$DEFAULT_LOG_SETTINGS \
$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
8 changes: 8 additions & 0 deletions librespeed/settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bf62b1c

Please sign in to comment.