source: packages/ipv6/ahcpd/files/ahcpd.init @ 28922

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

packages/ahcpd: use new service functions

  • Property svn:copyright set to Copyright (C) 2007 OpenWrt.org
File size: 2.4 KB
Line 
1#!/bin/sh /etc/rc.common
2# Copyright (C) 2007-2011 OpenWrt.org
3
4START=71
5
6SERVICE_USE_PID=1
7
8EXTRA_COMMANDS="status"
9EXTRA_HELP="        status Print ahcpd's status to the log file."
10
11append_bool() {
12        local section="$1"
13        local option="$2"
14        local value="$3"
15        local _loctmp
16        config_get_bool _loctmp "$section" "$option" 0
17        [ "$_loctmp" -gt 0 ] && append args "$value"
18}
19
20append_parm() {
21        local section="$1"
22        local option="$2"
23        local switch="$3"
24        local _loctmp
25        config_get _loctmp "$section" "$option"
26        [ -z "$_loctmp" ] && return 0
27        append args "$switch $_loctmp"
28}
29
30append_stmt() {
31        local name="$1"
32        local switch="$2"
33        append args "-C '$switch $name'"
34}
35
36append_opt_stmt() {
37        local section="$1"
38        local option="$2"
39        local switch="$3"
40        local _loctmp
41        config_get _loctmp "$section" "$option"
42        [ -z "$_loctmp" ] && return 0
43        append args "-C '$switch $_loctmp'"
44}
45
46ahcp_addif() {
47        local ifname=$(uci_get_state network "$1" ifname "$1")
48        append interfaces "$ifname"
49}
50
51ahcp_server() {
52        local cfg="$1"
53
54        append_opt_stmt "$cfg" 'mode' 'mode'
55        append_opt_stmt "$cfg" 'lease_dir' 'lease-dir'
56        config_list_foreach "$cfg" 'prefix' append_stmt 'prefix'
57        config_list_foreach "$cfg" 'name_server' append_stmt 'name-server'
58        config_list_foreach "$cfg" 'ntp_server' append_stmt 'ntp-server'
59
60        append_parm "$cfg" 'id_file' '-i'
61        append_parm "$cfg" 'log_file' '-L'
62}
63
64ahcp_config() {
65        local cfg="$1"
66        local interface
67        local _loctmp
68
69        config_list_foreach "$cfg" 'interface' ahcp_addif
70
71        # Add interfaces with "option proto ahcp" in /etc/config/network
72        # (only for client mode)
73        config_get _loctmp "$cfg" "mode"
74        if [ -z "$_loctmp" -o "$_loctmp" = "client" ]; then
75                for interface in $(uci -P /var/state show network|grep proto=ahcp|cut -d. -f2); do
76                        ahcp_addif $interface
77                done
78        fi
79
80        append_bool "$cfg" 'ipv4_only' '-4'
81        append_bool "$cfg" 'ipv6_only' '-6'
82        append_bool "$cfg" 'no_dns' '-N'
83
84        append_parm "$cfg" 'multicast_address' '-m'
85        append_parm "$cfg" 'port' '-p'
86        append_parm "$cfg" 'lease_time' '-t'
87        append_parm "$cfg" 'debug' '-d'
88        append_parm "$cfg" 'conf_file' '-c'
89        append_parm "$cfg" 'script' '-s'
90}
91
92start() {
93        mkdir -p /var/lib
94        config_load ahcpd
95        unset args
96        unset interfaces
97        config_foreach ahcp_config ahcpd
98        config_foreach ahcp_server ahcpd
99        [ -z "$interfaces" ] && return 0
100        service_start /usr/sbin/ahcpd -D $args $interfaces
101}
102
103stop() {
104        service_stop /usr/sbin/ahcpd
105}
106
107status() {
108        SERVICE_SIG="USR1" service_signal /usr/sbin/ahcpd
109}
Note: See TracBrowser for help on using the repository browser.