diff --git a/stunc/Makefile b/stunc/Makefile index 8f056c04b..7c7c36cd4 100755 --- a/stunc/Makefile +++ b/stunc/Makefile @@ -8,9 +8,9 @@ include $(TOPDIR)/rules.mk PKG_NAME:=stunc -PKG_VERSION:=1.0.0 +PKG_VERSION:=1.0.1 -PKG_SOURCE_VERSION:=74c8205a45a69572d0c6a2615e87c019c15f8972 +PKG_SOURCE_VERSION:=cd7c5d70bc97a2f1a26d5587ccf6f4c1e9ca82c8 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/stunc.git @@ -41,8 +41,11 @@ TARGET_CFLAGS += \ define Package/$(PKG_NAME)/install $(INSTALL_DIR) $(1)/usr/sbin - $(INSTALL_BIN) $(PKG_BUILD_DIR)/stund $(1)/usr/sbin/ - $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) $(PKG_BUILD_DIR)/stunc $(1)/usr/sbin/ + $(INSTALL_BIN) ./files/etc/init.d/stunc $(1)/etc/init.d/stunc + $(INSTALL_DATA) ./files/etc/config/stun $(1)/etc/config/stun endef $(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/stunc/files/etc/config/stun b/stunc/files/etc/config/stun index d006a43b4..3c8689c53 100644 --- a/stunc/files/etc/config/stun +++ b/stunc/files/etc/config/stun @@ -8,7 +8,5 @@ config stun 'stun' option min_keepalive '30' option max_keepalive '3600' # option client_port 7547 -#if client_port option is not set or < 0 then use a random port for connection request source port -#Log levels: Critical=0, Warning=1, Notice=2, Info=3, Debug=4 - option log_level '3' + option log_level '0' diff --git a/stunc/files/etc/init.d/stunc b/stunc/files/etc/init.d/stunc new file mode 100755 index 000000000..db3794da8 --- /dev/null +++ b/stunc/files/etc/init.d/stunc @@ -0,0 +1,67 @@ +#!/bin/sh /etc/rc.common +# STUN client software +# Copyright (C) 2020 iopsys Software Solutions AB +# Author: Omar Kallel + +START=90 + +USE_PROCD=1 +PROG="/usr/sbin/stunc" + + +log() { + #echo "${@}" >/dev/console + echo "${@}"|logger -t stun -p info +} + +validate_stun_section() +{ + uci_validate_section stun stun stun \ + 'enable:bool' \ + 'Username:string' \ + 'Password:string' \ + 'server_address:host' \ + 'server_port:port' \ + 'client_port:port' \ + 'log_level:uinteger:0' +} + +service_running() { + ubus wait_for tr069 + return $?; +} + +start_service() { + local enable server_address + + config_load stun + validate_stun_section || { + log "Validation failed for stun section"; + exit 1; + } + + if [ "$enable" -eq 0 ]; then + exit 0; + fi + + if [ -z "${server_address}" ]; then + log "Stun server address not defined or invalid" + exit 0; + fi + + procd_open_instance stun + procd_set_param command "$PROG" + procd_set_param respawn "3" "7" "0" + procd_close_instance + +} + +reload_service() { + stop + start +} + +service_triggers() +{ + procd_add_reload_trigger stun +} diff --git a/stunc/files/etc/init.d/stund b/stunc/files/etc/init.d/stund deleted file mode 100755 index 264a461ad..000000000 --- a/stunc/files/etc/init.d/stund +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/sh /etc/rc.common -# STUN client software -# Copyright (C) 2020 iopsys Software Solutions AB -# Author: Omar Kallel - -START=90 - -USE_PROCD=1 -PROG="/usr/sbin/stund" - -start_service() { - local enable=`uci -q get stun.stun.enable` - if [ "$enable" == "1" ]; then - local server=`uci -q get stun.stun.server_address` - [ "$server" = "" ] && exit 0 - procd_open_instance - procd_set_param command "$PROG" - procd_set_param respawn "3" "7" "0" - procd_close_instance - fi -} - -boot() { - start -} - -reload_service() { - logger -p crit -t "stun" "reloading service()" - stop - start -} - -service_triggers() -{ - procd_add_reload_trigger stun -}