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 # Use with care, since this may clear some autocluster defaults.!
169 eval "$hook_var=\"\""
172 ##############################
174 # common node creation stuff
175 create_node_COMMON ()
180 local template_file="${4:-$NODE_TEMPLATE}"
182 if [ "$SYSTEM_DISK_FORMAT" = "raw" -a "$BASE_FORMAT" != "raw" ] ; then
183 die "Error: if SYSTEM_DISK_FORMAT is \"raw\" then BASE_FORMAT must also be \"raw\"."
186 IPNUM=$(($FIRSTIP + $ip_offset))
187 DISK="${VIRTBASE}/${CLUSTER}/${NAME}.${SYSTEM_DISK_FORMAT}"
188 local base_disk="${VIRTBASE}/${BASENAME}.${BASE_FORMAT}"
190 if [ "$BASE_PER_NODE_TYPE" = "yes" ] ; then
191 base_disk="${VIRTBASE}/${BASENAME}-${type}.${BASE_FORMAT}"
194 mkdir -p $VIRTBASE/$CLUSTER tmp
197 case "$SYSTEM_DISK_FORMAT" in
199 echo "Creating the disk..."
200 qemu-img create -b "$base_disk" -f qcow2 "$DISK"
201 create_node_configure_image "$DISK" "$type"
204 echo "Creating the disk..."
205 cp -v --sparse=always "$base_disk" "$DISK"
206 create_node_configure_image "$DISK" "$type"
209 echo "Skipping disk image creation as requested"
212 die "Error: unknown SYSTEM_DISK_FORMAT=\"${SYSTEM_DISK_FORMAT}\"."
215 set_macaddrs $CLUSTER $ip_offset
218 echo "Creating $NAME.xml"
219 substitute_vars $template_file tmp/$NAME.xml
221 # install the XML file
222 $VIRSH undefine $NAME > /dev/null 2>&1 || true
223 $VIRSH define tmp/$NAME.xml
226 create_node_configure_image ()
236 # Provides an easy way of removing nodes from $NODE.
237 create_node_null () {
241 ##############################
243 hack_nodes_functions=
246 # Expand out any abbreviations in NODES.
255 for i in ${ips//,/ } ; do
256 ns="${ns}${ns:+ }${t}:${i}"
261 for i in $(seq ${ips/-/ }) ; do
262 ns="${ns}${ns:+ }${t}:${i}"
266 ns="${ns}${ns:+ }${n}"
271 # Apply nodes hacks. Some of this is about backward compatibility
272 # but the hacks also fill in the node names and whether they're
273 # part of the CTDB cluster. The order is the order that
274 # configuration modules register their hacks.
275 run_hooks hack_nodes_functions
277 if [ -n "$NUMNODES" ] ; then
278 # Attempt to respect NUMNODES. Reduce the number of CTDB
280 local numnodes=$NUMNODES
284 if [ "$ctdb_node" = 1 ] ; then
285 if [ $numnodes -gt 0 ] ; then
286 numnodes=$(($numnodes - 1))
294 hack_all_nodes_with hack_filter
296 [ $numnodes -gt 0 ] && \
297 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."
300 # Check IP addresses for duplicates.
302 # This function doesn't modify anything...
305 [ "${ip_offsets/${ip_offset}}" != "$ip_offsets" ] && \
306 die "Duplicate IP offset in NODES - ${node_type}:${ip_offset}"
307 ip_offsets="${ip_offsets}${ip_offset}:"
309 hack_all_nodes_with get_ip_offset
312 ##############################
314 sanity_check_cluster_name ()
316 [ -z "${CLUSTER//[A-Za-z0-9]}" ] || \
317 die "Cluster names should be restricted to the characters A-Za-z0-9. \
318 Some cluster filesystems have problems with other characters."
323 common_nodelist_hacking ()
325 # Rework the NODES list
328 # Build /etc/hosts and hack the names of the ctdb nodes
329 hosts_line_hack_name ()
331 # Ignore nodes without names (e.g. "null")
332 [ "$node_type" != "null" -a -n "$name" ] || return 0
336 local ip_addr="$IPBASE.0.$(($FIRSTIP + $ip_offset))"
338 if [ "$ctdb_node" = 1 ] ; then
339 num_ctdb_nodes=$(($num_ctdb_nodes + 1))
340 sname="${CLUSTER}n${num_ctdb_nodes}"
341 hosts_line="$ip_addr ${sname}.${ld} ${name}.${ld} $name $sname"
344 hosts_line="$ip_addr ${name}.${ld} $name"
347 # This allows you to add a function to your configuration file
348 # to modify hostnames (and other aspects of nodes). This
349 # function can access/modify $name (the existing name),
350 # $node_type and $ctdb_node (1, if the node is a member of the
351 # CTDB cluster, 0 otherwise).
352 if [ -n "$HOSTNAME_HACKING_FUNCTION" ] ; then
353 local old_name="$name"
354 $HOSTNAME_HACKING_FUNCTION
355 if [ "$name" != "$old_name" ] ; then
356 hosts_line="$ip_addr ${name}.${ld} $name"
362 hosts_file="tmp/hosts.$CLUSTER"
364 local num_ctdb_nodes=0
365 local ld=$(echo $DOMAIN | tr A-Z a-z)
366 echo "# autocluster $CLUSTER"
367 hack_all_nodes_with hosts_line_hack_name
371 # Build /etc/ctdb/nodes
374 [ "$ctdb_node" = 1 ] || return 0
375 echo "$IPBASE.0.$(($FIRSTIP + $ip_offset))"
376 num_nodes=$(($num_nodes + 1))
378 nodes_file="tmp/nodes.$CLUSTER"
380 hack_all_nodes_with ctdb_nodes_line >$nodes_file
381 : "${NUMNODES:=${num_nodes}}" # Set $NUMNODES if necessary
384 create_cluster_hooks=
385 cluster_created_hooks=
391 sanity_check_cluster_name
393 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
395 # Run hooks before doing anything else.
396 run_hooks create_cluster_hooks
398 common_nodelist_hacking
400 for_each_node call_func create_node
402 echo "Cluster $CLUSTER created"
403 echo "You may want to add this to your /etc/hosts file:"
406 run_hooks cluster_created_hooks
412 local single_node_ip_offset="$2"
414 sanity_check_cluster_name
416 mkdir -p $VIRTBASE/$CLUSTER $KVMLOG tmp
418 common_nodelist_hacking
421 set -- $(IFS=: ; echo $n)
422 [ $single_node_ip_offset -eq $2 ] || continue
423 call_func create_node "$@"
425 echo "Requested node created"
426 echo "You may want to update your /etc/hosts file:"
433 ###############################
434 # test the proxy setup
436 export http_proxy=$WEBPROXY
437 wget -O /dev/null $INSTALL_SERVER || \
438 die "Your WEBPROXY setting \"$WEBPROXY\" is not working"
444 kickstart_floppy_create_hooks=
450 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
454 echo "Testing WEBPROXY $WEBPROXY"
457 echo "Creating the disk"
458 qemu-img create -f $BASE_FORMAT "$DISK" $DISKSIZE
461 mkdir -p mnt tmp tmp/ISO
465 echo "Creating kickstart file from template"
466 substitute_vars "$KICKSTART" "tmp/ks.cfg"
468 if [ $INSTALLKEY = "--skip" ]; then
470 --------------------------------------------------------------------------------------
471 WARNING: You have not entered an install key. Some RHEL packages will not be installed.
473 Please enter a valid RHEL install key in your config file like this:
475 INSTALLKEY="1234-5678-0123-4567"
477 The install will continue without an install key in 5 seconds
478 --------------------------------------------------------------------------------------
483 # $ISO gets $ISO_DIR prepended if it doesn't start with a leading '/'.
486 (*) ISO="${ISO_DIR}/${ISO}"
489 echo "Creating kickstart floppy"
490 dd if=/dev/zero of=tmp/floppy.img bs=1024 count=1440
491 mkdosfs tmp/floppy.img
492 mount -o loop -t msdos tmp/floppy.img mnt
494 mount -o loop,ro $ISO tmp/ISO
496 echo "Setting up bootloader"
497 cp tmp/ISO/isolinux/isolinux.bin tmp
498 cp tmp/ISO/isolinux/vmlinuz tmp
499 cp tmp/ISO/isolinux/initrd.img tmp
501 run_hooks kickstart_floppy_create_hooks
508 substitute_vars $INSTALL_TEMPLATE tmp/$NAME.xml
510 rm -f $KVMLOG/serial.$NAME
512 # boot the install CD
513 $VIRSH create tmp/$NAME.xml
515 echo "Waiting for install to start"
518 # wait for the install to finish
519 if ! waitfor $KVMLOG/serial.$NAME "$KS_DONE_MESSAGE" $CREATE_BASE_TIMEOUT ; then
521 die "Failed to create base image $DISK"
529 Install finished, base image $DISK created
533 To ensure that this image does not change
535 Note that the root password has been set to $ROOTPASSWORD
540 ###############################
546 DISK="${VIRTBASE}/${NAME}.${BASE_FORMAT}"
560 echo "Creating $NAME.xml"
561 substitute_vars $BOOT_TEMPLATE tmp/$NAME.xml
563 # boot the base system
564 $VIRSH create tmp/$NAME.xml
567 ######################################################################
569 # various functions...
571 # Set some MAC address variables based on a hash of the cluster name
572 # plus the node number and each adapter number.
577 local md5=$(echo $cname | md5sum)
578 local nh=$(printf "%02x" $ip_offset)
579 local mac_prefix="02:${md5:0:2}:${md5:2:2}:00:${nh}:"
581 MAC1="${mac_prefix}01"
582 MAC2="${mac_prefix}02"
583 MAC3="${mac_prefix}03"
584 MAC4="${mac_prefix}04"
585 MAC5="${mac_prefix}05"
586 MAC6="${mac_prefix}06"
589 # mount a qemu image via nbd
591 echo "Connecting nbd to $1"
594 killall -9 -q $QEMU_NBD || true
595 $QEMU_NBD -p 1300 $1 &
597 [ -r $NBD_DEVICE ] || {
598 mknod $NBD_DEVICE b 43 0
600 umount mnt 2> /dev/null || true
601 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
602 killall -9 -q nbd-client || true
603 nbd-client localhost 1300 $NBD_DEVICE > /dev/null 2>&1 || true &
609 echo "Disconnecting nbd"
611 nbd-client -d $NBD_DEVICE > /dev/null 2>&1 || true
612 killall -9 -q nbd-client || true
613 killall -q $QEMU_NBD || true
620 case "$SYSTEM_DISK_FORMAT" in
624 extra_mount_options=""
628 extra_mount_options=",loop"
631 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
637 case "$SYSTEM_DISK_FORMAT" in
645 die "Error: unknown SYSTEM_DISK_FORMAT=${SYSTEM_DISK_FORMAT}."
649 # mount a qemu image via nbd
654 local device extra_mount_options
658 echo "Mounting disk ${disk}..."
660 for m in $SYSTEM_DISK_MOUNTS ; do
662 o="${m#*:}" # Offset is after colon
663 m="${m%:*}" # Mountpoint is before colon
664 echo " ${m} from offset ${o}"
666 for i in $(seq 1 5); do
667 mount -o offset=${o}${extra_mount_options} $device "mnt${m}" && {
671 umount mnt 2>/dev/null || true
674 [ $mount_ok = 1 ] || die "Failed to mount $disk"
678 echo "Mounted directory does not look like a root filesystem"
684 # unmount a qemu image
686 echo "Unmounting disk"
689 # umounts are done in reverse. Be lazy and construct a reverse
690 # list, since the shell will handle any strange whitespace for
694 for m in $SYSTEM_DISK_MOUNTS ; do
695 umounts="${m%:*}${umounts:+ }${umounts)"
697 for m in $umounts ; do
698 umount "mnt${m}" || umount "mnt${m}" || true
703 # setup the files from $BASE_TEMPLATES/, substituting any variables
704 # based on the config
705 copy_base_dir_substitute_templates ()
709 local d="$BASE_TEMPLATES/$dir"
710 [ -d "$d" ] || return 0
713 for f in $(cd "$d" && find . \! -name '*~') ; do
714 if [ -d "$d/$f" ]; then
717 substitute_vars "$d/$f" "mnt/$f"
719 chmod --reference="$d/$f" "mnt/$f"
725 setup_base_ssh_keys ()
727 # this is needed as git doesn't store file permissions other
729 chmod 600 mnt/etc/ssh/*key mnt/root/.ssh/*
730 chmod 700 mnt/etc/ssh mnt/root/.ssh mnt/root
731 if [ -r "$HOME/.ssh/id_rsa.pub" ]; then
732 echo "Adding $HOME/.ssh/id_rsa.pub to ssh authorized_keys"
733 cat "$HOME/.ssh/id_rsa.pub" >> mnt/root/.ssh/authorized_keys
735 if [ -r "$HOME/.ssh/id_dsa.pub" ]; then
736 echo "Adding $HOME/.ssh/id_dsa.pub to ssh authorized_keys"
737 cat "$HOME/.ssh/id_dsa.pub" >> mnt/root/.ssh/authorized_keys
741 register_hook setup_base_hooks setup_base_ssh_keys
743 setup_base_grub_conf ()
745 echo "Adjusting grub.conf"
746 local o="$EXTRA_KERNEL_OPTIONS" # For readability.
747 sed -e "s/console=ttyS0,19200/console=ttyS0,115200/" \
748 -e "s/ nodmraid//" -e "s/ nompath//" \
749 -e "s/quiet/noapic divider=10${o:+ }${o}/g" mnt/boot/grub/grub.conf -i.org
752 register_hook setup_base_hooks setup_base_grub_conf
759 echo "Copy base files"
760 copy_base_dir_substitute_templates "all"
761 if [ -n "$type" ] ; then
762 copy_base_dir_substitute_templates "$type"
765 run_hooks setup_base_hooks
768 # setup various networking components
771 # This avoids doing anything when we're called from boot_base().
772 if [ -z "$hosts_file" ] ; then
773 echo "Skipping network-related setup"
777 echo "Setting up networks"
778 cat $hosts_file >>mnt/etc/hosts
780 echo "Setting up /etc/ctdb/nodes"
781 mkdir -p mnt/etc/ctdb
782 cp $nodes_file mnt/etc/ctdb/nodes
784 [ "$WEBPROXY" = "" ] || {
785 echo "export http_proxy=$WEBPROXY" >> mnt/etc/bashrc
788 if [ -n "$NFSSHARE" -a -n "$NFS_MOUNTPOINT" ] ; then
789 echo "Enabling nfs mount of $NFSSHARE"
790 mkdir -p "mnt$NFS_MOUNTPOINT"
791 echo "$NFSSHARE $NFS_MOUNTPOINT nfs intr" >> mnt/etc/fstab
794 mkdir -p mnt/etc/yum.repos.d
795 echo '@@@YUM_TEMPLATE@@@' | substitute_vars - > mnt/etc/yum.repos.d/autocluster.repo
798 register_hook setup_base_hooks setup_network
801 [ -z "$TIMEZONE" ] && {
802 [ -r /etc/timezone ] && {
803 TIMEZONE=`cat /etc/timezone`
805 [ -r /etc/sysconfig/clock ] && {
806 . /etc/sysconfig/clock
809 TIMEZONE="${TIMEZONE// /_}"
811 [ -n "$TIMEZONE" ] || \
812 die "Unable to determine TIMEZONE - please set in config"
815 # substite a set of variables of the form @@XX@@ for the shell
816 # variables $XX in a file.
818 # Indirect variables @@@XX@@@ (3 ats) specify that the variable should
819 # contain a filename whose contents are substituted, with variable
820 # substitution applied to those contents. If filename starts with '|'
821 # it is a command instead - however, quoting is extremely fragile.
823 infile="${1:-/dev/null}" # if empty then default to /dev/null
824 outfile="$2" # optional
826 instring=$(cat $infile)
828 # Handle any indirects by looping until nothing changes.
829 # However, only handle 10 levels of recursion.
832 outstring=$(_substitute_vars "$instring" "@@@")
833 [ $? -eq 0 ] || die "Failed to expand template $infile"
835 [ "$instring" = "$outstring" ] && break
837 count=$(($count + 1))
838 [ $count -lt 10 ] || \
839 die "Recursion too deep in $infile - only 10 levels allowed!"
841 instring="$outstring"
844 # Now regular variables.
845 outstring=$(_substitute_vars "$instring" "@@")
846 [ $? -eq 0 ] || die "Failed to expand template $infile"
848 if [ -n "$outfile" ] ; then
849 echo "$outstring" > "$outfile"
856 # Delimiter @@ means to substitute contents of variable.
857 # Delimiter @@@ means to substitute contents of file named by variable.
858 # @@@ supports leading '|' in variable value, which means to excute a
860 _substitute_vars() {(
864 # get the list of variables used in the template
865 VARS=`echo "$instring" |
866 tr -cs "A-Z0-9_$delimiter" '\012' |
868 sed -n -e "s#^${delimiter}\(.*\)${delimiter}\\$#\1#p"`
872 # variable variables are fun .....
875 die "No substitution given for ${delimiter}$v${delimiter} in $infile"
879 if [ "$delimiter" = "@@@" ] ; then
881 c="${f#|}" # Is is a command, signified by a leading '|'?
882 if [ "$c" = "$f" ] ; then
883 # No leading '|', cat file.
887 die "Could not substitute contents of file $f"
890 # Leading '|', execute command.
891 # Quoting problems here - using eval "$c" doesn't help.
895 die "Could not execute command $c"
900 # escape some pesky chars
905 echo "s#${delimiter}${v}${delimiter}#${s}#g"
908 echo "$instring" | sed -f $tmp
914 which $1 > /dev/null || die "Please install $1 to continue"
917 # Set a variable if it isn't already set. This allows environment
918 # variables to override default config settings.
923 [ "${!v+x}" ] || eval "$v=\"$e\""
929 for i in "${installdir}/config.d/"*.defconf ; do
934 # Print the list of config variables defined in config.d/.
935 get_config_options () {( # sub-shell for local declaration of defconf()
937 defconf() { options="$options $1" ; }
942 # Produce a list of long options, suitable for use with getopt, that
943 # represent the config variables defined in config.d/.
944 getopt_config_options () {
945 local x=$(get_config_options | tr 'A-Z_' 'a-z-')
949 # Unconditionally set the config variable associated with the given
955 local v=$(echo "${longopt#--}" | tr 'a-z-' 'A-Z_')
956 # unset so defconf will set it
961 # Dump all of the current config variables.
964 for o in $(get_config_options) ; do
965 echo "${o}=\"${!o}\""
970 # $COLUMNS is set in interactive bash shells. It probably isn't set
971 # in this shell, so let's set it if it isn't.
972 : ${COLUMNS:=$(stty size 2>/dev/null | sed -e 's@.* @@')}
976 # Print text assuming it starts after other text in $startcol and
977 # needs to wrap before $COLUMNS - 2. Subsequent lines start at $startcol.
978 # Long "words" will extend past $COLUMNS - 2.
983 local width=$(($COLUMNS - 2 - $startcol))
984 [ $width -lt 0 ] && width=$((78 - $startcol))
989 if [ $startcol -gt 0 ] ; then
990 padding=$(printf "\n%${startcol}s" " ")
996 while [ -n "$text" ] ; do
999 # If we already have output then arrange padding on the next line.
1000 [ -n "$out" ] && out="${out}${padding}"
1002 # Break the text at $width.
1003 out="${out}${text:0:${width}}"
1004 text="${text:${width}}"
1006 # If we have left over text then the line break may be ugly,
1007 # so let's check and try to break it on a space.
1008 if [ -n "$text" ] ; then
1009 # The 'x's stop us producing a special character like '(',
1010 # ')' or '!'. Yuck - there must be a better way.
1011 if [ "x${text:0:1}" != "x " -a "x${text: -1:1}" != "x " ] ; then
1012 # We didn't break on a space. Arrange for the
1013 # beginning of the broken "word" to appear on the next
1014 # line but not if it will make us loop infinitely.
1015 if [ "${orig}" != "${out##* }${text}" ] ; then
1016 text="${out##* }${text}"
1019 # Hmmm, doing that would make us loop, so add the
1020 # rest of the word from the remainder of the text
1021 # to this line and let it extend past $COLUMNS - 2.
1022 out="${out}${text%% *}"
1023 if [ "${text# *}" != "$text" ] ; then
1024 # Remember the text after the next space for next time.
1027 # No text after next space.
1032 # We broke on a space. If it will be at the beginning
1033 # of the next line then remove it.
1042 # Display usage text, trying these approaches in order.
1043 # 1. See if it all fits on one line before $COLUMNS - 2.
1044 # 2. See if splitting before the default value and indenting it
1045 # to $startcol means that nothing passes $COLUMNS - 2.
1046 # 3. Treat the message and default value as a string and just us fill_text()
1048 usage_display_text () {
1053 local width=$(($COLUMNS - 2 - $startcol))
1054 [ $width -lt 0 ] && width=$((78 - $startcol))
1056 default="(default \"$default\")"
1058 if [ $((${#desc} + 1 + ${#default})) -le $width ] ; then
1059 echo "${desc} ${default}"
1061 local padding=$(printf "%${startcol}s" " ")
1063 if [ ${#desc} -lt $width -a ${#default} -lt $width ] ; then
1065 echo "${padding}${default}"
1067 fill_text $startcol "${desc} ${default}"
1072 # Display usage information for long config options.
1073 usage_smart_display () {( # sub-shell for local declaration of defconf()
1077 local local longopt=$(echo "$1" | tr 'A-Z_' 'a-z-')
1079 printf " --%-25s " "${longopt}=${3}"
1081 usage_display_text $startcol "$4" "$2"
1088 # Display usage information for long config options.
1089 usage_config_options (){
1090 usage_smart_display load_config
1094 local releases=$(cd $installdir/releases && echo *.release)
1095 releases="${releases//.release}"
1096 releases="${releases// /\", \"}"
1097 echo "\"$releases\""
1102 shift # subsequent args are passed to release file
1104 # This simply loads an extra config file from $installdir/releases
1105 f="${installdir}/releases/${release}.release"
1106 if [ -r "$f" ] ; then
1109 f="${installdir}/releases/${release%%-*}.release"
1110 if [ -r "$f" ] ; then
1111 . "$f" "${release#*-}"
1113 echo "Unknown release \"${release}\" specified to --with-release"
1114 printf "%-25s" "Supported releases are: "
1115 fill_text 25 "$(list_releases)"
1122 has_public_addresses_DEFAULT ()
1127 # Build public address configuration.
1128 # * 1st public IP: unless specified, last octet is $FIRSTIP + $PUBLIC_IP_OFFSET
1129 # * Excluded nodes: unless specified via comma-separated list of IP offsets,
1130 # nodes are excluded via their node types
1131 # * Number of public addresses per interface is either specified or $NUMNODES.
1132 make_public_addresses () {
1133 local firstip="${1:-$(($FIRSTIP + $PUBLIC_IP_OFFSET))}"
1134 local excluded_nodes="$2"
1135 local num_addrs="${3:-${NUMNODES}}"
1137 # For delimiting matches.
1138 excluded_nodes="${excluded_nodes:+,}${excluded_nodes}${excluded_nodes:+,}"
1140 excluded_nodes="${excluded_nodes// /}"
1142 make_public_addresses_for_node ()
1144 [ "$ctdb_node" = 1 ] || return 0
1146 echo "[/etc/ctdb/public_addresses:${name}.${DOMAIN}]"
1148 if [ -n "$excluded_nodes" -a \
1149 "${excluded_nodes/,${ip_offset},}" = "$excluded_nodes" ] ||
1150 ([ -z "$excluded_nodes" ] &&
1151 call_func has_public_addresses "$node_type") ; then
1154 for e in "1" "2" ; do
1155 for i in $(seq $firstip $(($firstip + $num_addrs - 1))) ; do
1156 if [ $i -gt 254 ] ; then
1157 die "make_public_addresses: octet > 254 - consider setting PUBLIC_IP_OFFSET"
1159 printf "\t${IPBASE}.${e}.${i}/24 eth${e}\n"
1165 hack_all_nodes_with make_public_addresses_for_node
1168 ######################################################################
1172 ############################
1173 # parse command line options
1174 long_opts=$(getopt_config_options)
1175 getopt_output=$(getopt -n autocluster -o "c:e:xh" -l help,dump,with-release: -l "$long_opts" -- "$@")
1176 [ $? != 0 ] && usage
1178 use_default_config=true
1180 # We do 2 passes of the options. The first time we just handle usage
1181 # and check whether -c is being used.
1182 eval set -- "$getopt_output"
1185 -c) shift 2 ; use_default_config=false ;;
1187 --) shift ; break ;;
1188 --with-release) shift 2 ;; # Don't set use_default_config=false!!!
1190 -h|--help) usage ;; # Usage should be shown here for real defaults.
1191 --*) shift 2 ;; # Assume other long opts are valid and take an arg.
1192 *) usage ;; # shouldn't happen, so this is reasonable.
1197 $use_default_config && [ -r "$config" ] && . "$config"
1199 eval set -- "$getopt_output"
1203 # force at least ./local_file to avoid accidental file from $PATH
1204 -c) . "$(dirname $2)/$(basename $2)" ; shift 2 ;;
1205 -e) eval "$2" ; exit ;;
1210 -x) set -x; shift ;;
1211 --dump) dump_config ;;
1212 --) shift ; break ;;
1213 -h|--help) usage ;; # Redundant.
1215 # Putting --opt1|opt2|... into a variable and having case
1216 # match against it as a pattern doesn't work. The | is
1217 # part of shell syntax, so we need to do this. Look away
1218 # now to stop your eyes from bleeding! :-)
1219 x=",${long_opts}" # Now each option is surrounded by , and :
1220 if [ "$x" != "${x#*,${1#--}:}" ] ; then
1221 # Our option, $1, surrounded by , and : was in $x, so is legal.
1222 setconf_longopt "$1" "$2"; shift 2
1227 *) usage ;; # shouldn't happen, so this is reasonable.
1235 echo ERROR: failed in function \"${FUNCNAME}\" at line ${LINENO} of ${BASH_SOURCE[0]} with code $es;
1238 # check for needed programs
1239 check_command expect
1240 if [ "$SYSTEM_DISK_FORMAT" != "raw" ] ; then
1241 check_command $QEMU_NBD
1242 check_command nbd-client
1245 [ $# -lt 1 ] && usage
1256 [ $# != 0 ] && usage
1260 [ $# != 1 ] && usage
1264 [ $# != 2 ] && usage
1265 create_one_node "$1" "$2"
1273 [ $# != 1 ] && usage
1277 [ $# != 0 ] && usage