summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/uhttpd/files/uhttpd.init
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-03-19 09:22:15 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-03-19 09:22:15 +0000
commit5f343a22e1a3cfe8736484ae9f239613e6647f9f (patch)
treea96cfff5fa3f01ce49a7f18c4af273e7a472f902 /contrib/package/uhttpd/files/uhttpd.init
parent60f7191ff4609ebd056eb4a326f29a49b3c32fb5 (diff)
uhttpd: add init script and uci configuration
Diffstat (limited to 'contrib/package/uhttpd/files/uhttpd.init')
-rwxr-xr-xcontrib/package/uhttpd/files/uhttpd.init76
1 files changed, 76 insertions, 0 deletions
diff --git a/contrib/package/uhttpd/files/uhttpd.init b/contrib/package/uhttpd/files/uhttpd.init
new file mode 100755
index 000000000..08c6a3929
--- /dev/null
+++ b/contrib/package/uhttpd/files/uhttpd.init
@@ -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
+}