strongswan: Update to 5.9.9
[feed/packages.git] / net / frp / files / frps.init
1 #!/bin/sh /etc/rc.common
2
3 START=99
4 USE_PROCD=1
5
6 NAME=frps
7 PROG=/usr/bin/$NAME
8
9 _err() {
10 echo "$*" >&2
11 logger -p daemon.err -t "$NAME" "$*"
12 }
13
14 config_cb() {
15 [ $# -eq 0 ] && return
16
17 local type="$1"
18 local name="$2"
19 if [ "$type" = "conf" ]; then
20 echo "[$name]" >> "$conf_file"
21 option_cb() {
22 local option="$1"
23 local value="$2"
24 echo "$option = $value" >> "$conf_file"
25 }
26 list_cb() {
27 local name="$1"
28 local value="$2"
29 [ "$name" = "_" ] && echo "$value" >> "$conf_file"
30 }
31 else
32 [ "$type" = "init" ] && init_cfg="$name"
33 option_cb() { return 0; }
34 list_cb() { return 0; }
35 fi
36 }
37
38 service_triggers()
39 {
40 procd_add_reload_trigger "$NAME"
41 }
42
43 start_service() {
44 local init_cfg=" "
45 local conf_file="/var/etc/$NAME.ini"
46
47 > "$conf_file"
48 config_load "$NAME"
49
50 local stdout stderr user group respawn env conf_inc
51 uci_validate_section "$NAME" init "$init_cfg" \
52 'stdout:bool:1' \
53 'stderr:bool:1' \
54 'user:string' \
55 'group:string' \
56 'respawn:bool:1' \
57 'env:list(string)' \
58 'conf_inc:list(string)'
59
60 local err=$?
61 [ $err -ne 0 ] && {
62 _err "uci_validate_section returned $err"
63 return 1
64 }
65
66 [ -n "$conf_inc" ] && config_list_foreach "$init_cfg" conf_inc cat >> "$conf_file"
67
68 procd_open_instance
69 procd_set_param command "$PROG" -c "$conf_file"
70 procd_set_param stdout $stdout
71 procd_set_param stderr $stderr
72 [ -n "$user" ] && procd_set_param user "$user"
73 [ -n "$group" ] && procd_set_param group "$group"
74 [ $respawn -eq 1 ] && procd_set_param respawn
75 [ -n "$env" ] && config_list_foreach "$init_cfg" env "procd_append_param env"
76 procd_close_instance
77 }
78
79 reload_service() {
80 stop
81 start
82 }