08f829e optimize the init script 92c1e67 add init scripts git-subtree-dir: fakehttp git-subtree-split: 08f829e96534891b8ab9aef4141256a47c2e69c2
106 lines
2.5 KiB
Bash
106 lines
2.5 KiB
Bash
#!/bin/sh /etc/rc.common
|
|
|
|
USE_PROCD=1
|
|
START=99
|
|
STOP=01
|
|
|
|
PROG="/usr/sbin/fakehttp"
|
|
NAME="fakehttp"
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger "${NAME}"
|
|
}
|
|
|
|
add_interface() {
|
|
local ifname="$1"
|
|
|
|
procd_append_param command "-i" "${ifname}"
|
|
procd_append_param netdev "${ifname}"
|
|
}
|
|
|
|
add_payload() {
|
|
local section="$1"
|
|
|
|
local type
|
|
config_get type "${section}" "type" ""
|
|
|
|
case "${type}" in
|
|
"h")
|
|
local hostname
|
|
config_get hostname "${section}" "hostname" ""
|
|
procd_append_param command "-h" "${hostname}"
|
|
;;
|
|
"e")
|
|
local hostname
|
|
config_get hostname "${section}" "hostname" ""
|
|
procd_append_param command "-e" "${hostname}"
|
|
;;
|
|
"b")
|
|
local file
|
|
config_get file "${section}" "file" ""
|
|
procd_append_param command "-b" "${file}"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
test_bool_then_append() {
|
|
local section="$1"
|
|
local config_option="$2"
|
|
local command_option="$3"
|
|
|
|
local tmp
|
|
config_get_bool tmp "${section}" "${config_option}" "0"
|
|
[ "${tmp}" -eq "1" ] && procd_append_param command "${command_option}"
|
|
}
|
|
|
|
test_number_then_append() {
|
|
local section="$1"
|
|
local config_option="$2"
|
|
local command_option="$3"
|
|
|
|
local tmp
|
|
config_get tmp "${section}" "${config_option}" "-1"
|
|
[ "${tmp}" -gt "0" ] && procd_append_param command "${command_option}" "${tmp}"
|
|
}
|
|
|
|
add_advanced() {
|
|
test_bool_then_append "advanced" "skip" "-f"
|
|
test_bool_then_append "advanced" "disable_estimation" "-g"
|
|
test_number_then_append "advanced" "pct" "-y"
|
|
test_number_then_append "advanced" "fwmark_bypassing" "-m"
|
|
test_number_then_append "advanced" "fwmark_handle" "-x"
|
|
test_number_then_append "advanced" "queue_number" "-n"
|
|
test_number_then_append "advanced" "repeat" "-r"
|
|
test_number_then_append "advanced" "ttl" "-t"
|
|
test_bool_then_append "advanced" "use_iptables" "-z"
|
|
}
|
|
|
|
fakehttp_instance() {
|
|
config_load "${NAME}"
|
|
|
|
local enabled
|
|
config_get_bool enabled "globals" "enabled" "0"
|
|
[ "${enabled}" -eq "1" ] || return 0
|
|
|
|
procd_open_instance
|
|
procd_set_param command "${PROG}"
|
|
config_list_foreach "globals" "interface" add_interface
|
|
test_bool_then_append "globals" "silent" "-s"
|
|
config_foreach add_payload "payload"
|
|
add_advanced
|
|
|
|
procd_set_param stdout 1
|
|
procd_set_param stderr 1
|
|
procd_set_param respawn
|
|
|
|
procd_close_instance
|
|
}
|
|
|
|
start_service() {
|
|
fakehttp_instance
|
|
}
|
|
|
|
reload_service() {
|
|
stop
|
|
start
|
|
} |