syncthing: validate stdiscosrv config
authorGeorge Sapkin <redacted>
Fri, 13 Mar 2026 23:25:11 +0000 (01:25 +0200)
committerHannu Nyman <redacted>
Sat, 21 Mar 2026 13:49:07 +0000 (15:49 +0200)
Validate UCI config for stdiscosrv service.

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

Switch instance name to stdiscosrv.

Signed-off-by: George Sapkin <redacted>
utils/syncthing/files/stdiscosrv.conf
utils/syncthing/files/stdiscosrv.init

index 476d618cdb9f3ba90b9e2d947bcb1aaf9532f4a2..b1120abb80fbb7b3e951fc6e7ab3c6f0fd37a489 100644 (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'
index a4f4f986ee51ce551f71709707568dcda287e4b3..63d26c3e8ec62d3b28d32ce82355da45f940aff9 100644 (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 group=$(id -gn $user)
+       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
+
+       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"
git clone https://git.99rst.org/PROJECT