branch Attitude Adjustment packages
[12.09/packages.git] / net / n2n / files / n2n.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2012 OpenWrt.org
3
4 START=90
5
6 start_instance() {
7         local cfg="$1"
8
9         config_get type "$cfg" TYPE
10
11         case "$type" in
12           edge)
13                 config_get ipaddr "$cfg" 'ipaddr'
14                 [ -n "$ipaddr" ] || return 1
15                 config_get supernode "$cfg" 'supernode'
16                 config_get port "$cfg" 'port'
17                 config_get community "$cfg" 'community'
18                 config_get key "$cfg" 'key'
19                 config_get_bool route "$cfg" 'route' '0'
20                 [ "$route" = "1" ] && args='-r'
21                 service_start /usr/sbin/edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port}
22                 ;;
23           supernode)
24                 config_get port "$cfg" port
25                 [ -n "$port" ] || return 1
26                 service_start /usr/sbin/supernode -l $port
27                 ;;
28         esac
29 }
30
31 stop_instance() {
32         local cfg="$1"
33
34         config_get type "$cfg" TYPE
35
36         case "$type" in
37           edge)
38                 service_stop /usr/sbin/edge
39                 ;;
40           supernode)
41                 service_stop /usr/sbin/supernode
42                 ;;
43         esac
44 }
45
46 start() {
47         config_load 'n2n'
48         config_foreach start_instance 'edge'
49         config_foreach start_instance 'supernode'
50 }
51
52 stop() {
53         config_load 'n2n'
54         config_foreach stop_instance 'edge'
55         config_foreach stop_instance 'supernode'
56 }