blob: 73c1d667ceb1616a2eb117b5d8c30f32f9b57820 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
#!/bin/bash
# Copyright 2008 Eric Thibodeau <kyron@neuralbs.com>
# All rights reserved. Released under the GPL v2 license.
# This script is written so parts can be reused for liveCD mounting...eventually ;)
. /mnt/livecd/sbin/functions.sh
CONFDIR="/etc/gentoo"
CLUSTER_CONF="$CONFDIR/cluster.conf"
LDAP_CONF="$CONFDIR/ldap_auth.conf"
conf_error() {
eerror "CONFIG_OK is not set to 'yes' in $1"
eerror "Please edit ALL files in $(dirname $1)"
eerror "and re-run $0"
einfo "If there are some files in $(dirname $1)"
einfo "which don't need configuration, hid them with"
einfo "a '.' before the name of the file"
exit 1
}
aufs_mount() {
CDROOT=/mnt/livecd/
MKDIR=${CDROOT}/bin/mkdir
MODPROBE=${CDROOT}/sbin/modprobe
$MODPROBE aufs || eerror "Got $? while probing for aufs module!"
# Looping this simply because it should replace the current tmpfs mounting of the liveCD :P
for I in tftproot
do
einfo "Setting up AUFS mount for /$I"
${MKDIR} -p /mnt/aufs/$I /$I
mount -t tmpfs tmpfs_$I /mnt/aufs/$I
mount -n -t aufs -o br:/mnt/aufs/${I}=rw:/mnt/livecd/${I} aufs_mount /${I}
done
}
do_conf() {
. $1
shift
einfo "Calling $* "
$*
if [ $? != 0 ]; then
eerror "Call to $* did not return 0 errors."
ewarn "Look above this message for clues."
exit 1
fi
}
# This could have been inlined into do_conf but we would rather check configs _before_
# we do anything...we could be a little mode selective than $CONFDIR/* though
check_conf() {
einfo "Checking config files.."
for I in $CONFDIR/*.conf
do
. $I
[[ $CONFIG_OK == "yes" ]] || conf_error $I
done
}
# This function has to be called after the $CLUSTER_CONF file has been sourced
# Required external vars:
# CLUSTER_CONF:NFSROOT
config_ssh(){
KEY_NAME="node_dsa"
NETADDR="$(sipcalc ${CLUSTER_ETH} | egrep 'Network address' | cut -d- -f2)"
# The following is needed because $HOME is set to / on the livecd console for some reason
HDIR="/root"
pushd $PWD
einfo "Setting up passwordless ssh for root between master and the nodes"
mkdir -p $HDIR/.ssh/ $NFSROOT/root/.ssh/
cd $HDIR/.ssh/
ssh-keygen -t dsa -b 1024 -f $KEY_NAME -N ""
cat $KEY_NAME.pub >> $NFSROOT/root/.ssh/authorized_keys
cat >> $HDIR/.ssh/config <<-EOF
# Auto-generated by $0 to ease the use of passwordless logins for all users
# Although this approach is questionnable, it's also one of the only way
# to automate some of the master-node configuration/discovery process
# until an Avahi-style approach is implemented.
Host *.gentoo.local ${NETADDR%.[09]*}.* node*
IdentityFile $HDIR/.ssh/$KEY_NAME
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
CheckHostIP no
Compression no
EOF
echo "# we don't use IPV6, the following setting removes undue delays that would be added" >> /etc/ssh/ssh_config
echo "AddressFamily inet" >> /etc/ssh/ssh_config
chmod 600 $HDIR/.ssh/* $NFSROOT/root/.ssh/*
chmod 700 $HDIR/.ssh $NFSROOT/root/.ssh
popd
}
####### Main #########
# Speed up the dev cycle by automating some tasks:
if [[ "$1" == "--test" ]]; then
ewarn
ewarn "Yeah...you know what you're doing right?"
ewarn "Warranty void if used ;)"
ewarn
cat >> /etc/conf.d/net <<-EOF
# These lines were added by 'cluster-setup --test'
config_eth1=( "10.0.0.1 broadcast 10.0.0.255 netmask 255.255.255.0" )
modules_eth1=( "!plug" )
# End of 'added by cluster-setup --test'
EOF
/etc/init.d/net.eth1 restart
echo root:test | chpasswd
/etc/init.d/sshd start
sed -i -e's:CONFIG_OK="no":CONFIG_OK="yes":' $CONFDIR/*.conf
fi
check_conf
grep -q /mnt/aufs/tftproot /proc/mounts
[ $? ] && aufs_mount
. $CLUSTER_CONF
einfo "Making sure $CLUSTER_ETH is configured correctly.."
if [[ "$CLUSTER_ETH" =~ eth.* && $1 != "--test" ]]; then
echo "The cluster's NIC is set as $CLUSTER_ETH with the following config:"
/sbin/ifconfig $CLUSTER_ETH
until [[ $ANS == "y" || $ANS == "n" ]]
do
echo -n "Do you want to change this now? [y/n]: "
read ANS
done
if [[ $ANS == "y" ]]; then
net-setup $CLUSTER_ETH
einfo "Adding modules_$CLUSTER_ETH=( \"!plug\" ) to /etc/conf.d/net (required for the system's consistency)"
echo "modules_$CLUSTER_ETH=( \"!plug\" )" >> /etc/conf.d/net
einfo "$CLUSTER_ETH will have to be restarted to be in a consistent state"
/etc/init.d/net.$CLUSTER_ETH restart
fi
[[ $ANS == "n" ]] && einfo "You know what you're doing..."
else
[[ $1 != "--test" ]] && einfo "CLUSTER_ETH is not set to an eth? device: $CLUSTER_ETH"
einfo "Hope you know what you're doing."
fi
do_conf $CLUSTER_CONF "emerge --config =sys-cluster/beowulf-head-0.1"
config_ssh
# we need to set master and master.$DOMAINNAME to a real IP address (not 127.0.0.1) for everything to work:
echo "$(LC_ALL=C ifconfig "eth1" | sed -n -e 's#.*\(inet addr:\|inet \)\([^ ]*\).*#\2#p') $(hostname).$LOCALDOMAINNAME $(hostname)" >> /etc/hosts
einfo "We need to refresh resolv.conf and dnsmasq."
einfo "Restarting both $PUBETH and dnsmasq..."
/etc/init.d/net.$PUBETH restart
/etc/init.d/dnsmasq restart
# This also has to be done with the $CLUSTER_CONF information sourced
# Setting up Torque
# Checking for pbs USE flag
portageq envvar USE | grep -q pbs
if [[ $? == 0 ]]; then
einfo "Setting up torque on $HOSTNAME and in $NFSROOT"
USE=server emerge --config =sys-cluster/torque-2.3.3
# if mom is not started on the master node, listing it in nodes doesn't hurt it and
# makes sure the file exists
echo $(hostname) >> $PBS_SERVER_HOME/server_priv/nodes
/etc/init.d/pbs_server start
USE=-server ROOT=$NFSROOT emerge --config =sys-cluster/torque-2.3.3
fi
# we want to do this last, otherwise some name resolution problems might haunt you
do_conf $LDAP_CONF "emerge --config =net-nds/ldap-auth-0.1"
/etc/init.d/slapd start || ewarn "Slapd did not start! See above for error messages...continuing"
einfo "Setting up auth on the $NFSROOT"
USE=-authmaster ROOT="$NFSROOT" emerge --config =net-nds/ldap-auth-0.1
[[ $? == 0 ]] && einfo "Once you have nodes going, restart Torque (pbs_server)"
if [[ $1 == "--test" ]]; then
echo "Using --test implies the following:"
echo '- root password is "test" and can log on (passwordless) onto nodes !!!!'
echo '- ldap admin password is "default" !!!!(again)'
echo "- eth1 is the cluster's NIC and is set to 10.0.0.1/24"
echo '- eth0 is the public nic'
echo '- all defaults in .config files get used'
fi
|