]> git.pld-linux.org Git - packages/lxc.git/blob - lxc_macvlan.init
Release 3. Fixes in init scripts.
[packages/lxc.git] / lxc_macvlan.init
1 #!/bin/sh
2 #
3 # lxc_macvlan Start/Stop LXC MACVLAN interface
4 #
5 # chkconfig: 345 98 02
6 # description: Starts/Stops LXC MACVLAN interface.
7 #
8 ### BEGIN INIT INFO
9 # Provides: lxc_macvlan
10 # Default-Start: 3 4 5
11 # Default-Stop: 0 1 6
12 # Short-Description: Start/Stop LXC MACVLAN interface
13 # Description: Start/Stop LXC MACVLAN interface
14 ### END INIT INFO
15
16 # Source function library
17 . /etc/rc.d/init.d/functions
18
19 # Source any configurable options
20 test ! -r /etc/sysconfig/lxc_macvlan ||
21         . /etc/sysconfig/lxc_macvlan
22
23 # Tests for data provided in /etc/sysconfig/lxc_macvlan
24 if [ -z "$MACVLAN_DEV" ]; then 
25     echo "MACVLAN_DEV not set is /etc/sysconfig/lxc_macvlan"
26     exit 6
27 fi
28
29 if [ -z "$MACVLAN_NAME" ]; then
30     echo "MACVLAN_NAME not set is /etc/sysconfig/lxc_macvlan"
31     exit 6
32 fi
33
34 if [ -z "$MACVLAN_ADDRESS" ]; then
35     echo "MACVLAN_ADDRESS not set is /etc/sysconfig/lxc_macvlan"
36     exit 6
37 fi
38
39 # If not defined MACVLAN_HWADDRESS, calculate it from MACVLAN_ADDRESS
40 if [ -z "$MACVLAN_HWADDRESS" ]; then 
41     MACVLAN_HWADDRESS=`echo $MACVLAN_ADDRESS | awk -F "/" '{print $1}' | awk -F "." '{ printf "00:16:3e:%x:%x:%x\n", $2, $3, $4 }'`
42     # TODO: Print on start() only
43     # echo "MACVLAN_HWADDRESS not set, using calculated from MACVLAN_ADDRESS=${MACVLAN_ADDRESS} value: ${MACVLAN_HWADDRESS}"; 
44 fi
45
46
47 start() {
48         msg_starting "LXC macvlan interface"
49         # set -x
50         ip link add link $MACVLAN_DEV name $MACVLAN_NAME address $MACVLAN_HWADDRESS type macvlan mode bridge
51         ip link set $MACVLAN_NAME up
52         ip address add $MACVLAN_ADDRESS brd + dev $MACVLAN_NAME
53         # TODO: check if works: 
54         #    cat  /sys/class/net/macv0/address                                                                                                                                                                                                        
55         #    00:13:00:00:20:14
56         RETVAL=$?
57         [ $RETVAL -eq 0 ] && ok || fail
58 }
59
60 stop() {
61         msg_stopping "LXC macvlan interface"
62         # set -x
63         ip link set $MACVLAN_NAME down
64         ip link del $MACVLAN_NAME
65         RETVAL=$?
66         [ $RETVAL -eq 0 ] && ok || fail
67 }
68
69 status() {
70         ip addr show $MACVLAN_NAME 
71 }
72
73
74 RETVAL=0
75
76 # See how we were called.
77 case "$1" in
78   start)
79         start
80         ;;
81
82   stop)
83         stop
84         ;;
85   restart|reload|force-reload)
86         stop
87         start
88         ;;
89   status)
90         status
91         ;;
92   *)
93
94         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
95         exit 3
96 esac
97
98 exit  $RETVAL
This page took 0.042521 seconds and 3 git commands to generate.