Create a swap partition if needed for new servers
Add a script to handle cloud servers with no swap. This can be used before install_puppet when developers run it by hand, and is called directly by launch_node. If the host has no swap, create a swap partition from the ephemeral disk and use the remainder on /opt. Change-Id: Iac8bfe4924d8607ddbddc45312a51fe52eb4cdbc
This commit is contained in:
parent
259a08db2b
commit
2c8d19ab08
@ -83,6 +83,10 @@ def bootstrap_server(server, admin_pass, key, cert, environment, name,
|
||||
ssh_client.ssh('ping6 -c5 -Q 0x10 review.openstack.org '
|
||||
'|| ping6 -c5 -Q 0x10 wiki.openstack.org')
|
||||
|
||||
ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'make_swap.sh'),
|
||||
'make_swap.sh')
|
||||
ssh_client.ssh('bash -x make_swap.sh')
|
||||
|
||||
ssh_client.scp(os.path.join(SCRIPT_DIR, '..', 'install_puppet.sh'),
|
||||
'install_puppet.sh')
|
||||
ssh_client.ssh('bash -x install_puppet.sh')
|
||||
|
45
make_swap.sh
Normal file
45
make_swap.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2013 OpenStack Foundation
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
# If we're running on a cloud server with no swap, fix that:
|
||||
if [ `grep SwapTotal /proc/meminfo | awk '{ print $2; }'` -eq 0 ]; then
|
||||
if [ -b /dev/vdb ]; then
|
||||
DEV='/dev/vdb'
|
||||
elif [ -b /dev/xvde ]; then
|
||||
DEV='/dev/xvde'
|
||||
fi
|
||||
if [ -n "$DEV" ]; then
|
||||
MEMKB=`grep MemTotal /proc/meminfo | awk '{print $2; }'`
|
||||
# Use the nearest power of two in MB as the swap size.
|
||||
# This ensures that the partitions below are aligned properly.
|
||||
MEM=`python -c "import math ; print 2**int(round(math.log($MEMKB/1024, 2)))"`
|
||||
umount ${DEV}
|
||||
parted ${DEV} --script -- mklabel msdos
|
||||
parted ${DEV} --script -- mkpart primary linux-swap 1 ${MEM}
|
||||
parted ${DEV} --script -- mkpart primary ext2 ${MEM} -1
|
||||
mkswap ${DEV}1
|
||||
mkfs.ext4 ${DEV}2
|
||||
swapon ${DEV}1
|
||||
mount ${DEV}2 /mnt
|
||||
rsync -a /opt/ /mnt/
|
||||
umount /mnt
|
||||
echo "${DEV}1 none swap sw 0 0" >> /etc/fstab
|
||||
echo "${DEV}2 /opt ext4 errors=remount-ro,barrier=0 0 2" >> /etc/fstab
|
||||
mount -a
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user