]> git.pld-linux.org Git - packages/lxc.git/blob - lxc_macvlan.init
Release 2. Added lxc_macvlan service, setting up host macvlan interface for lxc...
[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     echo "MACVLAN_HWADDRESS not set, using calculated from MACVLAN_ADDRESS=${MACVLAN_ADDRESS} value: ${MACVLAN_HWADDRESS}"; 
43 fi
44
45
46 start() {
47         msg_starting "LXC macvlan interface"
48         ip link add link $MACVLAN_DEV name $MACVLAN_NAME address $MACVLAN_HWADDRESS type macvlan mode bridge
49         ip link set $MACVLAN_NAME up
50         ip address add $MACVLAN_ADDRESS brd + dev $MACVLAN_NAME
51         # TODO: check if works: 
52         #    cat  /sys/class/net/macv0/address                                                                                                                                                                                                        
53         #    00:13:00:00:20:14
54         RETVAL=$?
55         [ $RETVAL -eq 0 ] && ok || fail
56 }
57
58 stop() {
59         msg_stopping "LXC macvlan interface"
60         ip link set $MACVLAN_NAME down
61         ip link del $MACVLAN_NAME
62         RETVAL=$?
63         [ $RETVAL -eq 0 ] && ok || fail
64 }
65
66
67 RETVAL=0
68
69 # See how we were called.
70 case "$1" in
71   start)
72         start
73         ;;
74
75   stop)
76         stop
77         ;;
78   restart|reload|force-reload)
79         stop
80         start
81         ;;
82   status)
83         ;;
84   *)
85
86         msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
87         exit 3
88 esac
89
90 exit  $RETVAL
This page took 0.041436 seconds and 3 git commands to generate.