2 # main autocluster script
4 # Copyright (C) Andrew Tridgell 2008
5 # Copyright (C) Martin Schwenke 2008
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, see <http://www.gnu.org/licenses/>.
21 installdir="`dirname \"$0\"`"
23 autocluster=`which $0`
24 installdir="`dirname \"$autocluster\"`"
32 Usage: autocluster [OPTION] ... <COMMAND>
34 -c <file> specify config file (default is "config")
35 -x enable script debugging
36 --dump dump config settings and exit
38 configuration options:
49 create cluster CLUSTERNAME
52 create node CLUSTERNAME NODENUMBER
53 create one cluster node
55 create tsm CLUSTERNAME
56 create a TSM server node
59 mount a qemu disk on mnt/
62 unmount a qemu disk from mnt/
74 ###############################
75 # create a single node
79 NAME="$CLUSTER""n$NODENUMBER"
80 BASE="$VIRTBASE/$BASENAME.img"
81 DISK="$VIRTBASE/$CLUSTER/$NAME.qcow2"
84 # first node might need more memory for SoFS GUI
85 if [ $NODENUMBER = 1 -a $GUIMEM -gt $MEM ]; then
90 echo "Creating cluster node $NAME"
92 mkdir -p $VIRTBASE/$CLUSTER
94 echo "Creating the disk"
96 qemu-img create -b "$BASE" -f qcow2 "$DISK"
98 IPNUM=`expr $FIRSTIP + $NODENUMBER`
107 MAC1=`get_macaddr $CLUSTER $NODENUMBER 1`
108 MAC2=`get_macaddr $CLUSTER $NODENUMBER 2`
109 MAC3=`get_macaddr $CLUSTER $NODENUMBER 3`
112 echo "Creating $NAME.xml"
113 substitute_vars $NODE_TEMPLATE tmp/$NAME.xml
115 # install the XML file
116 $VIRSH undefine $NAME > /dev/null 2>&1 || true
117 $VIRSH define tmp/$NAME.xml
121 ###############################
126 BASE="$VIRTBASE/$BASENAME.img"
127 DISK="$VIRTBASE/$CLUSTER/$NAME.qcow2"
128 TSMDISK="$VIRTBASE/$CLUSTER/tsmstorage.qcow2"
130 echo "Creating TSM cluster node $NAME"
132 mkdir -p $VIRTBASE/$CLUSTER tmp
134 echo "Creating the disk"
136 qemu-img create -b "$BASE" -f qcow2 "$DISK"
138 echo "Creating tsm disk"
139 qemu-img create -f qcow2 "$TSMDISK" $TSMDISKSIZE
141 # TSM server is first IP in the cluster
150 MAC1=`get_macaddr $CLUSTER 0 0`
152 echo "Creating $NAME.xml"
153 substitute_vars $TSM_TEMPLATE tmp/$NAME.xml
155 # install the XML file
156 $VIRSH undefine $NAME > /dev/null 2>&1 || true
157 $VIRSH define tmp/$NAME.xml
161 ###############################
162 # create a whole cluster
166 mkdir -p $VIRTBASE/$CLUSTER tmp
169 echo "Creating 3 shared disks"
170 for i in `seq 1 3`; do
171 # setup a nice ID at the start of the disk
172 qemu-img create -f raw $VIRTBASE/$CLUSTER/shared$i $SHAREDDISKSIZE
173 echo "SOFS-`uuidgen`" > tmp/diskid
174 dd if=tmp/diskid of=$VIRTBASE/$CLUSTER/shared$i conv=notrunc bs=1 > /dev/null 2>&1
177 echo "Creating $NUMNODES base nodes"
178 for i in `seq 1 $NUMNODES`; do
179 create_node "$CLUSTER" $i
182 if [ $WITH_TSM_NODE -eq 1 ]; then
183 echo "Creating TSM server node"
184 create_tsm "$CLUSTER"
187 echo "# autocluster $CLUSTER" > hosts.$CLUSTER
188 [ $WITH_TSM_NODE -eq 1 ] && {
189 echo "$IPBASE.0.$FIRSTIP ${CLUSTER}tsm.$LOWDOMAIN ${CLUSTER}tsm" >> hosts.$CLUSTER
191 for i in `seq 1 $NUMNODES`; do
192 echo "$IPBASE.0.`expr $FIRSTIP + $i` ${CLUSTER}n$i.$LOWDOMAIN ${CLUSTER}n$i" >> hosts.$CLUSTER
194 echo >> hosts.$CLUSTER
196 echo "Cluster $CLUSTER created"
197 echo "You may want to add this to your /etc/hosts file:"
203 ###############################
204 # test the proxy setup
206 export http_proxy=$WEBPROXY
207 wget -O /dev/null $INSTALL_SERVER || {
208 echo "Your WEBPROXY setting \"$WEBPROXY\" is not working"
220 DISK="$VIRTBASE/$NAME.img"
224 echo "Testing WEBPROXY $WEBPROXY"
227 echo "Creating the disk"
228 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
231 mkdir -p mnt tmp tmp/ISO
236 echo "Creating kickstart file from template"
237 substitute_vars "$KICKSTART" "tmp/ks.cfg"
239 if [ $INSTALLKEY = "--skip" ]; then
241 --------------------------------------------------------------------------------------
242 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
244 Please enter a valid RHEL install key in your config file like this:
246 INSTALLKEY="1234-5678-0123-4567"
248 The install will continue without an install key in 5 seconds
249 --------------------------------------------------------------------------------------
254 echo "Creating kickstart floppy"
255 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
256 mkdosfs tmp/floppy.img
257 mount -o loop -t msdos tmp/floppy.img mnt
259 mount -o loop,ro $ISO tmp/ISO
261 echo "Setting up bootloader"
262 cp tmp/ISO/isolinux/isolinux.bin tmp
263 cp tmp/ISO/isolinux/vmlinuz tmp
264 cp tmp/ISO/isolinux/initrd.img tmp
270 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
272 rm -f $KVMLOG/serial.$NAME
274 # boot the install CD
275 $VIRSH create tmp/$NAME.xml
277 echo "Waiting for install to start"
280 # wait for the install to finish
281 if ! waitfor $KVMLOG/serial.$NAME "you may safely reboot your system" 3600; then
283 echo "Failed to create base image $DISK"
292 Install finished, base image $DISK created
296 To ensure that this image does not change
298 Note that the root password has been set to $ROOTPASSWORD
305 ###############################
311 DISK="$VIRTBASE/$NAME.img"
325 echo "Creating $NAME.xml"
326 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
328 # boot the base system
329 $VIRSH create tmp/$NAME.xml
332 ######################################################################
334 . "$installdir/functions"
335 . "$installdir/config.default"
337 ############################
338 # parse command line options
339 long_opts=$(getopt_config_options)
340 getopt_output=$(getopt -n autocluster -o "c:xh" -l help,dump -l "$long_opts" -- "$@")
343 use_default_config=true
345 # We 2 passes of the options. The first time we just handle usage and
346 # check whether -c is being used.
347 eval set -- "$getopt_output"
350 -c) shift 2 ; use_default_config=false ;;
353 -h|--help) usage ;; # Usage should be shown here for real defaults.
354 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
355 *) usage ;; # shouldn't happen, so this is reasonable.
360 $use_default_config && [ -r "$config" ] && . "$config"
362 eval set -- "$getopt_output"
366 -c) . "`dirname $2`/$2" ; shift 2 ; conf_done=true ;;
368 --dump) dump_config ;;
370 -h|--help) usage ;; # Redundant.
372 # Putting --opt1|opt2|... into a variable and having case
373 # match against it as a pattern doesn't work. The | is
374 # part of shell syntax, so we need to do this. Look away
375 # now to stop your eyes from bleeding! :-)
376 x=",${long_opts}" # Now each option is surrounded by , and :
377 if [ "$x" != "${x#*,${1#--}:}" ] ; then
378 # Our option, $1, surrounded by , and : was in $x, so is legal.
379 setconf_longopt "$1" "$2"; shift 2
384 *) usage ;; # shouldn't happen, so this is reasonable.
392 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
395 LOWDOMAIN=`echo $DOMAIN | tr A-Z a-z`
397 # check for needed programs
398 check_command nbd-client
400 check_command $QEMU_NBD
402 [ $# -lt 1 ] && usage
422 create_node "$1" "$2";