1
0
mirror of https://git.openwrt.org/feed/packages.git synced 2024-06-17 21:03:56 +02:00
openwrt-packages/net/frp/files/frps.init
Van Waholtz 8fcc48c339 frp: update to 0.47.0
A restart is only required if `$conf_file` has been modified.

Signed-off-by: Van Waholtz <brvphoenix@gmail.com>
2023-03-09 10:41:17 +08:00

79 lines
1.6 KiB
Bash

#!/bin/sh /etc/rc.common
START=99
USE_PROCD=1
NAME=frps
PROG=/usr/bin/$NAME
_err() {
echo "$*" >&2
logger -p daemon.err -t "$NAME" "$*"
}
config_cb() {
[ $# -eq 0 ] && return
local type="$1"
local name="$2"
if [ "$type" = "conf" ]; then
echo "[$name]" >> "$conf_file"
option_cb() {
local option="$1"
local value="$2"
echo "$option = $value" >> "$conf_file"
}
list_cb() {
local name="$1"
local value="$2"
[ "$name" = "_" ] && echo "$value" >> "$conf_file"
}
else
[ "$type" = "init" ] && init_cfg="$name"
option_cb() { return 0; }
list_cb() { return 0; }
fi
}
service_triggers()
{
procd_add_reload_trigger "$NAME"
}
start_service() {
local init_cfg=" "
local conf_file="/var/etc/$NAME.ini"
> "$conf_file"
config_load "$NAME"
local stdout stderr user group respawn env conf_inc
uci_validate_section "$NAME" init "$init_cfg" \
'stdout:bool:1' \
'stderr:bool:1' \
'user:string' \
'group:string' \
'respawn:bool:1' \
'env:list(string)' \
'conf_inc:list(string)'
local err=$?
[ $err -ne 0 ] && {
_err "uci_validate_section returned $err"
return 1
}
[ -n "$conf_inc" ] && config_list_foreach "$init_cfg" conf_inc cat >> "$conf_file"
procd_open_instance
procd_set_param command "$PROG" -c "$conf_file"
procd_set_param file $conf_file
procd_set_param stdout $stdout
procd_set_param stderr $stderr
[ -n "$user" ] && procd_set_param user "$user"
[ -n "$group" ] && procd_set_param group "$group"
[ $respawn -eq 1 ] && procd_set_param respawn
[ -n "$env" ] && config_list_foreach "$init_cfg" env "procd_append_param env"
procd_close_instance
}