syncthing: validate stdiscosrv config

Validate UCI config for stdiscosrv service.

Change default DB directory to /etc/stdiscosrv/db.

Switch instance name to stdiscosrv.

Signed-off-by: George Sapkin <george@sapk.in>
(cherry picked from commit d26083edf8)
This commit is contained in:
George Sapkin committed 2026-04-20 04:22:34 +03:00
1 parent 18de8ab656
commit ed1966292a
2 files changed
+35 -48

No files matched your search

+2 -1
View File
@@ -2,7 +2,7 @@
config stdiscosrv 'stdiscosrv'
option enabled '0'
option listen ':8443'
option db_dir '/etc/stdiscosrv/discovery.db'
option db_dir '/etc/stdiscosrv/db'
# More info: https://docs.syncthing.net/users/stdiscosrv.html
# option cert '/etc/stdiscosrv/cert.pem'
@@ -12,6 +12,7 @@ config stdiscosrv 'stdiscosrv'
# Running as 'root' is possible, but not recommended
# option user 'syncthing'
# option group 'syncthing'
# CLI options with no value should be defined as booleans
# option compression '0'
+33 -47
View File
@@ -5,58 +5,47 @@
START=90
STOP=10
USE_PROCD=1
PROG=/usr/bin/stdiscosrv
config_cb() {
[ $# -eq 0 ] && return
option_cb() {
local option="$1"
local value="$2"
# Remove the leading underscore from the option name for backward
# compatibility
option="${option#_}"
eval $option="$value"
}
}
USE_PROCD=1
service_triggers() {
procd_add_reload_trigger 'stdiscosrv'
}
start_service() {
local conf_dir='/etc/stdiscosrv'
# Options with default value different with the syncthing should be defined
# explicitly here
local enabled=0
local compression=0
local cert="$conf_dir/cert.pem"
local db_dir="$conf_dir/discovery.db"
local db_flush_interval=''
local debug=0
local gc=0
local http=0
local key="$conf_dir/key.pem"
local listen=':8443'
local maxprocs=0
local memlimit=0
local metrics_listen=''
local nice=0
local user='syncthing'
config_load 'stdiscosrv'
[ "$enabled" -gt 0 ] || return 0
local config_name='stdiscosrv'
local enabled compression cert db_dir db_flush_interval debug http key \
listen metrics_listen nice user
local gc maxprocs memlimit
local group=$(id -gn $user)
uci_validate_section 'stdiscosrv' 'stdiscosrv' "$config_name" \
'compression:bool:0' \
'cert:string:/etc/stdiscosrv/cert.pem' \
'db_dir:string:/etc/stdiscosrv/db' \
'db_flush_interval:string' \
'debug:bool:0' \
'enabled:bool:0' \
'gc:uinteger:0' \
'group:string:syncthing' \
'http:bool:0' \
'key:string:/etc/stdiscosrv/key.pem' \
'listen:string::8443' \
'maxprocs:uinteger:0' \
'memlimit:uinteger:0' \
'metrics_listen:string' \
'nice:range(-20,19):0' \
'user:string:syncthing'
[ "$enabled" = 1 ] || return 0
[ -z "$group" ] && group=$(id -gn "$user")
mkdir -p "$db_dir"
[ -d "$conf_dir" ] && chown -R "$user":"$group" "$conf_dir"
[ -d "$db_dir" ] && chown -R "$user:$group" "$db_dir"
procd_open_instance
procd_open_instance stdiscosrv
procd_set_param command "$PROG"
@@ -65,18 +54,15 @@ start_service() {
[ "$memlimit" -le 0 ] || procd_append_param env GOMEMLIMIT="$memlimit"
procd_append_param command --cert="$cert"
[ "$compression" -eq 0 ] || \
procd_append_param command --compression
[ "$compression" -eq 0 ] || procd_append_param command --compression
procd_append_param command --db-dir="$db_dir"
[ -z "$db_flush_interval" ] || \
[ -z "$db_flush_interval" ] ||
procd_append_param command --db-flush-interval="$db_flush_interval"
[ "$debug" -eq 0 ] || \
procd_append_param command --debug
[ "$http" -eq 0 ] || \
procd_append_param command --http
[ "$debug" -eq 0 ] || procd_append_param command --debug
[ "$http" -eq 0 ] || procd_append_param command --http
procd_append_param command --key="$key"
procd_append_param command --listen="$listen"
[ -z "$metrics_listen" ] || \
[ -z "$metrics_listen" ] ||
procd_append_param command --metrics-listen="$metrics_listen"
procd_set_param nice "$nice"