mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-02-15 03:51:51 +00:00
84 lines
2.2 KiB
Bash
Executable file
84 lines
2.2 KiB
Bash
Executable file
#!/bin/sh /etc/rc.common
|
|
# shellcheck disable=SC2039
|
|
# vim: set noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 :
|
|
|
|
# shellcheck disable=SC2034
|
|
{
|
|
START=90
|
|
STOP=10
|
|
USE_PROCD=1
|
|
}
|
|
|
|
_validate_section() {
|
|
local tmp_hosts=$hosts tmp_timeout=$timeout tmp_tries=$tries
|
|
local tmp_interval=$interval tmp_options=$options tmp_type=$type tmp_enabled=$enabled
|
|
|
|
uci_validate_section omr-tracker "$1" "$2" \
|
|
'hosts:list(host)' \
|
|
'timeout:uinteger' \
|
|
'tries:uinteger' \
|
|
'interval:uinteger' \
|
|
'type:string' \
|
|
'enabled:bool:1' \
|
|
'options:string'
|
|
|
|
[ -z "$hosts" ] && hosts=$tmp_hosts
|
|
[ -z "$timeout" ] && timeout=$tmp_timeout
|
|
[ -z "$tries" ] && tries=$tmp_tries
|
|
[ -z "$interval" ] && interval=$tmp_interval
|
|
[ -z "$options" ] && options=$tmp_options
|
|
[ -z "$type" ] && type=$tmp_type
|
|
[ -z "$enabled" ] && enabled=$tmp_enabled
|
|
}
|
|
|
|
_launch_tracker() {
|
|
case "$1" in
|
|
loopback|lan*|if0*|tun*) return;;
|
|
esac
|
|
|
|
local interface_type
|
|
config_get interface_type "$1" type
|
|
|
|
local hosts timeout tries interval options type
|
|
_validate_section "defaults" "defaults"
|
|
_validate_section "interface" "$1"
|
|
|
|
local ifname ip4table
|
|
config_get ifname "$1" ifname
|
|
config_get multipath "$1" multipath
|
|
config_get gateway "$1" gateway
|
|
|
|
[ -z "$ifname" ] || [ -z "$multipath" ] || [ "$multipath" = "off" ] && [ "$1" != "glorytun" ] && return
|
|
[ $enabled = 0 ] && return
|
|
[ -z "$type" ] && type="ping"
|
|
|
|
procd_open_instance
|
|
# shellcheck disable=SC2086
|
|
procd_set_param command /bin/omr-tracker "$1" $options
|
|
procd_append_param env "OMR_TRACKER_HOSTS=$hosts"
|
|
procd_append_param env "OMR_TRACKER_TIMEOUT=$timeout"
|
|
procd_append_param env "OMR_TRACKER_TRIES=$tries"
|
|
procd_append_param env "OMR_TRACKER_INTERVAL=$interval"
|
|
procd_append_param env "OMR_TRACKER_TABLE=$ip4table"
|
|
procd_append_param env "OMR_TRACKER_DEVICE=$ifname"
|
|
procd_append_param env "OMR_TRACKER_DEVICE_GATEWAY=$gateway"
|
|
procd_append_param env "OMR_TRACKER_TYPE=$type"
|
|
procd_set_param limits nofile="51200 51200"
|
|
procd_set_param respawn 0 10 0
|
|
procd_set_param stderr 1
|
|
procd_close_instance
|
|
}
|
|
|
|
start_service() {
|
|
config_load network
|
|
config_foreach _launch_tracker interface
|
|
}
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger omr-tracker network
|
|
}
|
|
|
|
reload_service() {
|
|
stop
|
|
start
|
|
}
|