3.mfrisbeed-subboss.sh.in 5.86 KB
Newer Older
1 2 3
#!/bin/sh

# PROVIDE: mfrisbeed
Mike Hibler's avatar
Mike Hibler committed
4
# REQUIRE: DAEMON ntpd
5 6 7 8 9 10 11 12 13 14 15 16 17
# BEFORE: testbed
# KEYWORD: shutdown

#
# Start up the frisbee master server on a subboss.
# There is no sure fire way to dynamically tell if we are a subboss right now.
# We cannot use "tmcc role" because tmcc doesn't exist/work on real boss.
# So we just do our own script right now.
#
# We run it under the daemon wrapper if available so that it will get
# automatically restarted.
#

18 19 20 21 22 23 24
#
# Default values for configuration variables.
#
# MCBASEADDR: base multicast address.
#     Subbosses in the same broadcast domain should use different values to
#     avoid confusion; e.g., 239.193.1, 239.194.1, etc.
#     Unset to use mfrisbeed default.
25 26 27 28 29 30 31
# MCBASEPORT: base multicast port number.
#     Zero means any ephemeral port.
#     Unset to use mfrisbeed default.
# MCNUMPORT: number of ports to allow.
#     Range will be MCBASEPORT to MCBASEPORT+MCNUMPORT.
#     Zero means any ephemeral port above the base.
#     Unset to use mfrisbeed default.
32 33
# BANDWIDTH: maximum bandwidth any instance of frisbeed should use (Mb/sec).
#     Unset to use mfrisbeed default.
34 35 36 37 38 39 40
# DYNAMICBW: use *experimental* dynamic bandwidth control. If non-zero,
#     uses an additive-increase, multiplicitive-decrease algorithm based
#     on congestion detection. Here BANDWIDTH represents the maximum to allow.
#     Unset or zero disables.
# MAXLINGER: how long (seconds) to wait around after the last report/request
#     has been received. 0 means exit when last client leaves, -1 means
#     wait forever. Unset to use mfrisbeed default.
41 42 43 44 45 46 47 48 49 50 51
# UNICAST: use unicast rather than multicast when downloading from our parent.
# MCQUERIER: run as an IGMPv2 querier.
#     You should only have one of these per broadcast domain.
# EVENTSERVER: event server for client progress reports.
#     Only used when CLIENTREPORT is non-zero.
# CLIENTREPORT: client progress reporting interval.
#     Unset to disable. Set to zero to enable but start with no reports.
# CACHEDIR: local directory for caching images.
# DEBUG: set to run with debugging enabled.
#
MCBASEADDR=239.192.1
52 53
MCBASEPORT=
MCNUMPORT=
54
BANDWIDTH=100000000
55 56
DYNAMICBW=
MAXLINGER=180
57 58 59 60 61 62 63
UNICAST=false
MCQUERIER=false
EVENTSERVER=boss
CLIENTREPORT=
CACHEDIR=/z/image_cache
DEBUG=false

64 65 66 67 68 69 70 71 72
. /etc/rc.subr

bindir=@prefix@/sbin
if [ ! -x $bindir/mfrisbeed ]; then
    echo "*** mfrisbeed.sh: $bindir/mfrisbeed not installed"
    exit 1
fi

case "$1" in
73
start|faststart|quietstart|onestart|forcestart)
74
    ;;
75
restart|fastrestart|quietrestart|onerestart|forcerestart)
76 77 78 79 80 81 82 83 84
    if [ -f /var/run/mfrisbeed_wrapper.pid ]; then
	kill `cat /var/run/mfrisbeed_wrapper.pid` >/dev/null 2>&1
	rm -f /var/run/mfrisbeed_wrapper.pid
    fi
    if [ -f /var/run/mfrisbeed.pid ]; then
	kill `cat /var/run/mfrisbeed.pid` >/dev/null 2>&1
	rm -f /var/run/mfrisbeed.pid
    fi
    ;;
85
stop|faststop|quietstop|onestop|forcestop)
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    echo -n ' mfrisbeed'
    if [ -f /var/run/mfrisbeed_wrapper.pid ]; then
	kill `cat /var/run/mfrisbeed_wrapper.pid` >/dev/null 2>&1
	rm -f /var/run/mfrisbeed_wrapper.pid
    fi
    if [ -f /var/run/mfrisbeed.pid ]; then
	kill `cat /var/run/mfrisbeed.pid` >/dev/null 2>&1
	rm -f /var/run/mfrisbeed.pid
    fi
    rm -f /var/run/frisbeed-*.pid
    exit 0
    ;;
*)
    echo "Usage: $0 {start|stop|restart}" >&2
    exit 1
    ;;
esac

