All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

setup-driver.sh 5.72 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/bin/sh

set -x

DIRNAME=`dirname $0`

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Grab our libs
. "$DIRNAME/setup-lib.sh"
15 16 17 18 19
# Don't run setup-driver.sh twice
if [ -f $OURDIR/setup-driver-done ]; then
    echo "setup-driver already ran; not running again"
    exit 0
fi
20 21 22 23 24

#
# Setup nginx to show our setup/config directory.
#
if [ "$HOSTNAME" = "$CONTROLLER" ]; then
25
    ngfailed=0
26
    maybe_install_packages nginx
27
    ngfailed=$?
28 29 30
    # Always remove default nginx site-enabled file, since apache must
    # listen on port 80.  But if apache2 ran prior to nginx, nginx
    # install may have failed; if so, remove its default enabled site.
31 32
    rm -f /etc/nginx/sites-available/default \
        /etc/nginx/sites-enabled/default
33
    if [ ! $ngfailed -eq 0 ]; then
34 35
	maybe_install_packages nginx
    fi
36
    rm -f /etc/nginx/sites-enabled/default
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
    echo "$ADMIN_PASS" | htpasswd -n -i admin > /etc/nginx/htpasswd
    chown www-data:root /etc/nginx/htpasswd
    chmod 660 /etc/nginx/htpasswd
    mkdir /var/www/profile-setup
    chown www-data /var/www/profile-setup
    mount -o bind,ro $OURDIR /var/www/profile-setup/
    echo $OURDIR /var/www/profile-setup none defaults,bind 0 0 >> /etc/fstab
    cat <<EOF >/etc/nginx/sites-available/profile-setup-logs
server {
        include /etc/nginx/mime.types;
        types { text/plain log; }
        listen 7999 default_server;
        listen [::]:7999 default_server;
        root /var/www/profile-setup;
        index index.html;
        server_name _;
        location / {
                 autoindex on;
                 auth_basic "profile-setup";
                 auth_basic_user_file /etc/nginx/htpasswd;
        }
}
EOF
    ln -s /etc/nginx/sites-available/profile-setup-logs \
        /etc/nginx/sites-enabled/profile-setup-logs
62 63
    service_enable nginx
    service_restart nginx
64
fi
65
logtstart "driver"
66

67 68 69 70 71
#
# Maybe expand the rootfs.
#
$DIRNAME/setup-grow-rootfs.sh 1> $OURDIR/setup-grow-rootfs.log 2>&1

72 73 74
# Copy our source code into $OURDIR for future use:
echo "*** Copying source code into $OURDIR/bin ..."
mkdir -p $OURDIR/bin
David Johnson's avatar
David Johnson committed
75
rsync -avz $DIRNAME/ $OURDIR/bin/
76

77 78
echo "*** Setting up root ssh pubkey access across all nodes..."

79 80 81
# All nodes need to publish public keys, and acquire others'
$DIRNAME/setup-root-ssh.sh 1> $OURDIR/setup-root-ssh.log 2>&1

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
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi

if [ "$HOSTNAME" = "$NETWORKMANAGER" ]; then

    echo "*** Waiting for ssh access to all nodes..."

    for node in $NODES ; do
	[ "$node" = "$NETWORKMANAGER" ] && continue

	SUCCESS=1
	fqdn=`getfqdn $node`
	while [ $SUCCESS -ne 0 ] ; do
	    sleep 1
	    ssh -o ConnectTimeout=1 -o PasswordAuthentication=No -o NumberOfPasswordPrompts=0 -o StrictHostKeyChecking=No $fqdn /bin/ls > /dev/null
	    SUCCESS=$?
	done
	echo "*** $node is up!"
    done

    #
    # Get our hosts files setup to point to the new management network.
    # (These were created one-time in setup-lib.sh)
    #
107
    cat $OURDIR/mgmt-hosts > /etc/hosts.tmp
108 109 110
    # Some services assume they can resolve the hostname prior to network being
    # up (i.e. neutron-ovs-cleanup; see setup-ovs-node.sh).
    echo $MYIP `hostname` >> /etc/hosts.tmp
