syncthing: improve discovery argument parsing
authorGeorge Sapkin <[email protected]>
Wed, 6 Aug 2025 19:41:53 +0000 (22:41 +0300)
committerHannu Nyman <[email protected]>
Sun, 24 Aug 2025 16:43:57 +0000 (19:43 +0300)
Fixes: 47644ba46 ("syncthing: fix discovery and relay extra args")
Signed-off-by: George Sapkin <[email protected]>
utils/syncthing/files/stdiscosrv.conf
utils/syncthing/files/stdiscosrv.init

index 3e0401451388b3dc380c4dee7f704d864d1c3298..5606c5f25219385208a5b4b31e50498142e9203a 100644 (file)
@@ -7,11 +7,13 @@ config stdiscosrv 'stdiscosrv'
        # Find the documents from: https://docs.syncthing.net/users/stdiscosrv.html
        # option cert '/etc/stdiscosrv/cert.pem'
        # option key '/etc/stdiscosrv/key.pem'
-       # option db_flush_interval '5m'
+       # option db_flush_interval '5m'
        # option metrics_listen ''
 
-       # CLI options with no value should be defined as booleans and theirs names
-       # should be prefixed with '_'.
-       # option _compression '0'
-       # option _debug '0'
-       # option _http '1'
+       # Running as 'root' is possible, but not recommended
+       # option user 'syncthing'
+
+       # CLI options with no value should be defined as booleans
+       # option compression '0'
+       # option debug '0'
+       # option http '1'
index 7ad243a202f39511520eaf4e5d9a647d86ffa8e6..bc1da536a5187719b12dd20d4975fd8a4a34396e 100644 (file)
@@ -13,43 +13,36 @@ config_cb() {
        option_cb() {
                local option="$1"
                local value="$2"
-               case $option in
-               enabled|listen|cert|db_dir|key)
-                       eval $option=$value
-                       ;;
-               _*)
-                       [ "$value" = "0" ] || extra_args="$extra_args -${option//_/-}"
-                       ;;
-               *)
-                       extra_args="$extra_args --${option//_/-}='$value'"
-                       ;;
-               esac
-       }
-
-       list_cb() {
-               local name="$1"
-               local value="$2"
-               [ "$name" = "_" ] && extra_args="$extra_args --${value//_/-}" || return 0
+               # Remove the leading underscore from the option name for backward
+               # compatibility
+               option="${option#_}"
+               eval $option="$value"
        }
 }
 
 service_triggers() {
-       procd_add_reload_trigger "stdiscosrv"
+       procd_add_reload_trigger 'stdiscosrv'
 }
 
 start_service() {
-       local extra_args
-       # Options with default value different with the syncthing should be defined explicitly here
+       local conf_dir='/etc/stdiscosrv'
+
+       # Options with default value different with the syncthing should be defined
+       # explicitly here
        local enabled=0
-       local listen=":8443"
-       local conf_dir="/etc/stdiscosrv"
+       local compression=0
        local cert="$conf_dir/cert.pem"
-       local key="$conf_dir/key.pem"
        local db_dir="$conf_dir/discovery.db"
+       local db_flush_interval=''
+       local debug=0
+       local http=0
+       local key="$conf_dir/key.pem"
+       local listen=':8443'
+       local metrics_listen=''
        local nice=0
-       local user="syncthing"
+       local user='syncthing'
 
-       config_load "stdiscosrv"
+       config_load 'stdiscosrv'
 
        [ "$enabled" -gt 0 ] || return 0
 
@@ -58,19 +51,22 @@ start_service() {
        [ -d "$db_dir" ] || mkdir -p "$db_dir"
        [ -d "$conf_dir" ] && chown -R "$user":"$group" "$conf_dir"
 
-       config_get nice stdiscosrv nice "0"
-
        procd_open_instance
        procd_set_param command "$PROG"
-       procd_append_param command --listen="$listen"
-       procd_append_param command --db-dir="$db_dir"
        procd_append_param command --cert="$cert"
+       [ "$compression" -eq 0 ] || procd_append_param command --compression
+       procd_append_param command --db-dir="$db_dir"
+       [ -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
        procd_append_param command --key="$key"
-       [ -z "$extra_args" ] || procd_append_param command "$extra_args"
+       procd_append_param command --listen="$listen"
+       [ -z "$metrics_listen" ] || procd_append_param command --metrics-listen="$metrics_listen"
 
        procd_set_param nice "$nice"
        procd_set_param term_timeout 15
        procd_set_param user "$user"
+       procd_set_param group "$group"
        procd_set_param respawn
        procd_set_param stdout 1
        procd_set_param stderr 1