aboutsummaryrefslogtreecommitdiff
path: root/net/librespeed-go/files
diff options
context:
space:
mode:
authorTianling Shen <cnsztl@immortalwrt.org>2022-11-22 16:57:37 +0800
committerTianling Shen <cnsztl@gmail.com>2022-11-27 00:00:14 +0800
commita157e382df81ba1d40ba275730d7adf627508004 (patch)
tree78cd12993765f13a74e74826ad870dd1eea1ae46 /net/librespeed-go/files
parent46e4def61f6b670daac1725df8f3fc4475fe5450 (diff)
librespeed-go: add new package
Go backend for LibreSpeed. Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
Diffstat (limited to 'net/librespeed-go/files')
-rw-r--r--net/librespeed-go/files/librespeed-go.config47
-rw-r--r--net/librespeed-go/files/librespeed-go.init80
2 files changed, 127 insertions, 0 deletions
diff --git a/net/librespeed-go/files/librespeed-go.config b/net/librespeed-go/files/librespeed-go.config
new file mode 100644
index 000000000..e43dc912a
--- /dev/null
+++ b/net/librespeed-go/files/librespeed-go.config
@@ -0,0 +1,47 @@
+
+config librespeed-go 'config'
+ option enabled '0'
+
+ # bind address, use empty string to bind to all interfaces
+ option bind_address ''
+ # backend listen port
+ option listen_port '8989'
+
+ # change the base URL
+ # option url_base '/librespeed'
+ # proxy protocol port, use 0 to disable
+ option proxyprotocol_port '0'
+ # Server location, use zeroes to fetch from API automatically
+ option server_lat '0'
+ option server_lng '0'
+ # ipinfo.io API key, if applicable
+ option ipinfo_api_key ''
+
+ # assets directory path, defaults to `assets` in the same directory
+ # if the path cannot be found, embedded default assets will be used
+ option assets_path ''
+
+ # password for logging into statistics page, change this to enable stats page
+ # option statistics_password 'PASSWORD'
+ # redact IP addresses (boolean)
+ option redact_ip_addresses '0'
+
+ # database type for statistics data, currently supports: none, memory, bolt, mysql, postgresql
+ # if none is specified, no telemetry/stats will be recorded, and no result PNG will be generated
+ option database_type 'none'
+ # option database_hostname ''
+ # option database_name ''
+ # option database_username ''
+ # option database_password ''
+
+ # if you use `bolt` as database, set database_file to database file location
+ # option database_file '/etc/librespeed-go/speedtest.db'
+
+ # TLS and HTTP/2 settings. TLS is required for HTTP/2 (boolean)
+ option enable_tls '0'
+ option enable_http2 '0'
+
+ # if you use HTTP/2 or TLS, you need to prepare certificates and private keys
+ # option tls_cert_file '/etc/librespeed-go/cert.pem'
+ # option tls_key_file '/etc/librespeed-go/privkey.pem'
+
diff --git a/net/librespeed-go/files/librespeed-go.init b/net/librespeed-go/files/librespeed-go.init
new file mode 100644
index 000000000..484a283db
--- /dev/null
+++ b/net/librespeed-go/files/librespeed-go.init
@@ -0,0 +1,80 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2022 Tianling Shen <cnsztl@immortalwrt.org>
+
+USE_PROCD=1
+START=99
+
+CONF="librespeed-go"
+PROG="/usr/bin/librespeed-go"
+TMPCONF="/var/run/$CONF/settings.json"
+
+start_service() {
+ config_load "$CONF"
+
+ local enabled
+ config_get_bool enabled "config" "enabled" "0"
+ [ "$enabled" -eq "1" ] || return 1
+
+ mkdir -p "${TMPCONF%/*}"
+
+ json_init
+ option_cb() {
+ local name="$1"
+ local value="$2"
+
+ case "$name" in
+ "enabled") ;;
+ "enable_tls"|"enable_http2"|"redact_ip_addresses")
+ json_add_boolean "$name" "$value" ;;
+ *)
+ json_add_string "$name" "$value" ;;
+ esac
+ }
+ config_load "$CONF"
+ json_dump > "$TMPCONF"
+
+ local database_file
+ config_get database_file "config" "database_file"
+ if [ -n "$database_file" ]; then
+ mkdir -p "${database_file%/*}"
+ touch "$database_file"
+ chown librespeed "$database_file"
+ fi
+
+ procd_open_instance "$CONF"
+ procd_set_param command "$PROG"
+ procd_append_param command -c "$TMPCONF"
+
+ procd_set_param limits core="unlimited"
+ procd_set_param limits nofile="1000000 1000000"
+ procd_set_param respawn
+ procd_set_param stderr 1
+ procd_set_param user librespeed
+
+ procd_add_jail "$CONF" log
+ procd_add_jail_mount "$TMPCONF"
+ [ -z "$database_file" ] || procd_add_jail_mount_rw "$database_file"
+
+ local assets_path tls_cert_file tls_key_file
+ config_get assets_path "config" "assets_path"
+ config_get tls_cert_file "config" "tls_cert_file"
+ config_get tls_key_file "config" "tls_key_file"
+ [ -z "$assets_path" ] || procd_add_jail_mount "$assets_path"
+ [ -z "$tls_cert_file" ] || procd_add_jail_mount "$tls_cert_file"
+ [ -z "$tls_key_file" ] || procd_add_jail_mount "$tls_key_file"
+
+ procd_close_instance
+}
+
+stop_service() {
+ rm -rf "${TMPCONF%/*}"
+}
+
+reload_service() {
+ stop
+ start
+}
+
+service_triggers() {
+ procd_add_reload_trigger "$CONF"
+}