Add start / stop to s2aio

s2aio uses a loop back device over a local file
as Swift device. This device may get corrupted
when rebooting the host while swift is running.
Adding the start and stop helps mitigate the problem

Also, with the recent move to devstack as the
installation script for Swift and Keystone
starting the swift and keystone services
have changed. Again, the s2aio start helps
here.

Change-Id: I3e3884a1a04888be577fe4f92d471a65f6f5ce5b
This commit is contained in:
Eran Rom 2016-11-08 22:20:01 +02:00 committed by Kota Tsuyuzaki
parent d0ceeb55ec
commit b3f3e0c44c
5 changed files with 138 additions and 54 deletions

View File

@ -15,3 +15,7 @@ rsync
xfsprogs
libssl-dev [platform:dpkg]
openssl-devel [platform:rpm]
# N.B. uwsgi-plugin-python is needed only for s2aio.sh start/stop for keystone
# so that we will be able to remove if devstack or devstack plugin installs it
uwsgi-plugin-python

View File

@ -1,20 +1,20 @@
s2aio
=====
s2aio is a script that installs Swift and Storlets all on one.
s2aio is a script that installs Swift (with Keystone) and Storlets all on one.
The script allows to do the installation either on the host
where it is invoked or in a Docker container.
To install on the host:
To install on the host:
.. include:: s2aio_dev_host_include.rst
To install in a Docker container follow the same steps,
replacing the last command with:
::
::
./s2aio dev docker
./s2aio.sh install dev docker
If you do not have Docker installed on your host, the above script
will install it and set docker to use "vfs" as the docker storage driver
@ -23,3 +23,21 @@ Docker installed, you may need to change its
storage driver to "vfs". The created Docker container runs yet another
container. Running Docker in Docker may require the usage of the "vfs" storage
device.
When installed on the host, the script can be used to start and stop all
relevant services using:
::
./s2aio.sh stop
and
::
./s2aio.sh start
For the Swift data, the s2aio installation uses a loopback device over a .img file.
When shutting down the host, the .img file may get corrupted. Thus, the above stop and
start commands are useful when using s2aio.sh for in a long lived hosts that can get rebooted
from time to time.

View File

@ -7,4 +7,4 @@ With that user just do:
sudo apt-get install python-tox python-nose git
git clone https://github.com/openstack/storlets.git
cd storlets
./s2aio.sh dev host
./s2aio.sh install dev host

158
s2aio.sh
View File

