diff options
author | Daniel Golle <daniel@makrotopia.org> | 2023-11-02 15:39:49 +0000 |
---|---|---|
committer | Daniel Golle <daniel@makrotopia.org> | 2024-02-01 00:52:54 +0000 |
commit | 7b1c3068b74273af2370e433b3f476b65ddd123c (patch) | |
tree | e9b3ffa3e79474f11b28e8ae178cc6f49df06706 /package/network/services/uhttpd | |
parent | 906595c26271e644240fd8da134b2af5ad9dc285 (diff) | |
download | openwrt-7b1c3068b74273af2370e433b3f476b65ddd123c.tar.gz openwrt-7b1c3068b74273af2370e433b3f476b65ddd123c.tar.bz2 openwrt-7b1c3068b74273af2370e433b3f476b65ddd123c.zip |
uhttpd: restart when interface to listen becomes available
Currently uhttpd won't start with a listening interface configured if
the interface isn't already up at the time uhttpd starts. Make sure we
attempt to start uhttpd when it comes up.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'package/network/services/uhttpd')
-rwxr-xr-x | package/network/services/uhttpd/files/uhttpd.init | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/package/network/services/uhttpd/files/uhttpd.init b/package/network/services/uhttpd/files/uhttpd.init index bfde231bf6..c4d0025d69 100755 --- a/package/network/services/uhttpd/files/uhttpd.init +++ b/package/network/services/uhttpd/files/uhttpd.init @@ -219,10 +219,76 @@ start_instance() procd_close_instance } +uhttpd_interfaces() +{ + local cfg="$1" + local http https listen ips + + config_get http "$cfg" listen_http + config_get https "$cfg" listen_https + for listen in $http $https; do + case "$listen" in + "" |\ + "0.0.0.0:"* |\ + "[::]:"* ) + continue + ;; + *.*.*.*:*) + ips="$ips ${listen%%:*} +" + ;; + \[*\]:* ) + listen="${listen:1}" + ips="$ips ${listen%%]:*} +" + ;; + esac + done + ips="$( echo "$ips" | sort -u )" + echo "$ips" +} + +resolve_iface() +{ + local cfg="$1" + local ipaddr ipaddrs testip="$2" + + config_get ipaddrs "$cfg" ipaddr + for ipaddr in $ipaddrs; do + [ "$ipaddr" = "$testip" ] && echo "$cfg" + done +} + +get_interface_by_ip() +{ + config_load network + config_foreach resolve_iface interface "$@" +} + service_triggers() { + local iface ifaces all=0 + procd_add_reload_trigger "uhttpd" procd_add_raw_trigger acme.renew 5000 /etc/init.d/uhttpd reload + + config_load uhttpd + ips="$(config_foreach uhttpd_interfaces uhttpd)" + [ -z "$ips" ] && return 0 + + for ip in $ips; do + iface="$(get_interface_by_ip $ip)" + [ -z "$iface" ] && all=1 + ifaces="$ifaces $iface" + done + + if [ "$all" = "1" ]; then + procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/uhttpd start + else + for iface in $ifaces; do + procd_add_raw_trigger "interface.$iface.up" 1000 /etc/init.d/uhttpd start + done + fi } start_service() { |