echo -n " mfrisbeed"
rm -f /var/run/frisbeed-*.pid
106

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
#
# Get subboss specific overrides via tmcd.
#
SBINFO=
if [ -x "/usr/local/etc/emulab/tmcc" ]; then
    SBINFO=`/usr/local/etc/emulab/tmcc -b subbossinfo | grep -i '^frisbee'`
fi
if [ $? -eq 0 ]; then
    # XXX note that we do not expect any whitespace in our vals
    for kv in $SBINFO; do
	# upcase the key; not necessary, just makes me happy
	k=`echo ${kv%%=*} | awk '{print toupper($0)}'`

	# strip quotes from the val
	v="${kv##*=}"
	v="${v%\"}"
	v="${v#\"}"

	# no value, use the default
	if [ -z "$v" ]; then
	    k=SKIP
	fi

	case $k in
	    MCBASEADDR)
		MCBASEADDR=$v
		;;
134 135 136 137 138 139
	    MCBASEPORT)
		MCBASEPORT=$v
		;;
	    MCNUMPORT)
		MCNUMPORT=$v
		;;
140 141 142
	    BANDWIDTH)
		BANDWIDTH=$v
		;;
143 144 145 146 147 148
	    DYNAMICBW)
		DYNAMICBW=$v
		;;
	    MAXLINGER)
		MAXLINGER=$v
		;;
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
	    UNICAST)
		UNICAST=$v
		;;
	    MCQUERIER)
		MCQUERIER=$v
		;;
	    EVENTSERVER)
		EVENTSERVER=$v
		;;
	    CLIENTREPORT)
		CLIENTREPORT=$v
		;;
	    CACHEDIR)
		CACHEDIR=$v
		;;
	    DEBUG)
		DEBUG=$v
		;;
	esac
    done
fi

args="-C null -S @BOSSNODE_IP@ -I $CACHEDIR -A -M -R"
if [ "$UNICAST" = "true" ]; then
173 174
    args="$args -X ucast"
fi
175
if [ "$MCQUERIER" = "true" ]; then
176 177 178 179 180
    args="$args -Q 30"
    # XXX it is a v2 querier
    sysctl net.inet.igmp.default_version=2
    sysctl net.inet.igmp.legacysupp=1
    sysctl net.inet.igmp.v2enable=1
181
fi
182
if [ "$DEBUG" = "true" ]; then
183 184 185
   args="-ddD $args"
fi

186 187 188 189
opts=""
if [ -n "$MCBASEADDR" ]; then
    opts="-O mcaddr=$MCBASEADDR"
fi
190 191 192 193 194 195 196 197 198 199 200 201 202 203
if [ -n "$MCBASEPORT" ]; then
    if [ -z "$opts" ]; then
	opts="-O mcportbase=$MCBASEPORT"
    else
	opts="$opts,mcportbase=$MCBASEPORT"
    fi
fi
if [ -n "$MCNUMPORT" ]; then
    if [ -z "$opts" ]; then
	opts="-O mcportnum=$MCNUMPORT"
    else
	opts="$opts,mcportnum=$MCNUMPORT"
    fi
fi
204 205 206 207 208 209 210
if [ -n "$BANDWIDTH" ]; then
    if [ -z "$opts" ]; then
	opts="-O bandwidth=$BANDWIDTH"
    else
	opts="$opts,bandwidth=$BANDWIDTH"
    fi
fi
211 212 213 214 215 216 217 218 219 220 221 222 223 224
if [ -n "$DYNAMICBW" ]; then
    if [ -z "$opts" ]; then
	opts="-O dynamicbw=$DYNAMICBW"
    else
	opts="$opts,dynamicbw=$DYNAMICBW"
    fi
fi
if [ -n "$MAXLINGER" ]; then
    if [ -z "$opts" ]; then
	opts="-O maxlinger=$MAXLINGER"
    else
	opts="$opts,maxlinger=$MAXLINGER"
    fi
fi
225 226 227 228
if [ -n "$CLIENTREPORT" ]; then
    str="report=$CLIENTREPORT"
    if [ -n "$EVENTSERVER" ]; then
	str="$str,eventserver=$EVENTSERVER"
229 230 231 232 233 234 235 236
    fi
    if [ -z "$opts" ]; then
	opts="-O $str"
    else
	opts="$opts,$str"
    fi
fi

237
if [ "$DEBUG" != "true" -a -x @prefix@/sbin/daemon_wrapper ]; then
238
    @prefix@/sbin/daemon_wrapper -i 30 -l @prefix@/log/mfrisbeed_wrapper.log \
239
	@prefix@/sbin/mfrisbeed -d $args $opts
240
else
241
    @prefix@/sbin/mfrisbeed $args $opts
242 243 244
fi

exit $?