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
49 -E <expr> execute <expr> and continue
50 -x enable script debugging
51 --dump dump config settings and exit
53 configuration options:
64 create cluster CLUSTERNAME
67 create node CLUSTERNAME IP_OFFSET
68 (re)create a single cluster node
71 mount a qemu disk on mnt/
74 unmount a qemu disk from mnt/
85 ###############################
88 fill_text 0 "ERROR: $*" >&2
92 ###############################
94 # Indirectly call a function named by ${1}_${2}
96 local func="$1" ; shift
97 local type="$1" ; shift
99 local f="${func}_${type}"
100 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
104 if type -t "$f" >/dev/null && ! type -P "$f" >/dev/null ; then
107 die "No function defined for \"${func}\" \"${type}\""
112 # Note that this will work if you pass "call_func f" because the first
113 # element of the node tuple is the node type. Nice... :-)
118 "$@" $(IFS=: ; echo $n)
122 hack_one_node_with ()
124 local filter="$1" ; shift
133 local item="${node_type}:${ip_offset}${name:+:}${name}${ctdb_node:+:}${ctdb_node}"
134 nodes="${nodes}${nodes:+ }${item}"
137 # This also gets used for non-filtering iteration.
138 hack_all_nodes_with ()
143 for_each_node hack_one_node_with "$filter"
152 eval "$hook_var=\"${!hook_var}${!hook_var:+ }${new_hook}\""
160 for i in ${!hook_var} ; do
165 # Use with care, since this may clear some autocluster defaults.!
170 eval "$hook_var=\"\""
173 ##############################
175 # common node creation stuff
176 create_node_COMMON ()
181 local template_file="${4:-$NODE_TEMPLATE}"
183 if [ "$SYSTEM_DISK_FORMAT" != "qcow2" -a "$BASE_FORMAT" = "qcow2" ] ; then
184 die "Error: if BASE_FORMAT is \"qcow2\" then SYSTEM_DISK_FORMAT must also be \"qcow2\"."
187 IPNUM=$(($FIRSTIP + $ip_offset))
188 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}"
189 local base_disk="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}"
191 if [ "$BASE_PER_NODE_TYPE" = "yes" ] ; then
192 base_disk="${VIRTBASE}/${BASENAME}-${type}.${BASE_FORMAT}"
195 mkdir -p $VIRTBASE/$CLUSTER tmp
198 case "$SYSTEM_DISK_FORMAT" in
200 echo "Creating the disk..."
201 qemu-img create -b "$base_disk" -f qcow2 "$DISK"
202 create_node_configure_image "$DISK" "$type"
205 echo "Creating the disk..."
206 cp -v --sparse=always "$base_disk" "$DISK"
207 create_node_configure_image "$DISK" "$type"
210 echo "Creating the disk..."
211 cp -v --reflink=always "$base_disk" "$DISK"
212 create_node_configure_image "$DISK" "$type"
215 echo "Skipping disk image creation as requested"
218 die "Error: unknown SYSTEM_DISK_FORMAT=\"${SYSTEM_DISK_FORMAT}\"."
221 set_macaddrs $CLUSTER $ip_offset
223 # Pull the UUID for this node out of the map.
224 UUID=$(awk "\$1 == $ip_offset {print \$2}" $uuid_map)
226 echo "Creating $NAME.xml"
227 substitute_vars $template_file tmp/$NAME.xml
229 # install the XML file
230 $VIRSH undefine $NAME > /dev/null 2>&1 || true
231 $VIRSH define tmp/$NAME.xml
234 create_node_configure_image ()
239 diskimage_mount "$disk"
244 # Provides an easy way of removing nodes from $NODE.
245 create_node_null () {
249 ##############################
251 hack_nodes_functions=
254 # Expand out any abbreviations in NODES.
263 for i in ${ips//,/ } ; do
264 ns="${ns}${ns:+ }${t}:${i}"
269 for i in $(seq ${ips/-/ }) ; do
270 ns="${ns}${ns:+ }${t}:${i}"
274 ns="${ns}${ns:+ }${n}"
279 # Apply nodes hacks. Some of this is about backward compatibility
280 # but the hacks also fill in the node names and whether they're
281 # part of the CTDB cluster. The order is the order that
282 # configuration modules register their hacks.
283 run_hooks hack_nodes_functions
285 if [ -n "$NUMNODES" ] ; then
286 # Attempt to respect NUMNODES. Reduce the number of CTDB
288 local numnodes=$NUMNODES
292 if [ "$ctdb_node" = 1 ] ; then
293 if [ $numnodes -gt 0 ] ; then
294 numnodes=$(($numnodes - 1))
302 hack_all_nodes_with hack_filter
304 [ $numnodes -gt 0 ] && \
305 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."
308 # Check IP addresses for duplicates.
310 # This function doesn't modify anything...
313 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
314 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
315 ip_offsets="${ip_offsets}${ip_offset}:"
317 hack_all_nodes_with get_ip_offset
320 ##############################
322 sanity_check_cluster_name ()
324 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
325 die "Cluster names should be restricted to the characters A-Za-z0-9. \
326 Some cluster filesystems have problems with other characters."
331 common_nodelist_hacking ()
333 # Rework the NODES list
336 # Build /etc/hosts and hack the names of the ctdb nodes
337 hosts_line_hack_name ()
339 # Ignore nodes without names (e.g. "null")
340 [ "$node_type" != "null" -a -n "$name" ] || return 0
344 local ip_addr="$IPBASE.$IPNET0.$(($FIRSTIP + $ip_offset))"
346 if [ "$ctdb_node" = 1 ] ; then
347 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
348 sname="${CLUSTER}n${num_ctdb_nodes}"
349 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
352 hosts_line="$ip_addr ${name}.${ld} $name"
355 # This allows you to add a function to your configuration file
356 # to modify hostnames (and other aspects of nodes). This
357 # function can access/modify $name (the existing name),
358 # $node_type and $ctdb_node (1, if the node is a member of the
359 # CTDB cluster, 0 otherwise).
360 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
361 local old_name="$name"
362 $HOSTNAME_HACKING_FUNCTION
363 if [ "$name" != "$old_name" ] ; then
364 hosts_line="$ip_addr ${name}.${ld} $name"
370 hosts_file="tmp/hosts.$CLUSTER"
372 local num_ctdb_nodes=0
373 local ld=$(echo $DOMAIN | tr A-Z a-z)
374 echo "# autocluster $CLUSTER"
375 hack_all_nodes_with hosts_line_hack_name
379 # Build /etc/ctdb/nodes
382 [ "$ctdb_node" = 1 ] || return 0
383 echo "$IPBASE.$IPNET0.$(($FIRSTIP + $ip_offset))"
384 num_nodes=$(($num_nodes + 1))
386 nodes_file="tmp/nodes.$CLUSTER"
388 hack_all_nodes_with ctdb_nodes_line >$nodes_file
389 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
392 uuid_map="tmp/uuid_map.$CLUSTER"
395 echo "${ip_offset} $(uuidgen) ${node_type}"
397 hack_all_nodes_with uuid_map_line >$uuid_map
400 create_cluster_hooks=
401 cluster_created_hooks=
407 sanity_check_cluster_name
409 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
411 # Run hooks before doing anything else.
412 run_hooks create_cluster_hooks
414 common_nodelist_hacking
416 for_each_node call_func create_node
418 echo "Cluster $CLUSTER created"
421 run_hooks cluster_created_hooks
424 cluster_created_hosts_message ()
426 echo "You may want to add this to your /etc/hosts file:"
430 register_hook cluster_created_hooks cluster_created_hosts_message
435 local single_node_ip_offset="$2"
437 sanity_check_cluster_name
439 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
441 common_nodelist_hacking
444 set -- $(IFS=: ; echo $n)
445 [ $single_node_ip_offset -eq $2 ] || continue
446 call_func create_node "$@"
448 echo "Requested node created"
450 echo "You may want to update your /etc/hosts file:"
457 ###############################
458 # test the proxy setup
460 export http_proxy=$WEBPROXY
461 wget -O /dev/null $INSTALL_SERVER || \
462 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
468 kickstart_floppy_create_hooks=
474 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
478 echo "Testing WEBPROXY $WEBPROXY"
481 echo "Creating the disk"
482 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
485 mkdir -p mnt tmp tmp/ISO
489 echo "Creating kickstart file from template"
490 substitute_vars "$KICKSTART" "tmp/ks.cfg"
492 if [ $INSTALLKEY = "--skip" ]; then
494 --------------------------------------------------------------------------------------
495 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
497 Please enter a valid RHEL install key in your config file like this:
499 INSTALLKEY="1234-5678-0123-4567"
501 The install will continue without an install key in 5 seconds
502 --------------------------------------------------------------------------------------
507 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
510 (*) ISO="${ISO_DIR}/${ISO}"
513 echo "Creating kickstart floppy"
514 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
515 mkdosfs tmp/floppy.img
516 mount -o loop -t msdos tmp/floppy.img mnt
518 mount -o loop,ro $ISO tmp/ISO
520 echo "Setting up bootloader"
521 cp tmp/ISO/isolinux/isolinux.bin tmp
522 cp tmp/ISO/isolinux/vmlinuz tmp
523 cp tmp/ISO/isolinux/initrd.img tmp
525 run_hooks kickstart_floppy_create_hooks
532 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
534 rm -f $KVMLOG/serial.$NAME
536 # boot the install CD
537 $VIRSH create tmp/$NAME.xml
539 echo "Waiting for install to start"
542 # wait for the install to finish
543 if ! waitfor $KVMLOG/serial.$NAME "$KS_DONE_MESSAGE" $CREATE_BASE_TIMEOUT ; then
545 die "Failed to create base image ${DISK} after waiting for ${CREATE_BASE_TIMEOUT} seconds.
546 You may need to increase the value of CREATE_BASE_TIMEOUT.
547 Alternatively, the install might have completed but KS_DONE_MESSAGE
548 (currently \"${KS_DONE_MESSAGE}\")
549 may not have matched anything at the end of the kickstart output."
557 Install finished, base image $DISK created
561 To ensure that this image does not change
563 Note that the root password has been set to $ROOTPASSWORD
568 ###############################
574 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
582 diskimage_mount $DISK
588 echo "Creating $NAME.xml"
589 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
591 # boot the base system
592 $VIRSH create tmp/$NAME.xml
595 ######################################################################
597 # various functions...
599 # Set some MAC address variables based on a hash of the cluster name
600 # plus the node number and each adapter number.
605 local md5=$(echo $cname | md5sum)
606 local nh=$(printf "%02x" $ip_offset)
607 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
609 MAC1="${mac_prefix}01"
610 MAC2="${mac_prefix}02"
611 MAC3="${mac_prefix}03"
612 MAC4="${mac_prefix}04"
613 MAC5="${mac_prefix}05"
614 MAC6="${mac_prefix}06"
617 ######################################################################
619 # Updating a disk image...
621 make_system_disk_access_function ()
623 eval "$1 () { call_func $1 \"\$SYSTEM_DISK_ACCESS_METHOD\" \"\$@\" ; }"
628 mkdir_p substitute_vars chmod chmod_reference \
629 is_directory is_file append_text_file append_text sed put ln_s grep \
632 make_system_disk_access_function "diskimage_$i"
635 # setup the files from $BASE_TEMPLATES/, substituting any variables
636 # based on the config
637 copy_base_dir_substitute_templates ()
641 local d="$BASE_TEMPLATES/$dir"
642 [ -d "$d" ] || return 0
645 for f in $(cd "$d" && find . \! -name '*~') ; do
646 f="${f#./}" # remove leading "./" for clarity
647 if [ -d "$d/$f" ]; then
648 # Don't chmod existing directory
649 if diskimage_is_directory "/$f" ; then
652 diskimage_mkdir_p "/$f"
655 diskimage_substitute_vars "$d/$f" "/$f"
657 diskimage_chmod_reference "$d/$f" "/$f"
663 setup_base_ssh_keys ()
665 # this is needed as git doesn't store file permissions other
667 # Note that we protect the wildcards from the local shell.
668 diskimage_chmod 600 "/etc/ssh/*key" "/root/.ssh/*"
669 diskimage_chmod 700 "/etc/ssh" "/root/.ssh" "/root"
670 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
671 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
672 diskimage_append_text_file "$HOME/.ssh/id_rsa.pub" "/root/.ssh/authorized_keys"
674 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
675 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
676 diskimage_append_text_file "$HOME/.ssh/id_dsa.pub" "/root/.ssh/authorized_keys"
680 register_hook setup_base_hooks setup_base_ssh_keys
682 setup_base_grub_conf ()
684 echo "Adjusting grub.conf"
685 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
686 diskimage_sed "/boot/grub/grub.conf" \
687 -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
688 -e "s/ nodmraid//" -e "s/ nompath//" \
689 -e "s/quiet/noapic divider=10${o:+ }${o}/g"
692 register_hook setup_base_hooks setup_base_grub_conf
699 echo "Copy base files"
700 copy_base_dir_substitute_templates "all"
701 if [ -n "$type" ] ; then
702 copy_base_dir_substitute_templates "$type"
705 run_hooks setup_base_hooks
708 # setup various networking components
711 # This avoids doing anything when we're called from boot_base().
712 if [ -z "$hosts_file" ] ; then
713 echo "Skipping network-related setup"
717 echo "Setting up networks"
718 diskimage_append_text_file "$hosts_file" "/etc/hosts"
720 echo "Setting up /etc/ctdb/nodes"
721 diskimage_mkdir_p "/etc/ctdb"
722 diskimage_put "$nodes_file" "/etc/ctdb/nodes"
724 [ "$WEBPROXY" = "" ] || {
725 diskimage_append_text "export http_proxy=$WEBPROXY" "/etc/bashrc"
728 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
729 echo "Enabling nfs mount of $NFSSHARE"
730 diskimage_mkdir_p "$NFS_MOUNTPOINT"
731 diskimage_append_text "$NFSSHARE $NFS_MOUNTPOINT nfs intr" "/etc/fstab"
734 diskimage_mkdir_p "/etc/yum.repos.d"
735 echo '@@@YUM_TEMPLATE@@@' | diskimage_substitute_vars - "/etc/yum.repos.d/autocluster.repo"
738 register_hook setup_base_hooks setup_network
741 [ -z "$TIMEZONE" ] && {
742 [ -r /etc/timezone ] && {
743 TIMEZONE=`cat /etc/timezone`
745 [ -r /etc/sysconfig/clock ] && {
746 . /etc/sysconfig/clock
749 TIMEZONE="${TIMEZONE// /_}"
751 [ -n "$TIMEZONE" ] || \
752 die "Unable to determine TIMEZONE - please set in config"
755 # substite a set of variables of the form @@XX@@ for the shell
756 # variables $XX in a file.
758 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
759 # contain a filename whose contents are substituted, with variable
760 # substitution applied to those contents. If filename starts with '|'
761 # it is a command instead - however, quoting is extremely fragile.
763 infile="${1:-/dev/null}" # if empty then default to /dev/null
764 outfile="$2" # optional
766 instring=$(cat $infile)
768 # Handle any indirects by looping until nothing changes.
769 # However, only handle 10 levels of recursion.
772 outstring=$(_substitute_vars "$instring" "@@@")
773 [ $? -eq 0 ] || die "Failed to expand template $infile"
775 [ "$instring" = "$outstring" ] && break
777 count=$(($count + 1))
778 [ $count -lt 10 ] || \
779 die "Recursion too deep in $infile - only 10 levels allowed!"
781 instring="$outstring"
784 # Now regular variables.
785 outstring=$(_substitute_vars "$instring" "@@")
786 [ $? -eq 0 ] || die "Failed to expand template $infile"
788 if [ -n "$outfile" ] ; then
789 echo "$outstring" > "$outfile"
796 # Delimiter @@ means to substitute contents of variable.
797 # Delimiter @@@ means to substitute contents of file named by variable.
798 # @@@ supports leading '|' in variable value, which means to excute a
800 _substitute_vars() {(
804 # Get the list of variables used in the template. The grep
805 # gets rid of any blank lines and lines with extraneous '@'s
806 # next to template substitutions.
807 VARS=$(echo "$instring" |
808 sed -n -e "s#[^@]*${delimiter}\([A-Z0-9_][A-Z0-9_]*\)${delimiter}[^@]*#\1\n#gp" |
809 grep '^[A-Z0-9_][A-Z0-9_]*$' |
814 # variable variables are fun .....
817 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
821 if [ "$delimiter" = "@@@" ] ; then
823 c="${f#|}" # Is is a command, signified by a leading '|'?
824 if [ "$c" = "$f" ] ; then
825 # No leading '|', cat file.
829 die "Could not substitute contents of file $f"
832 # Leading '|', execute command.
833 # Quoting problems here - using eval "$c" doesn't help.
837 die "Could not execute command $c"
842 # escape some pesky chars
843 # This first one can be too slow if done using a bash
844 # variable pattern subsitution.
845 s=$(echo -n "$s" | tr '\n' '\001' | sed -e 's/\o001/\\n/g')
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 $IPNET1 $IPNET2 ; 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 ######################################################################
1119 ############################
1120 # parse command line options
1121 long_opts=$(getopt_config_options)
1122 getopt_output=$(getopt -n autocluster -o "c:e:E:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1123 [ $? != 0 ] && usage
1125 use_default_config=true
1127 # We do 2 passes of the options. The first time we just handle usage
1128 # and check whether -c is being used.
1129 eval set -- "$getopt_output"
1132 -c) shift 2 ; use_default_config=false ;;
1135 --) shift ; break ;;
1136 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1138 -h|--help) usage ;; # Usage should be shown here for real defaults.
1139 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1140 *) usage ;; # shouldn't happen, so this is reasonable.
1145 $use_default_config && [ -r "$config" ] && . "$config"
1147 eval set -- "$getopt_output"
1151 # force at least ./local_file to avoid accidental file from $PATH
1152 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1153 -e) run_hooks post_config_hooks ; eval "$2" ; exit ;;
1154 -E) eval "$2" ; shift 2 ;;
1159 -x) set -x; shift ;;
1160 --dump) run_hooks post_config_hooks ; dump_config ;;
1161 --) shift ; break ;;
1162 -h|--help) usage ;; # Redundant.
1164 # Putting --opt1|opt2|... into a variable and having case
1165 # match against it as a pattern doesn't work. The | is
1166 # part of shell syntax, so we need to do this. Look away
1167 # now to stop your eyes from bleeding! :-)
1168 x=",${long_opts}" # Now each option is surrounded by , and :
1169 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1170 # Our option, $1, surrounded by , and : was in $x, so is legal.
1171 setconf_longopt "$1" "$2"; shift 2
1176 *) usage ;; # shouldn't happen, so this is reasonable.
1180 run_hooks post_config_hooks
1186 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1189 # check for needed programs
1190 check_command expect
1191 if [ "$SYSTEM_DISK_FORMAT" = "qcow2" ] ; then
1192 check_command $QEMU_NBD
1193 check_command nbd-client
1196 [ $# -lt 1 ] && usage
1207 [ $# != 0 ] && usage
1211 [ $# != 1 ] && usage
1215 [ $# != 2 ] && usage
1216 create_one_node "$1" "$2"
1224 [ $# != 1 ] && usage
1225 diskimage_mount "$1"
1228 [ $# != 0 ] && usage