111
    cp -p /etc/hosts $OURDIR/hosts.orig
112 113 114 115 116
    cp -p /etc/hosts $OURDIR/hosts.stripped
    for node in $NODES ; do
	sed -i -e "s/[ ]$node\$//g" $OURDIR/hosts.stripped
    done
    cat $OURDIR/hosts.stripped >> /etc/hosts.tmp
117
    mv /etc/hosts.tmp /etc/hosts
118 119 120
    for node in $NODES 
    do
	[ "$node" = "$NETWORKMANAGER" ] && continue
121 122 123
	#if unified ; then
	#    continue
	#fi
124 125 126

	fqdn=`getfqdn $node`
	$SSH $fqdn mkdir -p $OURDIR
127 128 129 130
	#scp -p -o StrictHostKeyChecking=no \
	    #$SETTINGS $OURDIR/mgmt-hosts $OURDIR/mgmt-netmask \
	    #$OURDIR/data-hosts $OURDIR/data-netmask \
	    #$fqdn:$OURDIR
131
	scp -p -o StrictHostKeyChecking=no \
132
	    $OURDIR/mgmt-hosts $OURDIR/hosts.stripped $fqdn:$OURDIR
133 134
	# For now, just insert the new hosts in front of the existing ones.
	# setup-{ovs,linuxbridge}-node.sh may do differently.
135
	$SSH $fqdn "cp -p /etc/hosts $OURDIR/hosts.orig ; cat $OURDIR/mgmt-hosts > /etc/hosts.tmp ; cat $OURDIR/hosts.stripped >> /etc/hosts.tmp ; mv /etc/hosts.tmp /etc/hosts"
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    done

    echo "*** Setting up the Management Network"

    if [ -z "${MGMTLAN}" ]; then
	echo "*** Building a VPN-based Management Network"

	$DIRNAME/setup-vpn.sh 1> $OURDIR/setup-vpn.log 2>&1

        # Give the VPN a chance to settle down
	PINGED=0
	while [ $PINGED -eq 0 ]; do
	    sleep 2
	    ping -c 1 $CONTROLLER
	    if [ $? -eq 0 ]; then
		PINGED=1
	    fi
	done
    else
	echo "*** Using $MGMTLAN as the Management Network"
    fi

158 159
    if [ "${ML2PLUGIN}" = "openvswitch" ]; then
	echo "*** Moving Interfaces into OpenVSwitch Bridges"
160

161 162 163 164 165 166
	$DIRNAME/setup-ovs.sh 1> $OURDIR/setup-ovs.log 2>&1
    else
	echo "*** Setting up Linux Bridge static network configuration"

	$DIRNAME/setup-linuxbridge.sh 1> $OURDIR/setup-linuxbridge.log 2>&1
    fi
167 168 169 170 171 172

    echo "*** Telling controller to set up OpenStack!"

    ssh -o StrictHostKeyChecking=no ${CONTROLLER} "/bin/touch $OURDIR/networkmanager-driver-done"
fi

173 174 175
# Mark things as done right here, it's safe.
touch $OURDIR/setup-driver-done

176 177 178 179 180 181 182 183 184 185 186
if [ "$HOSTNAME" = "$CONTROLLER" ]; then
    #
    # Wait for networkmanager setup to touch a special file indicating that
    # it's finished all the network stuff and we should setup the controller.
    #
    echo "*** Waiting for networkmanager to finish network configuration..."

    while [ ! -f $OURDIR/networkmanager-driver-done ]; do
	sleep 1
    done

187 188
    logtend "driver"

189 190 191 192 193 194
    echo "*** Building an Openstack!"

    exec /bin/sh -c "$DIRNAME/setup-controller.sh 1> $OURDIR/setup-controller.log 2>&1 </dev/null"

    exit 1
elif [ "$HOSTNAME" != "$NETWORKMANAGER" ]; then
195
    logtend "driver"
196 197 198
    exit 0;
fi

199
logtend "driver"
200
exit 0