source: packages/net/mini_snmpd/files/mini_snmpd.init @ 29211

Last change on this file since 29211 was 29211, checked in by nico, 5 years ago

packages/mini_snmpd: allow both raw & uci interface names in interfaces list

File size: 1.2 KB
Line 
1#!/bin/sh /etc/rc.common
2# Copyright (C) 2009-2011 OpenWrt.org
3
4START=50
5
6SERVICE_DAEMONIZE=1
7SERVICE_WRITE_PID=1
8
9append_disk() {
10        local disk="$1"
11        append disks "$disk" ','
12}
13
14append_interface() {
15        local name="$1"
16        local interface
17        config_get interface "$name" 'ifname' "$name"
18        append interfaces "$interface" ','
19}
20
21append_string() {
22        local section="$1"
23        local option="$2"
24        local value="$3"
25        local _val
26        config_get _val "$section" "$option"
27        [ -n "$_val" ] && append args "$3 $_val"
28}
29
30start_instance() {
31        local cfg="$1"
32        local args=""
33        local disks=""
34        local interfaces=""
35        local ipv6
36
37        append_string "$cfg" community "-c"
38        append_string "$cfg" location "-L"
39        append_string "$cfg" contact "-C"
40
41        config_get_bool ipv6 "$cfg" "ipv6" '0'
42        [ "$ipv6" -gt 0 ] && append args "-6"
43
44        config_get_bool enabled "$cfg" "enabled" '1'
45        [ "$enabled" -gt 0 ] || return 1
46
47        config_list_foreach "$section" 'disks' append_disk
48        args="${args}${disks:+ -d $disks}"
49
50        config_list_foreach "$section" 'interfaces' append_interface
51        args="${args}${interfaces:+ -i $interfaces}"
52
53        service_start /usr/bin/mini_snmpd $args
54}
55
56start() {
57        include /lib/network
58        scan_interfaces
59        config_load 'mini_snmpd'
60        config_foreach start_instance 'mini_snmpd'
61}
62
63stop() {
64        service_stop /usr/bin/mini_snmpd
65}
Note: See TracBrowser for help on using the repository browser.