aboutsummaryrefslogtreecommitdiff
path: root/src/vde2/vde.rc
blob: b368f99558811c5d9a2909d16f6ce98aef577445 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions
. /etc/conf.d/vde

case "$1" in
  start)
    # bring up all defined profiles
    for i in $VDE_CONFIG; do
      [ -e /etc/vde/$i ] && . /etc/vde/$i
      stat_busy "Starting vde_switch $i"
      # get options from profile
      [ -n "$VDE_NUMPORTS" ] && OPTIONS="-n $VDE_NUMPORTS"
      [ "$VDE_HUB" = "yes" ] && OPTIONS="$OPTIONS -x"
      [ "$VDE_FSTP" = "yes" ] && OPTIONS="$OPTIONS -F"
      [ -n "$VDE_MAC" ] && OPTIONS="$OPTIONS --macaddr $VDE_MAC"
      [ -n "$VDE_PRIORITY" ] && OPTIONS="$OPTIONS --priority $VDE_PRIORITY"
      [ -n "$VDE_HASH" ] && OPTIONS="$OPTIONS --hashsize $VDE_HASH"
      [ -n "$VDE_SOCK" ] && OPTIONS="$OPTIONS -s $VDE_SOCK"
      [ -n "$VDE_SOCK_MODE" ] && OPTIONS="$OPTIONS -m $VDE_SOCK_MODE"
      [ -n "$VDE_SOCK_GROUP" ] && OPTIONS="$OPTIONS -g $VDE_SOCK_GROUP"
      [ -n "$VDE_MANAGEMENT_SOCK" ] && OPTIONS="$OPTIONS -M $VDE_MANAGEMENT_SOCK"
      [ -n "$VDE_MANAGEMENT_SOCK_MODE" ] && OPTIONS="$OPTIONS --mgmtmode $VDE_MANAGEMENT_SOCK_MODE"
      [ -n "$VDE_TAP" ] && OPTIONS="$OPTIONS -t $VDE_TAP"
      [ -n "$VDE_OPTIONS" ] && OPTIONS="$OPTIONS $VDE_OPTIONS"
      vde_switch $OPTIONS -p /var/run/vde-$i.pid -daemon &>/dev/null
      [ -n "$VDE_SOCK" -a -n "$VDE_SOCK_GROUP" ] && chgrp "$VDE_SOCK_GROUP" "$VDE_SOCK"
      if [ $? -gt 0 ]; then
        stat_fail
      else
        stat_done
      fi
      if [ "$SLIRP" = "yes" ]; then
        stat_busy "Starting slirpvde for $i"
        [ "$SLIRP_DHCP" = "yes" ] && SP_OPTIONS="-D"
        [ -n "$SLIRP_NETWORK" ] && SP_OPTIONS="$SP_OPTIONS -n $SLIRP_NETWORK"
        [ -n "$SLIRP_OPTIONS" ] && SP_OPTIONS="$SP_OPTIONS $SLIRP_OPTIONS"
        [ -n "$VDE_SOCK" ] && SP_OPTIONS="$SP_OPTIONS -s $VDE_SOCK"
        [ -n "$VDE_SOCK_MODE" ] && SP_OPTIONS="$SP_OPTIONS -m $VDE_SOCK_MODE"
        [ -n "$VDE_SOCK_GROUP" ] && SP_OPTIONS="$SP_OPTIONS -g $VDE_SOCK_GROUP"
        slirpvde $SP_OPTIONS -p /var/run/slirpvde-$i.pid -daemon &>/dev/null
        if [ $? -gt 0 ]; then
          stat_fail
        else
          stat_done
        fi
        unset OPTIONS
        unset SP_OPTIONS
      fi
    done
    for i in $VDE_CONNECTION; do
      # connect specified vde_switches
      if [ "$(grep ^vde_plug /etc/vde/$i)" ]; then
        stat_busy "Connecting VDE switches $i together..."
        while read j; do
          switch="$(echo $j | grep ^vde_plug)"
          [ -n "$switch" ] && (dpipe $switch &)
        done </etc/vde/$i
        if [ $? -gt 0 ]; then
          stat_fail
        else
          stat_done
        fi
      fi
    done
    add_daemon vde
    ;;
  stop)
    # kill vde_plug if switches are connected
    [ -n "$VDE_CONNECTION" ] && killall vde_plug >/dev/null 2>&1
    for i in $VDE_CONFIG; do
      [ -e /etc/vde/$i ] && . /etc/vde/$i
      if [ "$SLIRP" = "yes" ]; then
        stat_busy "Stopping slirpvde for $i"
        kill $(cat /var/run/slirpvde-$i.pid) &> /dev/null
        if [ $? -gt 0 ]; then
          stat_fail
        else
          stat_done
        fi
        rm /var/run/slirpvde-$i.pid &> /dev/null
      fi
      stat_busy "Stopping vde_switch $i"
      kill $(cat /var/run/vde-$i.pid) &> /dev/null
        if [ $? -gt 0 ]; then
          stat_fail
        else
          stat_done
        fi
      rm /var/run/vde-$i.pid &> /dev/null
      stat_busy "Removing $i vde sockets"
      rm -rf $VDE_SOCK $VDE_MANAGEMENT_SOCK
      if [ $? -gt 0 ]; then
        stat_fail
      else
        stat_done
      fi
    done
      unset OPTIONS
      unset SP_OPTIONS
      [ -e /var/run/vde/gmon.out ] && rm /var/run/vde/gmon.out
      rm_daemon vde 
    ;;
  restart)
    $0 stop
    sleep 3
    $0 start
    ;;
    *)
    echo "usage: $0 {start|stop|restart}"
esac
exit 0