|
Revision 5876, 1.3 KB
(checked in by jow, 3 years ago)
|
|
uhttpd: add init script and uci configuration
|
-
Property svn:executable set to
*
|
| Line | |
|---|
| 1 | #!/bin/sh /etc/rc.common |
|---|
| 2 | # Copyright (C) 2010 Jo-Philipp Wich |
|---|
| 3 | |
|---|
| 4 | START=50 |
|---|
| 5 | UHTTPD_BIN="/usr/sbin/uhttpd" |
|---|
| 6 | UHTTPD_ARGS="" |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | append_listen_http() { |
|---|
| 10 | append UHTTPD_ARGS "-p $1" |
|---|
| 11 | } |
|---|
| 12 | |
|---|
| 13 | append_listen_https() { |
|---|
| 14 | append UHTTPD_ARGS "-s $1" |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | append_arg() { |
|---|
| 18 | local cfg="$1" |
|---|
| 19 | local var="$2" |
|---|
| 20 | local opt="$3" |
|---|
| 21 | local val |
|---|
| 22 | |
|---|
| 23 | config_get val "$cfg" "$var" |
|---|
| 24 | [ -n "$val" ] && append UHTTPD_ARGS "$opt $val" |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | start_instance() |
|---|
| 28 | { |
|---|
| 29 | UHTTPD_ARGS="" |
|---|
| 30 | |
|---|
| 31 | local cfg="$1" |
|---|
| 32 | local ssl |
|---|
| 33 | |
|---|
| 34 | append_arg "$cfg" home "-h" |
|---|
| 35 | append_arg "$cfg" cgi_prefix "-c" |
|---|
| 36 | append_arg "$cfg" lua_prefix "-l" |
|---|
| 37 | append_arg "$cfg" lua_handler "-L" |
|---|
| 38 | |
|---|
| 39 | config_list_foreach "$cfg" listen_http \ |
|---|
| 40 | append_listen_http |
|---|
| 41 | |
|---|
| 42 | config_get ssl "$cfg" listen_https |
|---|
| 43 | [ -n "$ssl" ] && { |
|---|
| 44 | append_arg "$cfg" cert "-C" |
|---|
| 45 | append_arg "$cfg" key "-K" |
|---|
| 46 | |
|---|
| 47 | config_list_foreach "$cfg" listen_https \ |
|---|
| 48 | append_listen_https |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | start-stop-daemon -S -x $UHTTPD_BIN \ |
|---|
| 52 | -p /var/run/uhttpd_${cfg}.pid \ |
|---|
| 53 | -m -b -- -f $UHTTPD_ARGS |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | stop_instance() |
|---|
| 57 | { |
|---|
| 58 | local cfg="$1" |
|---|
| 59 | |
|---|
| 60 | [ -f /var/run/uhttpd_${cfg}.pid ] && { |
|---|
| 61 | start-stop-daemon -K -q -n ${UHTTPD_BIN##*/} \ |
|---|
| 62 | -p /var/run/uhttpd_${cfg}.pid -s TERM |
|---|
| 63 | |
|---|
| 64 | rm -f /var/run/uhttpd_${cfg}.pid |
|---|
| 65 | } |
|---|
| 66 | } |
|---|
| 67 | |
|---|
| 68 | start() { |
|---|
| 69 | config_load uhttpd |
|---|
| 70 | config_foreach start_instance uhttpd |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | stop() { |
|---|
| 74 | config_load uhttpd |
|---|
| 75 | config_foreach stop_instance uhttpd |
|---|
| 76 | } |
|---|