[PATCH] uhttpd: uhttpd-mod-ubus: reload uhttpd only if it's runtime install

Rafał Miłecki zajec5 at gmail.com
Sun Nov 26 12:47:39 PST 2023


From: Rafał Miłecki <rafal at milecki.pl>

Reloading service from uci-defaults script is a hack to workaround
postinst limitation. It should not be executed during boot as other
uci-defaults scripts may want to adjust uhttpd's config too.

Cc: Hauke Mehrtens <hauke at hauke-m.de>
Fixes: d25d281fd668 ("uhttpd: Reload config after uhttpd-mod-ubus was added")
Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 package/network/services/uhttpd/Makefile           |  2 +-
 package/network/services/uhttpd/files/ubus.default | 13 ++++++++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/package/network/services/uhttpd/Makefile b/package/network/services/uhttpd/Makefile
index 02a02405fd..9405070626 100644
--- a/package/network/services/uhttpd/Makefile
+++ b/package/network/services/uhttpd/Makefile
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=uhttpd
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/uhttpd.git
diff --git a/package/network/services/uhttpd/files/ubus.default b/package/network/services/uhttpd/files/ubus.default
index 474016c1c5..e2240a1018 100644
--- a/package/network/services/uhttpd/files/ubus.default
+++ b/package/network/services/uhttpd/files/ubus.default
@@ -12,6 +12,17 @@ fi
 	commit=1
 }
 
-[ "$commit" = 1 ] && uci commit uhttpd && /etc/init.d/uhttpd reload
+# Normally (when executing this script during boot) we want to adjust config
+# only. Actual uhttpd start will happen later.
+#
+# If this is package installation in a running system however then we need to
+# reload uhttpd to make ubus access work right after. Ideally this should be
+# handled by a "postinst" script but those get executed *before* uci-defaults
+# scripts. For that reason we abuse uci-defaults to call init.d script.
+#
+# Check for $PKG_ROOT to detect "opkg install" case in a running system.
+if [ -n "$PKG_ROOT" ]; then
+	[ "$commit" = 1 ] && uci commit uhttpd && /etc/init.d/uhttpd reload
+fi
 
 exit 0
-- 
2.35.3




More information about the openwrt-devel mailing list