readonly self=$(readlink -f $0)
readonly ensure_dirs=@PKGLIBDIR@/ensure-dirs
-readonly action_shortcuts=( start stop restart status )
+readonly action_shortcuts=( start stop restart status watcher )
readonly default_nodecount=5
readonly default_instcount=10
readonly default_netprefix=192.0.2
readonly default_netdev=eth0
+readonly default_initscript=@SYSCONFDIR@/init.d/ganeti
readonly cluster_name=cluster
+readonly etc_hosts_filename=/etc/hosts
# IP address space:
# Cluster: .1
readonly max_instance_count=$((255 - first_inst_ipaddr_octet))
usage() {
- echo "Usage: $0 [-c <number>] [-i <number>] [-p <prefix>] [-n <netdev>]"\
- '<directory>'
+ echo "Usage: $0 [-E] [-N] [-c <number>] [-i <number>] [-p <prefix>]"\
+ '[-n <netdev>] [-I <path>] <directory>'
echo
echo 'Options:'
echo " -c Number of virtual nodes (defaults to $default_nodecount)"
echo " -p IPv4 network prefix (defaults to $default_netprefix)"
echo ' -n Network device for virtual IP addresses (defaults to'\
"$default_netdev)"
+ echo " -I Path to init script (defaults to $default_initscript)"
+ echo " -E Do not modify $etc_hosts_filename"
+ echo ' -N Do not configure networking'
}
# Variables for options
instcount=$default_instcount
netprefix=$default_netprefix
netdev=$default_netdev
+initscript=$default_initscript
+etchosts=1
+networking=1
# Parse options
-while getopts :hc:p:n:i: opt; do
+while getopts :hENc:p:n:i:I: opt; do
case "$opt" in
h)
usage
exit 1
fi
;;
+ I)
+ initscript="$OPTARG"
+ if [[ ! -x $initscript ]]; then
+ echo "Init script '$initscript' is not executable" >&2
+ exit 1
+ fi
+ ;;
+ E)
+ etchosts=
+ ;;
+ N)
+ networking=
+ ;;
\?)
echo "Invalid option: -$OPTARG" >&2
usage >&2
fi
mkdir -p \
- $nodedir/etc/default \
- $nodedir/var/lock\
- $nodedir/var/{lib,log,run}/ganeti
+ $nodedir@SYSCONFDIR@/default \
+ $nodedir@LOCALSTATEDIR@/lock\
+ $nodedir@LOCALSTATEDIR@/{lib,log,run}/ganeti
GANETI_HOSTNAME=$(node_hostname $number) \
GANETI_ROOTDIR=$nodedir \
}
setup_etc_hosts() {
- echo 'Configuring /etc/hosts ...' >&2
+ echo "Configuring $etc_hosts_filename ..." >&2
(
set -e -u
- local -r tmpfile=$(mktemp /etc/hosts.vcluster.XXXXX)
+ local -r tmpfile=$(mktemp $etc_hosts_filename.vcluster.XXXXX)
trap "rm -f $tmpfile" EXIT
{
- egrep -v "^$netprefix.[[:digit:]]+[[:space:]]" /etc/hosts
+ egrep -v "^$netprefix.[[:digit:]]+[[:space:]]" $etc_hosts_filename
echo "$netprefix.1 $cluster_name"
for ((i=0; i < nodecount; ++i)); do
echo "$(node_ipaddr $i) $(node_hostname $i)"
done
} > $tmpfile && \
chmod 0644 $tmpfile && \
- mv $tmpfile /etc/hosts && \
+ mv $tmpfile $etc_hosts_filename && \
trap - EXIT
)
}
echo '#!/bin/bash'
for ((i=0; i < nodecount; ++i)); do
local name=$(node_hostname $i)
- echo "echo 'Action \"$action\" for virtual node \"$name\" ...'"
- echo "$name/cmd /etc/init.d/ganeti $action"
+ if [[ $action = watcher ]]; then
+ echo "echo 'Running watcher for virtual node \"$name\" ..."
+ echo "$name/cmd ganeti-watcher \"\$@\""
+ else
+ echo "echo 'Action \"$action\" for virtual node \"$name\" ...'"
+ echo "$name/cmd $initscript $action \"\$@\""
+ fi
done
} > $rootdir/$action-all
chmod +x $rootdir/$action-all
cat <<EOF
Initialize cluster:
- cd $rootdir && node1/cmd gnt-cluster init --no-etc-hosts $cluster_name
+ cd $rootdir && node1/cmd gnt-cluster init --no-etc-hosts \\
+ --no-ssh-init --no-lvm-storage --no-drbd-storage $cluster_name
Change cluster settings:
cd $rootdir && node1/cmd gnt-cluster modify \\
- --enabled-hypervisors=fake \\
+ --enabled-hypervisors=fake --specs-nic-count=min=0 \\
--specs-disk-size=min=0 --specs-disk-count=min=0
Add node:
}
setup_all_nodes
-setup_etc_hosts
-setup_network_interfaces
+if [[ -n "$etchosts" ]]; then
+ setup_etc_hosts
+fi
+if [[ -n "$networking" ]]; then
+ setup_network_interfaces
+fi
setup_scripts
show_info