Update to 0.1.1 and add an init script

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët
2019-04-03 13:21:42 +00:00
parent 880f914256
commit 70a12e18b6
2 changed files with 85 additions and 17 deletions

56
glorytun/init Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/sh /etc/rc.common
START=90
STOP=10
USE_PROCD=1
PROG_NAME=glorytun
PROG=/usr/sbin/$PROG_NAME
validate_section() {
uci_validate_section $PROG_NAME $PROG_NAME "$1" \
'enable:bool:0' \
'key:string' \
'server:host' \
'port:port' \
'dev:string'
}
start_instance() {
local enable key server port dev
validate_section "$1" || return
[ "$enable" = "1" ] || return 0
[ "$key" ] || return
[ "$server" ] || return
[ "$port" ] || return
keyfile="/tmp/$PROG_NAME.key"
( umask 077; echo "$key" > "$keyfile" )
key=""
procd_open_instance
procd_set_param command $PROG \
bind "0.0.0.0" "$port" \
to "$server" "$port" \
keyfile "$keyfile" \
${dev:+dev "$dev"}
procd_set_param respawn 0 30 0
procd_set_param file "$keyfile"
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
}
start_service() {
config_load glorytun
config_foreach start_instance mud
}
service_triggers() {
procd_add_reload_trigger glorytun
}