source: packages/net/vrrpd/files/vrrpd.init @ 29214

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

packages/vrrpd: use uci config

  • Property svn:eol-style set to native
File size: 1.8 KB
Line 
1#!/bin/sh /etc/rc.common
2# Copyright (C) 2006-2011 OpenWrt.org
3
4START=50
5
6append_list_item() {
7        local val="$1"
8        local var="$2"
9        append "$var" "$val"
10}
11
12append_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
22append_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
32config_get_ifname() {
33        local var="$1"
34        local section="$2"
35        local option="$3"
36        local val="$4"
37        local _val
38        config_get _val "$section" "$option" "$val"
39        config_get "$var" "$_val" 'ifname' "$_val"
40}
41
42section_enabled() {
43        local enabled
44        config_get_bool enabled "$1" 'enabled' 0
45        [ $enabled -gt 0 ]
46}
47
48start_instance() {
49        local section="$1"
50        local id
51        local if
52        local args
53
54        section_enabled "$section" || return 1
55
56        config_get id "$section" 'virtual_id' '1'
57        config_get_ifname if "$section" 'interface' 'lan'
58
59        args="-v $id -i $if"
60        append_string args "$section" 'delay' '-d'
61        append_string args "$section" 'priority' '-p'
62        append_bool args "$section" 'no_virtual_mac' '-n'
63        config_list_foreach "$section" 'virtual_ip' append_list_item args
64
65        SERVICE_PID_FILE="/var/run/vrrpd_${if}_${id}.pid"
66        service_start /usr/sbin/vrrpd $args
67}
68
69stop_instance() {
70        local section="$1"
71        local id
72        local if
73
74        section_enabled "$section" || return 1
75
76        config_get id "$section" 'virtual_id' '1'
77        config_get_ifname if "$section" 'interface' 'lan'
78
79        SERVICE_PID_FILE="/var/run/vrrpd_${if}_${id}.pid"
80        service_stop /usr/sbin/vrrpd
81}
82
83start() {
84        include /lib/network
85        scan_interfaces
86        config_load 'vrrpd'
87        config_foreach start_instance 'vrrpd'
88}
89
90stop() {
91        include /lib/network
92        scan_interfaces
93        config_load 'vrrpd'
94        config_foreach stop_instance 'vrrpd'
95}
Note: See TracBrowser for help on using the repository browser.