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/>.
20 ##BEGIN-INSTALLDIR-MAGIC##
21 # There are better ways of doing this but not if you still want to be
22 # able to run straight out of a git tree. :-)
24 installdir="`dirname \"$0\"`"
26 autocluster=`which $0`
27 installdir="`dirname \"$autocluster\"`"
29 ##END-INSTALLDIR-MAGIC##
36 Usage: autocluster [OPTION] ... <COMMAND>
38 -c <file> specify config file (default is "config")
41 releases=$(list_releases)
44 defconf "WITH_RELEASE" "" \
45 "<string>" "specify preset options for a release using a version string. Possible values are: ${releases}."
48 -e <expr> execute <expr> and exit (advanced debugging)
49 -x enable script debugging
50 --dump dump config settings and exit
52 configuration options:
63 create cluster CLUSTERNAME
66 create node CLUSTERNAME IP_OFFSET
67 (re)create a single cluster node
70 mount a qemu disk on mnt/
73 unmount a qemu disk from mnt/
84 ###############################
87 fill_text 0 "ERROR: $*" >&2
91 ###############################
93 # Indirectly call a function named by ${1}_${2}
95 local func="$1" ; shift
96 local type="$1" ; shift
98 local f="${func}_${type}"
99 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
103 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
106 die "No function defined for \"${func}\" \"${type}\""
111 # Note that this will work if you pass "call_func f" because the first
112 # element of the node tuple is the node type. Nice... :-)
117 "$@" $(IFS=: ; echo $n)
121 hack_one_node_with ()
123 local filter="$1" ; shift
132 local item="${node_type}:${ip_offset}${name:+:}${name}${ctdb_node:+:}${ctdb_node}"
133 nodes="${nodes}${nodes:+ }${item}"
136 # This also gets used for non-filtering iteration.
137 hack_all_nodes_with ()
142 for_each_node hack_one_node_with "$filter"
151 eval "$hook_var=\"${!hook_var}${!hook_var:+ }${new_hook}\""
159 for i in ${!hook_var} ; do
164 ##############################
166 # common node creation stuff
167 create_node_COMMON ()
172 local template_file="${4:-$NODE_TEMPLATE}"
174 if [ "$SYSTEM_DISK_FORMAT" = "raw" -a "$BASE_FORMAT" != "raw" ] ; then
175 die "Error: if SYSTEM_DISK_FORMAT is \"raw\" then BASE_FORMAT must also be \"raw\"."
178 IPNUM=$(($FIRSTIP + $ip_offset))
179 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}"
180 local base_disk="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}"
182 mkdir -p $VIRTBASE/$CLUSTER tmp
184 echo "Creating the disk"
186 case "$SYSTEM_DISK_FORMAT" in
188 qemu-img create -b "$base_disk" -f qcow2 "$DISK"
189 create_node_configure_image "$DISK" "$type"
192 cp -v --sparse=always "$base_disk" "$DISK"
193 create_node_configure_image "$DISK" "$type"
196 echo "Skipping disk image creation as requested"
199 die "Error: unknown SYSTEM_DISK_FORMAT=\"${SYSTEM_DISK_FORMAT}\"."
202 set_macaddrs $CLUSTER $ip_offset
205 echo "Creating $NAME.xml"
206 substitute_vars $template_file tmp/$NAME.xml
208 # install the XML file
209 $VIRSH undefine $NAME > /dev/null 2>&1 || true
210 $VIRSH define tmp/$NAME.xml
213 create_node_configure_image ()
224 # Provides an easy way of removing nodes from $NODE.
225 create_node_null () {
229 ##############################
231 hack_nodes_functions=
234 # Expand out any abbreviations in NODES.
243 for i in ${ips//,/ } ; do
244 ns="${ns}${ns:+ }${t}:${i}"
249 for i in $(seq ${ips/-/ }) ; do
250 ns="${ns}${ns:+ }${t}:${i}"
254 ns="${ns}${ns:+ }${n}"
259 # Apply nodes hacks. Some of this is about backward compatibility
260 # but the hacks also fill in the node names and whether they're
261 # part of the CTDB cluster. The order is the order that
262 # configuration modules register their hacks.
263 run_hooks hack_nodes_functions
265 if [ -n "$NUMNODES" ] ; then
266 # Attempt to respect NUMNODES. Reduce the number of CTDB
268 local numnodes=$NUMNODES
272 if [ "$ctdb_node" = 1 ] ; then
273 if [ $numnodes -gt 0 ] ; then
274 numnodes=$(($numnodes - 1))
282 hack_all_nodes_with hack_filter
284 [ $numnodes -gt 0 ] && \
285 die "Can't not use NUMNODES to increase the number of nodes over that specified by NODES. You need to set NODES instead - please read the documentation."
288 # Check IP addresses for duplicates.
290 # This function doesn't modify anything...
293 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
294 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
295 ip_offsets="${ip_offsets}${ip_offset}:"
297 hack_all_nodes_with get_ip_offset
300 ##############################
302 sanity_check_cluster_name ()
304 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
305 die "Cluster names should be restricted to the characters A-Za-z0-9. \
306 Some cluster filesystems have problems with other characters."
309 common_nodelist_hacking ()
311 # Rework the NODES list
314 # Build /etc/hosts and hack the names of the ctdb nodes
315 hosts_line_hack_name ()
317 # Ignore nodes without names (e.g. "null")
318 [ "$node_type" != "null" -a -n "$name" ] || return 0
322 local ip_addr="$IPBASE.0.$(($FIRSTIP + $ip_offset))"
324 if [ "$ctdb_node" = 1 ] ; then
325 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
326 sname="${CLUSTER}n${num_ctdb_nodes}"
327 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
330 hosts_line="$ip_addr ${name}.${ld} $name"
333 # This allows you to add a function to your configuration file
334 # to modify hostnames (and other aspects of nodes). This
335 # function can access/modify $name (the existing name),
336 # $node_type and $ctdb_node (1, if the node is a member of the
337 # CTDB cluster, 0 otherwise).
338 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
339 local old_name="$name"
340 $HOSTNAME_HACKING_FUNCTION
341 if [ "$name" != "$old_name" ] ; then
342 hosts_line="$ip_addr ${name}.${ld} $name"
348 hosts_file="tmp/hosts.$CLUSTER"
350 local num_ctdb_nodes=0
351 local ld=$(echo $DOMAIN | tr A-Z a-z)
352 echo "# autocluster $CLUSTER"
353 hack_all_nodes_with hosts_line_hack_name
357 # Build /etc/ctdb/nodes
360 [ "$ctdb_node" = 1 ] || return 0
361 echo "$IPBASE.0.$(($FIRSTIP + $ip_offset))"
362 num_nodes=$(($num_nodes + 1))
364 nodes_file="tmp/nodes.$CLUSTER"
366 hack_all_nodes_with ctdb_nodes_line >$nodes_file
367 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
370 create_cluster_hooks=
371 cluster_created_hooks=
377 sanity_check_cluster_name
379 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
381 # Run hooks before doing anything else.
382 run_hooks create_cluster_hooks
384 common_nodelist_hacking
386 for_each_node call_func create_node
388 echo "Cluster $CLUSTER created"
389 echo "You may want to add this to your /etc/hosts file:"
392 run_hooks cluster_created_hooks
398 local single_node_ip_offset="$2"
400 sanity_check_cluster_name
402 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
404 common_nodelist_hacking
407 set -- $(IFS=: ; echo $n)
408 [ $single_node_ip_offset -eq $2 ] || continue
409 call_func create_node "$@"
411 echo "Requested node created"
412 echo "You may want to update your /etc/hosts file:"
419 ###############################
420 # test the proxy setup
422 export http_proxy=$WEBPROXY
423 wget -O /dev/null $INSTALL_SERVER || \
424 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
433 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
437 echo "Testing WEBPROXY $WEBPROXY"
440 echo "Creating the disk"
441 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
444 mkdir -p mnt tmp tmp/ISO
448 echo "Creating kickstart file from template"
449 substitute_vars "$KICKSTART" "tmp/ks.cfg"
451 if [ $INSTALLKEY = "--skip" ]; then
453 --------------------------------------------------------------------------------------
454 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
456 Please enter a valid RHEL install key in your config file like this:
458 INSTALLKEY="1234-5678-0123-4567"
460 The install will continue without an install key in 5 seconds
461 --------------------------------------------------------------------------------------
466 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
469 (*) ISO="${ISO_DIR}/${ISO}"
472 echo "Creating kickstart floppy"
473 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
474 mkdosfs tmp/floppy.img
475 mount -o loop -t msdos tmp/floppy.img mnt
477 mount -o loop,ro $ISO tmp/ISO
479 echo "Setting up bootloader"
480 cp tmp/ISO/isolinux/isolinux.bin tmp
481 cp tmp/ISO/isolinux/vmlinuz tmp
482 cp tmp/ISO/isolinux/initrd.img tmp
488 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
490 rm -f $KVMLOG/serial.$NAME
492 # boot the install CD
493 $VIRSH create tmp/$NAME.xml
495 echo "Waiting for install to start"
498 # wait for the install to finish
499 if ! waitfor $KVMLOG/serial.$NAME "you may safely reboot your system" $CREATE_BASE_TIMEOUT ; then
501 die "Failed to create base image $DISK"
509 Install finished, base image $DISK created
513 To ensure that this image does not change
515 Note that the root password has been set to $ROOTPASSWORD
520 ###############################
526 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
540 echo "Creating $NAME.xml"
541 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
543 # boot the base system
544 $VIRSH create tmp/$NAME.xml
547 ######################################################################
549 # various functions...
551 # Set some MAC address variables based on a hash of the cluster name
552 # plus the node number and each adapter number.
557 local md5=$(echo $cname | md5sum)
558 local nh=$(printf "%02x" $ip_offset)
559 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
561 MAC1="${mac_prefix}01"
562 MAC2="${mac_prefix}02"
563 MAC3="${mac_prefix}03"
564 MAC4="${mac_prefix}04"
565 MAC5="${mac_prefix}05"
566 MAC6="${mac_prefix}06"
569 # mount a qemu image via nbd
571 echo "Connecting nbd to $1"
574 killall -9 -q $QEMU_NBD || true
575 $QEMU_NBD -p 1300 $1 &
577 [ -r $NBD_DEVICE ] || {
578 mknod $NBD_DEVICE b 43 0
580 umount mnt 2> /dev/null || true
581 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
582 killall -9 -q nbd-client || true
583 nbd-client localhost 1300 $NBD_DEVICE > /dev/null 2>&1 || true &
589 echo "Disconnecting nbd"
591 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
592 killall -9 -q nbd-client || true
593 killall -q $QEMU_NBD || true
600 case "$SYSTEM_DISK_FORMAT" in
604 extra_mount_options=""
608 extra_mount_options=",loop"
611 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
617 case "$SYSTEM_DISK_FORMAT" in
625 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
629 # mount a qemu image via nbd
634 local device extra_mount_options
638 echo "Mounting disk $disk"
641 for i in $(seq 1 5); do
642 mount -o offset=32256${extra_mount_options} $device mnt && {
646 umount mnt 2>/dev/null || true
649 [ $mount_ok = 1 ] || die "Failed to mount $disk"
652 echo "Mounted directory does not look like a root filesystem"
658 # unmount a qemu image
660 echo "Unmounting disk"
662 umount mnt || umount mnt || true
666 # setup the files from $BASE_TEMPLATES/, substituting any variables
667 # based on the config
668 copy_base_dir_substitute_templates ()
672 local d="$BASE_TEMPLATES/$dir"
673 [ -d "$d" ] || return 0
676 for f in $(cd "$d" && find . \! -name '*~') ; do
677 if [ -d "$d/$f" ]; then
680 substitute_vars "$d/$f" "mnt/$f"
682 chmod --reference="$d/$f" "mnt/$f"
693 echo "Copy base files"
694 copy_base_dir_substitute_templates "all"
695 if [ -n "$type" ] ; then
696 copy_base_dir_substitute_templates "$type"
699 # this is needed as git doesn't store file permissions other
701 chmod 600 mnt/etc/ssh/*key mnt/root/.ssh/*
702 chmod 700 mnt/etc/ssh mnt/root/.ssh mnt/root
703 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
704 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
705 cat "$HOME/.ssh/id_rsa.pub" >> mnt/root/.ssh/authorized_keys
707 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
708 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
709 cat "$HOME/.ssh/id_dsa.pub" >> mnt/root/.ssh/authorized_keys
711 echo "Adjusting grub.conf"
712 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
713 sed -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
714 -e "s/ nodmraid//" -e "s/ nompath//" \
715 -e "s/quiet/noapic divider=10${o:+ }${o}/g" mnt/boot/grub/grub.conf -i.org
716 run_hooks setup_base_hooks
719 # setup various networking components
721 echo "Setting up networks"
723 cat $hosts_file >>mnt/etc/hosts
725 echo "Setting up /etc/ctdb/nodes"
726 mkdir -p mnt/etc/ctdb
727 cp $nodes_file mnt/etc/ctdb/nodes
729 [ "$WEBPROXY" = "" ] || {
730 echo "export http_proxy=$WEBPROXY" >> mnt/etc/bashrc
733 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
734 echo "Enabling nfs mount of $NFSSHARE"
735 mkdir -p "mnt$NFS_MOUNTPOINT"
736 echo "$NFSSHARE $NFS_MOUNTPOINT nfs intr" >> mnt/etc/fstab
739 mkdir -p mnt/etc/yum.repos.d
740 echo '@@@YUM_TEMPLATE@@@' | substitute_vars - > mnt/etc/yum.repos.d/autocluster.repo
744 [ -z "$TIMEZONE" ] && {
745 [ -r /etc/timezone ] && {
746 TIMEZONE=`cat /etc/timezone`
748 [ -r /etc/sysconfig/clock ] && {
749 . /etc/sysconfig/clock
752 TIMEZONE="${TIMEZONE// /_}"
754 [ -n "$TIMEZONE" ] || \
755 die "Unable to determine TIMEZONE - please set in config"
758 # substite a set of variables of the form @@XX@@ for the shell
759 # variables $XX in a file.
761 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
762 # contain a filename whose contents are substituted, with variable
763 # substitution applied to those contents. If filename starts with '|'
764 # it is a command instead - however, quoting is extremely fragile.
766 infile="${1:-/dev/null}" # if empty then default to /dev/null
767 outfile="$2" # optional
769 instring=$(cat $infile)
771 # Handle any indirects by looping until nothing changes.
772 # However, only handle 10 levels of recursion.
775 outstring=$(_substitute_vars "$instring" "@@@")
776 [ $? -eq 0 ] || die "Failed to expand template $infile"
778 [ "$instring" = "$outstring" ] && break
780 count=$(($count + 1))
781 [ $count -lt 10 ] || \
782 die "Recursion too deep in $infile - only 10 levels allowed!"
784 instring="$outstring"
787 # Now regular variables.
788 outstring=$(_substitute_vars "$instring" "@@")
789 [ $? -eq 0 ] || die "Failed to expand template $infile"
791 if [ -n "$outfile" ] ; then
792 echo "$outstring" > "$outfile"
799 # Delimiter @@ means to substitute contents of variable.
800 # Delimiter @@@ means to substitute contents of file named by variable.
801 # @@@ supports leading '|' in variable value, which means to excute a
803 _substitute_vars() {(
807 # get the list of variables used in the template
808 VARS=`echo "$instring" |
809 tr -cs "A-Z0-9_$delimiter" '\012' |
811 sed -n -e "s#^${delimiter}\(.*\)${delimiter}\\$#\1#p"`
815 # variable variables are fun .....
818 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
822 if [ "$delimiter" = "@@@" ] ; then
824 c="${f#|}" # Is is a command, signified by a leading '|'?
825 if [ "$c" = "$f" ] ; then
826 # No leading '|', cat file.
830 die "Could not substitute contents of file $f"
833 # Leading '|', execute command.
834 # Quoting problems here - using eval "$c" doesn't help.
838 die "Could not execute command $c"
843 # escape some pesky chars
848 echo "s#${delimiter}${v}${delimiter}#${s}#g"
851 echo "$instring" | sed -f $tmp
857 which $1 > /dev/null || die "Please install $1 to continue"
860 # Set a variable if it isn't already set. This allows environment
861 # variables to override default config settings.
866 [ "${!v+x}" ] || eval "$v=\"$e\""
872 for i in "${installdir}/config.d/"*.defconf ; do
877 # Print the list of config variables defined in config.d/.
878 get_config_options () {( # sub-shell for local declaration of defconf()
880 defconf() { options="$options $1" ; }
885 # Produce a list of long options, suitable for use with getopt, that
886 # represent the config variables defined in config.d/.
887 getopt_config_options () {
888 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
892 # Unconditionally set the config variable associated with the given
898 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
899 # unset so defconf will set it
904 # Dump all of the current config variables.
907 for o in $(get_config_options) ; do
908 echo "${o}=\"${!o}\""
913 # $COLUMNS is set in interactive bash shells. It probably isn't set
914 # in this shell, so let's set it if it isn't.
915 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
919 # Print text assuming it starts after other text in $startcol and
920 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
921 # Long "words" will extend past $COLUMNS - 2.
926 local width=$(($COLUMNS - 2 - $startcol))
927 [ $width -lt 0 ] && width=$((78 - $startcol))
932 if [ $startcol -gt 0 ] ; then
933 padding=$(printf "\n%${startcol}s" " ")
939 while [ -n "$text" ] ; do
942 # If we already have output then arrange padding on the next line.
943 [ -n "$out" ] && out="${out}${padding}"
945 # Break the text at $width.
946 out="${out}${text:0:${width}}"
947 text="${text:${width}}"
949 # If we have left over text then the line break may be ugly,
950 # so let's check and try to break it on a space.
951 if [ -n "$text" ] ; then
952 # The 'x's stop us producing a special character like '(',
953 # ')' or '!'. Yuck - there must be a better way.
954 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
955 # We didn't break on a space. Arrange for the
956 # beginning of the broken "word" to appear on the next
957 # line but not if it will make us loop infinitely.
958 if [ "${orig}" != "${out##* }${text}" ] ; then
959 text="${out##* }${text}"
962 # Hmmm, doing that would make us loop, so add the
963 # rest of the word from the remainder of the text
964 # to this line and let it extend past $COLUMNS - 2.
965 out="${out}${text%% *}"
966 if [ "${text# *}" != "$text" ] ; then
967 # Remember the text after the next space for next time.
970 # No text after next space.
975 # We broke on a space. If it will be at the beginning
976 # of the next line then remove it.
985 # Display usage text, trying these approaches in order.
986 # 1. See if it all fits on one line before $COLUMNS - 2.
987 # 2. See if splitting before the default value and indenting it
988 # to $startcol means that nothing passes $COLUMNS - 2.
989 # 3. Treat the message and default value as a string and just us fill_text()
991 usage_display_text () {
996 local width=$(($COLUMNS - 2 - $startcol))
997 [ $width -lt 0 ] && width=$((78 - $startcol))
999 default="(default \"$default\")"
1001 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
1002 echo "${desc} ${default}"
1004 local padding=$(printf "%${startcol}s" " ")
1006 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
1008 echo "${padding}${default}"
1010 fill_text $startcol "${desc} ${default}"
1015 # Display usage information for long config options.
1016 usage_smart_display () {( # sub-shell for local declaration of defconf()
1020 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
1022 printf " --%-25s " "${longopt}=${3}"
1024 usage_display_text $startcol "$4" "$2"
1031 # Display usage information for long config options.
1032 usage_config_options (){
1033 usage_smart_display load_config
1037 local releases=$(cd $installdir/releases && echo *.release)
1038 releases="${releases//.release}"
1039 releases="${releases// /\", \"}"
1040 echo "\"$releases\""
1045 shift # subsequent args are passed to release file
1047 # This simply loads an extra config file from $installdir/releases
1048 f="${installdir}/releases/${release}.release"
1049 if [ -r "$f" ] ; then
1052 f="${installdir}/releases/${release%%-*}.release"
1053 if [ -r "$f" ] ; then
1054 . "$f" "${release#*-}"
1056 echo "Unknown release \"${release}\" specified to --with-release"
1057 printf "%-25s" "Supported releases are: "
1058 fill_text 25 "$(list_releases)"
1065 has_public_addresses_DEFAULT ()
1070 # Build public address configuration.
1071 # * 1st public IP: unless specified, last octet is $FIRSTIP + $PUBLIC_IP_OFFSET
1072 # * Excluded nodes: unless specified via comma-separated list of IP offsets,
1073 # nodes are excluded via their node types
1074 # * Number of public addresses per interface is either specified or $NUMNODES.
1075 make_public_addresses () {
1076 local firstip="${1:-$(($FIRSTIP + $PUBLIC_IP_OFFSET))}"
1077 local excluded_nodes="$2"
1078 local num_addrs="${3:-${NUMNODES}}"
1080 # For delimiting matches.
1081 excluded_nodes="${excluded_nodes:+,}${excluded_nodes}${excluded_nodes:+,}"
1083 excluded_nodes="${excluded_nodes// /}"
1085 make_public_addresses_for_node ()
1087 [ "$ctdb_node" = 1 ] || return 0
1089 echo "[/etc/ctdb/public_addresses:${name}.${DOMAIN}]"
1091 if [ -n "$excluded_nodes" -a \
1092 "${excluded_nodes/,${ip_offset},}" = "$excluded_nodes" ] ||
1093 ([ -z "$excluded_nodes" ] &&
1094 call_func has_public_addresses "$node_type") ; then
1097 for e in "1" "2" ; do
1098 for i in $(seq $firstip $(($firstip + $num_addrs - 1))) ; do
1099 if [ $i -gt 254 ] ; then
1100 die "make_public_addresses: octet > 254 - consider setting PUBLIC_IP_OFFSET"
1102 printf "\t${IPBASE}.${e}.${i}/24 eth${e}\n"
1108 hack_all_nodes_with make_public_addresses_for_node
1111 ######################################################################
1115 ############################
1116 # parse command line options
1117 long_opts=$(getopt_config_options)
1118 getopt_output=$(getopt -n autocluster -o "c:e:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1119 [ $? != 0 ] && usage
1121 use_default_config=true
1123 # We do 2 passes of the options. The first time we just handle usage
1124 # and check whether -c is being used.
1125 eval set -- "$getopt_output"
1128 -c) shift 2 ; use_default_config=false ;;
1130 --) shift ; break ;;
1131 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1133 -h|--help) usage ;; # Usage should be shown here for real defaults.
1134 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1135 *) usage ;; # shouldn't happen, so this is reasonable.
1140 $use_default_config && [ -r "$config" ] && . "$config"
1142 eval set -- "$getopt_output"
1146 # force at least ./local_file to avoid accidental file from $PATH
1147 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1148 -e) eval "$2" ; exit ;;
1153 -x) set -x; shift ;;
1154 --dump) dump_config ;;
1155 --) shift ; break ;;
1156 -h|--help) usage ;; # Redundant.
1158 # Putting --opt1|opt2|... into a variable and having case
1159 # match against it as a pattern doesn't work. The | is
1160 # part of shell syntax, so we need to do this. Look away
1161 # now to stop your eyes from bleeding! :-)
1162 x=",${long_opts}" # Now each option is surrounded by , and :
1163 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1164 # Our option, $1, surrounded by , and : was in $x, so is legal.
1165 setconf_longopt "$1" "$2"; shift 2
1170 *) usage ;; # shouldn't happen, so this is reasonable.
1178 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1181 # check for needed programs
1182 check_command expect
1183 if [ "$SYSTEM_DISK_FORMAT" != "raw" ] ; then
1184 check_command $QEMU_NBD
1185 check_command nbd-client
1188 [ $# -lt 1 ] && usage
1199 [ $# != 0 ] && usage
1203 [ $# != 1 ] && usage
1207 [ $# != 2 ] && usage
1208 create_one_node "$1" "$2"
1216 [ $# != 1 ] && usage
1220 [ $# != 0 ] && usage