mirror of
https://github.com/openwrt/packages.git
synced 2026-04-15 10:51:55 +00:00
syncthing: validate syncthing config
Validate UCI config for syncthing service. Switch instance name to syncthing. Signed-off-by: George Sapkin <george@sapk.in>
This commit is contained in:
committed by
Hannu Nyman
parent
30199decfd
commit
af5999ce2a
@@ -2,7 +2,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=syncthing
|
||||
PKG_VERSION:=2.0.15
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE:=syncthing-source-v$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://github.com/syncthing/syncthing/releases/download/v$(PKG_VERSION)
|
||||
@@ -109,12 +109,11 @@ define SyncthingInstall
|
||||
$(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/$(2) $(1)/usr/bin
|
||||
endef
|
||||
|
||||
|
||||
define Package/syncthing/install
|
||||
$(call SyncthingInstall,$(1),syncthing)
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/sysctl.d/
|
||||
$(INSTALL_BIN) $(CURDIR)/files/syncthing-sysctl.conf $(1)/etc/sysctl.d/90-syncthing-inotify.conf
|
||||
$(INSTALL_CONF) $(CURDIR)/files/syncthing.sysctl $(1)/etc/sysctl.d/90-syncthing.conf
|
||||
endef
|
||||
|
||||
define Package/stdiscosrv/install
|
||||
|
||||
@@ -10,7 +10,7 @@ config syncthing 'syncthing'
|
||||
# Consult syslog if things go wrong.
|
||||
option home '/etc/syncthing'
|
||||
|
||||
# Changes to "niceness"/macprocs are not picked up by "reload_config" or by
|
||||
# Changes to "niceness"/maxprocs are not picked up by "reload_config" or by
|
||||
# "restart": the service has to be stopped/started for those to take effect.
|
||||
option nice '19'
|
||||
|
||||
@@ -21,6 +21,7 @@ config syncthing 'syncthing'
|
||||
|
||||
# Running as 'root' is possible, but not recommended
|
||||
# option user 'syncthing'
|
||||
# option group 'syncthing'
|
||||
|
||||
option log_file '/var/log/syncthing.log'
|
||||
# option log_level 'INFO'
|
||||
|
||||
@@ -5,68 +5,55 @@
|
||||
START=90
|
||||
STOP=10
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
PROG=/usr/bin/syncthing
|
||||
|
||||
config_cb() {
|
||||
[ $# -eq 0 ] && return
|
||||
|
||||
option_cb() {
|
||||
local option="$1"
|
||||
local value="$2"
|
||||
|
||||
case $option in
|
||||
|
||||
# Support old option names
|
||||
logfile)
|
||||
option='log_file'
|
||||
;;
|
||||
|
||||
macprocs)
|
||||
option='maxprocs'
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
eval $option="$value"
|
||||
}
|
||||
}
|
||||
USE_PROCD=1
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger 'syncthing'
|
||||
}
|
||||
|
||||
start_service() {
|
||||
# Options with default value different with the syncthing should be defined
|
||||
# explicitly here
|
||||
local enabled=0
|
||||
local db_delete_retention_interval=''
|
||||
local db_maintenance_interval=''
|
||||
local gc=0
|
||||
local gui_address='http://0.0.0.0:8384'
|
||||
local gui_apikey=''
|
||||
local home='/etc/syncthing'
|
||||
local log_file='/var/log/syncthing.log'
|
||||
local log_level='INFO'
|
||||
local log_max_old_files=7
|
||||
local log_max_size=1048576
|
||||
local maxprocs=0
|
||||
local memlimit=0
|
||||
local nice=0
|
||||
local user='syncthing'
|
||||
|
||||
config_load 'syncthing'
|
||||
|
||||
[ "$enabled" -gt 0 ] || return 0
|
||||
local config_name='syncthing'
|
||||
local enabled db_delete_retention_interval db_maintenance_interval \
|
||||
gui_address gui_apikey home log_file logfile log_level \
|
||||
log_max_old_files log_max_size nice user
|
||||
local gc maxprocs macprocs memlimit
|
||||
|
||||
local group=$(id -gn $user)
|
||||
uci_validate_section 'syncthing' 'syncthing' "$config_name" \
|
||||
'db_delete_retention_interval:string' \
|
||||
'db_maintenance_interval:string' \
|
||||
'enabled:bool:0' \
|
||||
'gc:uinteger:0' \
|
||||
'group:string:syncthing' \
|
||||
'gui_address:string:http://0.0.0.0:8384' \
|
||||
'gui_apikey:string' \
|
||||
'home:string:/etc/syncthing' \
|
||||
'log_file:string:/var/log/syncthing.log' \
|
||||
'logfile:string' \
|
||||
'log_level:or("DEBUG", "INFO", "WARN", "ERROR"):INFO' \
|
||||
'log_max_old_files:uinteger:7' \
|
||||
'log_max_size:uinteger:1048576' \
|
||||
'macprocs:uinteger' \
|
||||
'maxprocs:uinteger:0' \
|
||||
'memlimit:uinteger:0' \
|
||||
'nice:range(-20,19):0' \
|
||||
'user:string:syncthing'
|
||||
|
||||
[ "$enabled" = 1 ] || return 0
|
||||
|
||||
# Compatibility with older configs
|
||||
[ -n "$logfile" ] && log_file="$logfile"
|
||||
[ -n "$macprocs" ] && maxprocs="$macprocs"
|
||||
|
||||
[ -z "$group" ] && group=$(id -gn "$user")
|
||||
|
||||
mkdir -p "$home"
|
||||
# A separate step to handle an upgrade use case
|
||||
[ -d "$home" ] && chown -R $user:$group "$home"
|
||||
[ -d "$home" ] && chown -R "$user:$group" "$home"
|
||||
|
||||
procd_open_instance
|
||||
procd_open_instance syncthing
|
||||
|
||||
procd_set_param command "$PROG"
|
||||
|
||||
@@ -75,20 +62,21 @@ start_service() {
|
||||
[ "$memlimit" -le 0 ] || procd_append_param env GOMEMLIMIT="$memlimit"
|
||||
|
||||
procd_append_param command serve
|
||||
[ -z "$db_delete_retention_interval" ] || \
|
||||
procd_append_param command --db-delete-retention-interval="$db_delete_retention_interval"
|
||||
[ -z "$db_maintenance_interval" ] || \
|
||||
procd_append_param command --db-maintenance-interval="$db_maintenance_interval"
|
||||
[ -z "$db_delete_retention_interval" ] ||
|
||||
procd_append_param command \
|
||||
--db-delete-retention-interval="$db_delete_retention_interval"
|
||||
[ -z "$db_maintenance_interval" ] ||
|
||||
procd_append_param command \
|
||||
--db-maintenance-interval="$db_maintenance_interval"
|
||||
procd_append_param command --gui-address="$gui_address"
|
||||
[ -z "$gui_apikey" ] || \
|
||||
[ -z "$gui_apikey" ] ||
|
||||
procd_append_param command --gui_apikey="$gui_apikey"
|
||||
procd_append_param command --home="$home"
|
||||
procd_append_param command --log-file="$log_file"
|
||||
[ -z "$log_level" ] || \
|
||||
procd_append_param command --log-level="$log_level"
|
||||
[ -z "$log_max_old_files" ] || \
|
||||
[ -z "$log_level" ] || procd_append_param command --log-level="$log_level"
|
||||
[ -z "$log_max_old_files" ] ||
|
||||
procd_append_param command --log-max-old-files="$log_max_old_files"
|
||||
[ -z "$log_max_size" ] || \
|
||||
[ -z "$log_max_size" ] ||
|
||||
procd_append_param command --log-max-size="$log_max_size"
|
||||
procd_append_param command --no-browser
|
||||
procd_append_param command --no-port-probing
|
||||
|
||||
Reference in New Issue
Block a user