[packages] vrrpd: use network.sh to find devices
[openwrt/svn-archive/archive.git] / net / vrrpd / files / vrrpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006-2012 OpenWrt.org
3
4 START=50
5
6 append_list_item() {
7 local val="$1"
8 local var="$2"
9 append "$var" "$val"
10 }
11
12 append_bool() {
13 local var="$1"
14 local section="$2"
15 local option="$3"
16 local value="$4"
17 local _val
18 config_get_bool _val "$section" "$option" 0
19 [ $_val -gt 0 ] && append "$var" "$value"
20 }
21
22 append_string() {
23 local var="$1"
24 local section="$2"
25 local option="$3"
26 local val="$4"
27 local _val
28 config_get _val "$section" "$option"
29 [ -n "$_val" ] && append "$var" "$val $_val"
30 }
31
32 section_enabled() {
33 local enabled
34 config_get_bool enabled "$1" 'enabled' 0
35 [ $enabled -gt 0 ]
36 }
37
38 start_instance() {
39 local section="$1"
40 local id
41 local if
42 local dev
43 local args
44
45 section_enabled "$section" || return 1
46
47 config_get id "$section" 'virtual_id' '1'
48 config_get if "$section" 'interface' 'lan'
49 network_get_device dev "$if" && {
50 args="-v $id -i $dev"
51 append_string args "$section" 'delay' '-d'
52 append_string args "$section" 'priority' '-p'
53 append_bool args "$section" 'no_virtual_mac' '-n'
54 config_list_foreach "$section" 'virtual_ip' append_list_item args
55
56 SERVICE_PID_FILE="/var/run/vrrpd_${dev}_${id}.pid"
57 service_start /usr/sbin/vrrpd $args
58 }
59 }
60
61 stop_instance() {
62 local section="$1"
63 local id
64 local if
65 local dev
66
67 section_enabled "$section" || return 1
68
69 config_get id "$section" 'virtual_id' '1'
70 config_get if "$section" 'interface' 'lan'
71 network_get_device dev "$if"
72
73 SERVICE_PID_FILE="/var/run/vrrpd_${dev}_${id}.pid"
74 service_stop /usr/sbin/vrrpd
75 }
76
77 start() {
78 . /lib/functions/network.sh
79 config_load 'vrrpd'
80 config_foreach start_instance 'vrrpd'
81 }
82
83 stop() {
84 . /lib/functions/network.sh
85 config_load 'vrrpd'
86 config_foreach stop_instance 'vrrpd'
87 }