aboutsummaryrefslogtreecommitdiff
path: root/net/frp/files/frps.init
diff options
context:
space:
mode:
authorRichard Yu <yurichard3839@gmail.com>2019-06-25 21:29:46 +0800
committerRichard Yu <yurichard3839@gmail.com>2019-06-26 17:26:51 +0800
commitaa3efeddbf0e86613626b3ef9c7f6415493c6da2 (patch)
tree06e2cd2584d26d473705b3b0b01ddec5c4544089 /net/frp/files/frps.init
parent400bf225c449434142149b4a9474a55aa8b14735 (diff)
frp: add uci config integration
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
Diffstat (limited to 'net/frp/files/frps.init')
-rw-r--r--net/frp/files/frps.init70
1 files changed, 63 insertions, 7 deletions
diff --git a/net/frp/files/frps.init b/net/frp/files/frps.init
index 0a804a380..be4e1b8fd 100644
--- a/net/frp/files/frps.init
+++ b/net/frp/files/frps.init
@@ -3,14 +3,70 @@
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
+}
+
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 /usr/bin/frps -c /etc/frp/frps.ini
- procd_set_param file /etc/frp/frps.ini
- procd_set_param stdout 1
- procd_set_param stderr 1
- procd_set_param user nobody
- procd_set_param group nogroup
- procd_set_param respawn
+ procd_set_param command "$PROG" -c "$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
}