rc.frisbee 3.31 KB
Newer Older
1
#!/bin/sh
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
Leigh B. Stoller's avatar
Leigh B. Stoller committed
5
6
7
# All rights reserved.
#

8
9
10
11
12
13
#
# Amount of memory in MB to leave for everyone else in the system.  If you
# get out-of-memory or vm_pager error while running frisbee, increase this.
#
RESIDMEM=32

14
15
16
17
if [ -r /etc/emulab/paths.sh ]; then
	. /etc/emulab/paths.sh
else
	BINDIR=/etc/testbed
18
	BOOTDIR=/etc/testbed
19
fi
20

21
$BINDIR/tmcc state RELOADSETUP
22

23
BOSSINFO=`$BINDIR/tmcc bossinfo`
24
LOADINFO=`$BINDIR/tmcc loadinfo`
25
26
27

# For testing purposes.
#BOSSINFO='boss.emulab.net 155.101.128.70'
Mike Hibler's avatar
Mike Hibler committed
28
#LOADINFO='ADDR=234.5.6.69:4444'
29

30
31
32
33
34
BOSSIP=`echo $BOSSINFO | awk '{ print $2 }'`

# XXX should be part of loadinfo
LOADIP="-S $BOSSIP"

35
if [ -x /usr/sbin/ntpdate ]; then
36
	/usr/sbin/ntpdate -b $BOSSIP >/dev/null 2>&1
37
38
fi

39
ADDRESS=`echo $LOADINFO | awk -F= '{ printf $2 }' | awk -F' ' '{ print $1 }'`
40
PARTITION=`echo $LOADINFO | awk -F= '{ printf $3 }' | awk -F' ' '{ print $1 }'`
Mike Hibler's avatar
Mike Hibler committed
41
PARTITION=${PARTITION:-'0'}
42
PARTOS=`echo $LOADINFO | awk -F= '{ printf $4 }' | awk -F' ' '{ print $1 }'`
43
44
45
DISK=`echo $LOADINFO | awk -F= '{ printf $5 }' | awk -F' ' '{ print $1 }'`
DISK=${DISK:-'ad0'}

Mike Hibler's avatar
Mike Hibler committed
46
if [ "$PARTITION" != "0" ]; then
47
	SLICE="-s $PARTITION"
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	case $PARTOS in
	FreeBSD)
		SLICE="$SLICE -D 165"
		PTYPE=165
		;;
	OpenBSD)
		SLICE="$SLICE -D 166"
		PTYPE=166
		;;
	Linux)
		SLICE="$SLICE -D 131"
		PTYPE=131
		;;
	*)
		;;
	esac
64
65
fi

66
67
68
69
70
# Enable IPoD
if [ -r $BINDIR/rc.ipod ]; then
	. $BINDIR/rc.ipod
fi

71
72
#
# set memory limits:
73
74
#	allow $RESIDMEM MB for non-frisbee stuff
#	split remaining memory (min of 2MB) between network/disk buffering
75
#
76
HOSTMEM=`sysctl -n hw.usermem`
77
78
79
80
81
82
83
84
85
86
87
HOSTMEM=`expr $HOSTMEM / 1048576`
if [ $HOSTMEM -ge `expr $RESIDMEM + 2` ]; then
	HOSTMEM=`expr $HOSTMEM - $RESIDMEM`
	BYTES=`expr $HOSTMEM \* 1024`
	DATASEGSZ=`ulimit -d`
	if [ $BYTES -gt $DATASEGSZ ]; then
	    BYTES=$DATASEGSZ
	    HOSTMEM=`expr $BYTES / 1024`
	    echo "WARNING: kernel limits buffering to $HOSTMEM MB"
	fi
	ulimit -v $BYTES
88
89
90
91
92
93
94
95
96
97
98

	## For GaTech we use more memory for disks since the disks are so slow
	#NETMEM=`expr $HOSTMEM \* 1 / 3`
	#DISKMEM=`expr $HOSTMEM \* 2 / 3`
	#MEMARGS="-C $NETMEM -W $DISKMEM"

	# For Utah, we let the client split up the memory
	# (50/50, but no more chunk buffers than there are chunks in the image)
	MEMARGS="-M $HOSTMEM"
fi

99
if [ x"$ADDRESS" != x ]; then
100
101
        PORT=`echo $ADDRESS | awk -F: '{ printf $2 }'`
	MCAST=`echo $ADDRESS | awk -F: '{ printf $1 }'`
102
103
104
105
106
	if [ -e $BOOTDIR/myip ]; then
		MCASTIF="-i `cat $BOOTDIR/myip`"
	else
		MCASTIF=""
	fi
107
	MCASTADDR="-m $MCAST -p $PORT"
108

109
110
	echo "Running $BINDIR/frisbee $LOADIP $MEMARGS $SLICE $MCASTIF $MCASTADDR /dev/$DISK at `date`"
	$BINDIR/tmcc state RELOADING
111

112
	$BINDIR/frisbee $LOADIP $MEMARGS $SLICE $MCASTIF $MCASTADDR /dev/$DISK
113
114
	case $? in
	0)
115
116
117
		echo "Frisbee run finished"
		echo "Resizing final disk partition"
		$BINDIR/growdisk -vW /dev/$DISK
Mike Hibler's avatar
Mike Hibler committed
118
119
120
121
122
		#
		# XXX limit the use of slicefix for now to just
		# those machines with "ad4" as their root disk
		#
		if [ -x $BINDIR/slicefix -a "$DISK" = "ad4" ]; then
123
			echo "Adjusting slice-related files";
Mike Hibler's avatar
Mike Hibler committed
124
			$BINDIR/slicefix $PARTITION $DISK
125
		fi
126
127
128
129
		echo "Image load complete, rebooting ..."
		$BINDIR/tmcc state RELOADDONE
		/sbin/reboot
		sleep 100
130
131
132
133
134
		;;
	*)
		echo "Frisbee run failed, status $?"
		;;
	esac
135
136
137
else
	echo "Unable to get address for loading image"
fi
138
echo "Failed to load disk, dropping to login prompt"