@ -1,44 +1,38 @@
#!/bin/bash
set -eu
# s2aio install from scratch an all in one swift with the storlet engine.
# s2aio has two flavors:
# s2aio controls an all in one installation of swift, keystone and storlets
# s2aio has 3 sub commands: install, start and stop
# install would install from scratch an all in one swift with the storlet engine.
# the installation has two flavors:
# 1. Jenkins job installation, for running the funciotal tests.
# 2. Developer instalation.
# start and stop are currently supported only for the host flavor.
if [ "$#" -ne 2 ]; then
echo "Usage: s2aio.sh <flavor> <target>"
usage() {
echo "Usage: s2aio.sh install <flavor> <target>"
echo " s2aio.sh start"
echo " s2aio.sh stop"
echo "flavor = jenkins | dev"
echo "target = host | docker"
exit 1
fi
}
FLAVOR="$1"
if [ "$FLAVOR" != "jenkins" ] && [ "$FLAVOR" != "dev" ]; then
echo "flavor must be either \"jenkins\" or \"dev\""
exit 1
fi
start_s2aio() {
set -e
swift-init --run-dir /opt/stack/data/swift/run/ all start
sudo mkdir -p /var/run/uwsgi
sudo chown ${USER}:`id -g -n ${USER}` /var/run/uwsgi
/usr/local/bin/uwsgi /etc/keystone/keystone-uwsgi-public.ini &> /dev/null &
/usr/local/bin/uwsgi /etc/keystone/keystone-uwsgi-admin.ini &> /dev/null &
exit 0
}
TARGET="$2"
if [ "$TARGET" != "host" ] && [ "$TARGET" != "docker" ]; then
echo "target must be either \"host\" or \"docker\""
exit 1
fi
stop_s2aio() {
sh -c 'swift-init --run-dir /opt/stack/data/swift/run/ all stop'
sh -c 'ps aux | pgrep uwsgi | xargs kill -9'
exit 0
}
# Make sure hostname is resolvable
grep -q -F ${HOSTNAME} /etc/hosts || sudo sed -i '1i127.0.0.1\t'"$HOSTNAME"'' /etc/hosts
install/install_ansible.sh
# Allow Ansible to ssh as the current user without a password
# While at it, take care of host key verification.
# This involves:
# 1. Generate an rsa key for the current user if necessary
if [ ! -f ~/.ssh/id_rsa.pub ]; then
ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ""
fi
if [ "$TARGET" == "docker" ]; then
# install docker
install_docker() {
sudo apt-get install apt-transport-https aufs-tools linux-image-generic-lts-xenial -y --force-yes
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
sudo sh -c "echo deb https://apt.dockerproject.org/repo ubuntu-xenial main > /etc/apt/sources.list.d/docker.list"
@ -46,10 +40,12 @@ if [ "$TARGET" == "docker" ]; then
sudo apt-get install docker-engine -y --force-yes
sudo sh -c "echo DOCKER_OPTS=\"--storage-driver=vfs\" >> /etc/default/docker"
sudo service docker restart
}
install_swift_on_container() {
# run the swift docker container
S2AIO_RUNNING=`sudo docker ps | grep s2aio | wc -l`
S2AIO_EXISTS=`sudo docker ps -a | grep s2aio | wc -l`
S2AIO_RUNNING=`sudo docker ps | grep -c s2aio`
S2AIO_EXISTS=`sudo docker ps -a | grep -c s2aio`
if [ "$S2AIO_RUNNING" == "0" ]; then
if [ "$S2AIO_EXISTS" == "1" ]; then
sudo docker rm s2aio
@ -58,6 +54,10 @@ if [ "$TARGET" == "docker" ]; then
fi
export S2AIO_IP=`sudo docker exec s2aio ifconfig | grep "inet addr" | head -1 | awk '{print $2}' | awk -F":" '{print $2}'`
# Take care of host key verification
touch ~/.ssh/known_hosts
ssh-keygen -R $S2AIO_IP -f ~/.ssh/known_hosts
ssh-keyscan -H $S2AIO_IP >> ~/.ssh/known_hosts
sudo docker exec s2aio sh -c "echo deb http://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse >> /etc/apt/sources.list"
sudo docker exec s2aio apt-get update
sudo docker exec s2aio apt-get install software-properties-common -y --force-yes
@ -69,12 +69,6 @@ if [ "$TARGET" == "docker" ]; then
# Add the key to the user's authorized keys
sudo docker exec s2aio mkdir -p /root/.ssh
sudo docker exec s2aio bash -c "echo `cat ~/.ssh/id_rsa.pub` > /root/.ssh/authorized_keys"
# Take care of host key verification for the current user
touch ~/.ssh/known_hosts
ssh-keygen -R $S2AIO_IP -f ~/.ssh/known_hosts
ssh-keyscan -H $S2AIO_IP >> ~/.ssh/known_hosts
sudo docker exec s2aio useradd stack
sudo docker exec s2aio mkdir /home/stack
sudo docker exec s2aio bash -c 'grep -q "^#includedir.*/etc/sudoers.d" /etc/sudoers ||\
@ -87,7 +81,9 @@ if [ "$TARGET" == "docker" ]; then
sudo docker exec --user stack s2aio chmod -R 0755 /home/stack
sudo docker exec --user stack s2aio /home/stack/install_swift.sh docker $S2AIO_IP
sudo docker exec s2aio service rsyslog restart
else
}
install_swift_on_host() {
export S2AIO_IP='127.0.0.1'
# Add the key to the user's authorized keys
@ -113,18 +109,84 @@ else
cd install/swift
./install_swift.sh host $S2AIO_IP
cd -
}
install_storlets() {
install/storlets/prepare_storlets_install.sh "$FLAVOR" "$TARGET"
# Install Storlets
cd install/storlets
./install_storlets.sh
cd -
# TODO: this is for tests. Deal accordingly.
cp install/storlets/deploy/cluster_config.json .
sudo chown $USER:$USER cluster_config.json
}
install_s2aio() {
# Make sure hostname is resolvable
grep -q -F ${HOSTNAME} /etc/hosts || sudo sed -i '1i127.0.0.1\t'"$HOSTNAME"'' /etc/hosts
install/install_ansible.sh
# Allow Ansible to ssh as the current user without a password
# While at it, take care of host key verification.
# This involves:
# 1. Generate an rsa key for the current user if necessary
if [ ! -f ~/.ssh/id_rsa.pub ]; then
ssh-keygen -q -t rsa -f ~/.ssh/id_rsa -N ""
fi
if [ "$TARGET" == "docker" ]; then
install_docker
install_swift_on_container
else
install_swift_on_host
fi
install_storlets
echo "export OS_IDENTITY_API_VERSION=3" >> ~/.bashrc
echo "export OS_USERNAME=tester; export OS_PASSWORD=testing" >> ~/.bashrc
echo "export OS_PROJECT_NAME=test; OS_DEFAULT_DOMAIN=default" >> ~/.bashrc
echo "export OS_AUTH_URL=http://"$S2AIO_IP":5000/v3" >> ~/.bashrc
}
set -eu
if [ "$#" -ne 1 ] && [ "$#" -ne 3 ]; then
usage
fi
install/storlets/prepare_storlets_install.sh "$FLAVOR" "$TARGET"
COMMAND="$1"
case $COMMAND in
"install" )
if [ "$#" -ne 3 ]; then
usage
fi
FLAVOR="$2"
if [ "$FLAVOR" != "jenkins" ] && [ "$FLAVOR" != "dev" ]; then
echo "flavor must be either \"jenkins\" or \"dev\""
exit 1
fi
TARGET="$3"
if [ "$TARGET" != "host" ] && [ "$TARGET" != "docker" ]; then
echo "target must be either \"host\" or \"docker\""
exit 1
fi
install_s2aio
;;
# Install Storlets
cd install/storlets
./install_storlets.sh
cd -
"start" )
start_s2aio
;;
# TODO: this is for tests. Deal accordingly.
cp install/storlets/deploy/cluster_config.json .
sudo chown $USER:$USER cluster_config.json
"stop" )
stop_s2aio
;;
* )
usage
esac
echo "export OS_IDENTITY_API_VERSION=3" >> ~/.bashrc
echo "export OS_USERNAME=tester; export OS_PASSWORD=testing" >> ~/.bashrc

View File

@ -1,2 +1,2 @@
#!/bin/bash
./s2aio.sh jenkins host
./s2aio.sh install jenkins host