net/u2pnpd: convert init to procd

Drops pid files, no longer needed with procd management.
Now properly reloads on reload_config after UCI changes.

Signed-off-by: Karl Palsson <karlp@etactica.com>

[ Fixed two shellcheck warnings and bump PKG_RELEASE ]
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
This commit is contained in:
Karl Palsson 2020-08-20 11:40:28 +00:00 committed by Michael Heimpold
parent 95362efd29
commit 75992cc981
2 changed files with 33 additions and 46 deletions

View File

@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=u2pnpd PKG_NAME:=u2pnpd
PKG_VERSION:=0.5 PKG_VERSION:=0.5
PKG_RELEASE:=2 PKG_RELEASE:=3
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://github.com/mhei/u2pnpd/releases/download/v$(PKG_VERSION) PKG_SOURCE_URL:=https://github.com/mhei/u2pnpd/releases/download/v$(PKG_VERSION)

View File

@ -3,60 +3,47 @@
START=50 START=50
STOP=20 STOP=20
USE_PROCD=1
SERVICE_DAEMONIZE=1 append_arg() {
SERVICE_PID_FILE=/var/run/u2pnpd.pid local cfg="$1"
SERVICE_USE_PID=1 local opt="$2"
SERVICE_WRITE_PID=1 local var="$3"
local def="$4"
local val
config_get val "$cfg" "$var"
[ -n "$val" ] || [ -n "$def" ] && procd_append_param command "$opt" "${val:-$def}"
}
start_instance() { start_instance() {
local section="$1" local cfg="$1"
local enabled local enabled
local interface manufacturer manufacturerURL modelDescription
local modelName modelNumber modelURL serialNumber friendlyName
local uuid httpsURL
local i
config_get_bool enabled "$section" 'enabled' 1 config_get_bool enabled "$cfg" 'enabled' 1
[ "$enabled" -gt 0 ] || return 0 [ "$enabled" -gt 0 ] || return 0
for i in interface httpsURL manufacturer manufacturerURL modelDescription \ procd_open_instance
modelName modelNumber modelURL serialNumber friendlyName uuid; do procd_set_param command /usr/bin/u2pnpd
config_get "$i" "$section" "$i" append_arg "$cfg" -s httpsURL
done append_arg "$cfg" --interface interface
append_arg "$cfg" --manufacturer manufacturer
[ -n "$interface" ] && SERVICE_PID_FILE="/var/run/u2pnpd.$interface.pid" append_arg "$cfg" --manufacturerURL manufacturerURL
append_arg "$cfg" --modelDescription modelDescription
service_start /usr/bin/u2pnpd ${httpsURL:+-s} \ append_arg "$cfg" --modelName modelName
${interface:+--interface="$interface"} \ append_arg "$cfg" --modelNumber modelNumber
${manufacturer:+--manufacturer="$manufacturer"} \ append_arg "$cfg" --modelURL modelURL
${manufacturerURL:+--manufacturerURL="$manufacturerURL"} \ append_arg "$cfg" --serialNumber serialNumber
${modelDescription:+--modelDescription="$modelDescription"} \ append_arg "$cfg" --friendlyName friendlyName
${modelName:+--modelName="$modelName"} \ append_arg "$cfg" --uuid uuid
${modelNumber:+--modelNumber="$modelNumber"} \ procd_set_param file /etc/config/u2pnpd
${modelURL:+--modelURL="$modelURL"} \ procd_set_param respawn
${serialNumber:+--serialNumber="$serialNumber"} \ procd_close_instance
${friendlyName:+--friendlyName="$friendlyName"} \
${uuid:+--uuid="$uuid"}
} }
stop_instance() { start_service() {
local section="$1" config_load u2pnpd && config_foreach start_instance u2pnpd
local interface
config_get interface "$section" 'interface'
[ -n "$interface" ] && SERVICE_PID_FILE="/var/run/u2pnpd.$interface.pid"
service_stop /usr/bin/u2pnpd
rm -f "$SERVICE_PID_FILE"
} }
start() { service_triggers() {
config_load 'u2pnpd' procd_add_reload_trigger u2pnpd
config_foreach start_instance 'u2pnpd'
}
stop() {
config_load 'u2pnpd'
config_foreach stop_instance 'u2pnpd'
} }