packages/utils/rtty/files/rtty.init
Jeffery To 447d95a048 rtty: Update init script
This replaces the use of uci_validate_section() with
uci_load_validate(), which removes the need to declare local variables
for every config option.

This also adds a service_triggers() function.

Signed-off-by: Jeffery To <jeffery.to@gmail.com>
2019-02-12 14:34:38 +08:00

64 lines
1.3 KiB
Bash

#!/bin/sh /etc/rc.common
USE_PROCD=1
START=99
BIN=/usr/sbin/rtty
validate_rtty_section() {
uci_load_validate rtty rtty "$1" "$2" \
'interface:uci("network", "@interface"):lan' \
'id:maxlength(63)' \
'description:maxlength(126)' \
'host:host' \
'port:port' \
'ssl:bool:0' \
'keepalive:uinteger:5'
}
start_rtty() {
. /lib/functions/network.sh
local ifname
[ "$2" = 0 ] || {
echo "validation failed" >&2
return 1
}
[ -n "$interface" ] && network_get_device ifname "$interface"
[ -z "$ifname" -a -z "$id" ] && {
echo "You must specify an interface or ID" >&2
return 1
}
[ -z "$host" ] && {
echo "host required" >&2
return 1
}
[ -z "$port" ] && {
echo "port required" >&2
return 1
}
procd_open_instance
procd_set_param command $BIN -h $host -p $port -a -k $keepalive
[ -n "$ifname" ] && procd_append_param command -i "$ifname"
[ -n "$id" ] && procd_append_param command -I "$id"
[ -n "$description" ] && procd_append_param command -d "$description"
[ "$ssl" = "1" ] && procd_append_param command -s
procd_set_param respawn
procd_close_instance
}
start_service() {
config_load rtty
config_foreach validate_rtty_section rtty start_rtty
}
service_triggers() {
procd_add_reload_trigger "rtty"
procd_add_validation validate_rtty_section
}