010b2b939c364624a0ee163b648883407c9b3d27
[feed/packages.git] / utils / owfs / files / owftpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2009-2012 OpenWrt.org
3
4 START=99
5
6 SERVICE_WRITE_PID=1
7 SERVICE_DAEMONIZE=1
8
9 # Needed for restricted TCP port 21
10 DEFAULT_SERVICE_UID=0
11 DEFAULT_SERVICE_GID=0
12
13 append_device() {
14 append devices "$1"
15 }
16
17
18 start_owfs_daemon() {
19 local program="$1"
20 local config="$1"
21 local args="--foreground --error_print=1 $2"
22
23
24 local enabled
25 config_get_bool enabled "$config" enabled 0
26 [ "${enabled}" -eq 0 ] && return 1
27
28 local readonly
29 config_get_bool readonly "$config" readonly 0
30 [ "${readonly}" -eq 1 ] && append args "--readonly"
31
32 local error_level
33 config_get error_level "$config" error_level
34 [ -n "${error_level}" ] && append args "--error_level=${error_level}"
35
36 local options
37 config_get options "$config" options
38
39 devices=""
40 config_list_foreach "$config" devices append_device
41
42 config_get SERVICE_UID "$config" uid "$DEFAULT_SERVICE_UID"
43 config_get SERVICE_GID "$config" gid "$DEFAULT_SERVICE_GID"
44
45 service_start "/usr/bin/$program" $args $options $devices
46 }
47
48 start_owftpd() {
49 local config="owftpd"
50 local args=""
51
52 config_load "$config"
53
54 local port
55 config_get port "$config" port
56 [ -n "${port}" ] && append args "--port=${port}"
57
58 local max_connections
59 config_get max_connections "$config" max_connections
60 [ -n "${max_connections}" ] && append args "--max_connections=${max_connections}"
61
62 start_owfs_daemon "$config" "$args"
63 }
64
65
66 start() {
67 start_owftpd
68 }
69
70 stop() {
71 service_stop /usr/bin/owftpd
72 }