# 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'
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
[ -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