uhttpd: add init script and uci configuration
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 19 Mar 2010 09:22:15 +0000 (09:22 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 19 Mar 2010 09:22:15 +0000 (09:22 +0000)
contrib/package/uhttpd/Makefile
contrib/package/uhttpd/files/uhttpd.config [new file with mode: 0644]
contrib/package/uhttpd/files/uhttpd.init [new file with mode: 0755]

index ec37b2e..802fb20 100644 (file)
@@ -18,7 +18,7 @@ define Package/uhttpd
   SECTION:=net
   CATEGORY:=Network
   TITLE:=uHTTPd - tiny, single threaded HTTP server
-  DEPENDS:=+liblua +libcyassl
+  DEPENDS:=+liblua +libcyassl +zlib
 endef
 
 define Package/uhttpd/description
@@ -35,9 +35,17 @@ define Build/Prepare
        $(CP) ./src/* $(PKG_BUILD_DIR)/
 endef
 
+define Package/uhttpd/conffiles
+/etc/config/uhttpd
+endef
+
 define Package/uhttpd/install
-       $(INSTALL_DIR) $(1)/sbin
-       $(INSTALL_BIN) $(PKG_BUILD_DIR)/uhttpd $(1)/sbin/
+       $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/uhttpd.init $(1)/etc/init.d/uhttpd
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_CONF) ./files/uhttpd.config $(1)/etc/config/uhttpd
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/uhttpd $(1)/usr/sbin/uhttpd
 endef
 
 $(eval $(call BuildPackage,uhttpd))
diff --git a/contrib/package/uhttpd/files/uhttpd.config b/contrib/package/uhttpd/files/uhttpd.config
new file mode 100644 (file)
index 0000000..97a43f4
--- /dev/null
@@ -0,0 +1,27 @@
+config uhttpd main
+       # Server document root
+       option home             /www
+
+       # Certificate and private key for HTTPS.
+       # If no listen_https addresses are given,
+       # the key options are ignored.
+       option cert             /etc/nixio/cert_main.der
+       option key              /etc/nixio/rsa_main.der
+
+       # CGI url prefix, will be searched in docroot.
+       # Default is /cgi-bin
+       option cgi_prefix       /cgi-bin
+
+       # Lua url prefix and handler script.
+       # Lua support is disabled if no prefix given.
+#      option lua_prefix       /lua
+#      option lua_handler      /www/lua/handler.lua
+
+       # HTTP listen addresses, multiple allowed
+       list listen_http        0.0.0.0:80
+#      list listen_http        [::]:80
+
+       # HTTPS listen addresses, multiple allowed
+       list listen_https       0.0.0.0:443
+#      list listen_https       [::]:443
+
diff --git a/contrib/package/uhttpd/files/uhttpd.init b/contrib/package/uhttpd/files/uhttpd.init
new file mode 100755 (executable)
index 0000000..08c6a39
--- /dev/null
@@ -0,0 +1,76 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2010 Jo-Philipp Wich
+
+START=50
+UHTTPD_BIN="/usr/sbin/uhttpd"
+UHTTPD_ARGS=""
+
+
+append_listen_http() {
+       append UHTTPD_ARGS "-p $1"
+}
+
+append_listen_https() {
+       append UHTTPD_ARGS "-s $1"
+}
+
+append_arg() {
+       local cfg="$1"
+       local var="$2"
+       local opt="$3"
+       local val
+
+       config_get val "$cfg" "$var"
+       [ -n "$val" ] && append UHTTPD_ARGS "$opt $val"
+}
+
+start_instance()
+{
+       UHTTPD_ARGS=""
+
+       local cfg="$1"
+       local ssl
+
+       append_arg "$cfg" home "-h"
+       append_arg "$cfg" cgi_prefix "-c"
+       append_arg "$cfg" lua_prefix "-l"
+       append_arg "$cfg" lua_handler "-L"
+
+       config_list_foreach "$cfg" listen_http \
+               append_listen_http
+
+       config_get ssl "$cfg" listen_https
+       [ -n "$ssl" ] && {
+               append_arg "$cfg" cert "-C"
+               append_arg "$cfg" key  "-K"
+
+               config_list_foreach "$cfg" listen_https \
+                       append_listen_https
+       }
+
+       start-stop-daemon -S -x $UHTTPD_BIN \
+               -p /var/run/uhttpd_${cfg}.pid \
+               -m -b -- -f $UHTTPD_ARGS
+}
+
+stop_instance()
+{
+       local cfg="$1"
+
+       [ -f /var/run/uhttpd_${cfg}.pid ] && {
+               start-stop-daemon -K -q -n ${UHTTPD_BIN##*/} \
+                       -p /var/run/uhttpd_${cfg}.pid -s TERM
+
+               rm -f /var/run/uhttpd_${cfg}.pid
+       }
+}
+
+start() {
+       config_load uhttpd
+       config_foreach start_instance uhttpd
+}
+
+stop() {
+       config_load uhttpd
+       config_foreach stop_instance uhttpd
+}