"Fossies" - the Fresh Open Source Software Archive

Member "storlets-7.0.0/s2aio.sh" (14 Apr 2021, 3477 Bytes) of package /linux/misc/openstack/storlets-7.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    3 #    not use this file except in compliance with the License. You may obtain
    4 #    a copy of the License at
    5 #
    6 #         http://www.apache.org/licenses/LICENSE-2.0
    7 #
    8 #    Unless required by applicable law or agreed to in writing, software
    9 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   10 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   11 #    License for the specific language governing permissions and limitations
   12 #    under the License.
   13 
   14 set -e
   15 
   16 REPO_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
   17 DEVSTACK_DIR=~/devstack
   18 SWIFT_IP=127.0.0.1
   19 KEYSTONE_IP=$SWIFT_IP
   20 KEYSTONE_PROTOCOL=http
   21 KEYSTONE_PUBLIC_URL=${KEYSTONE_PROTOCOL}://${KEYSTONE_IP}/identity/v3
   22 IDENTITY_API_VERSION=3
   23 
   24 SWIFT_DATA_DIR=/opt/stack/data/swift
   25 
   26 function usage {
   27     echo "Usage: s2aio.sh install"
   28     echo "       s2aio.sh start"
   29     echo "       s2aio.sh stop"
   30     exit 1
   31 }
   32 
   33 function _prepare_devstack_env {
   34     # Checkout devstack
   35     if [ ! -e $DEVSTACK_DIR ]; then
   36         git clone git://github.com/openstack-dev/devstack.git $DEVSTACK_DIR
   37         if [ ${USE_PYTHON3} == "False" ]; then
   38           cp devstack/localrc.py2.sample $DEVSTACK_DIR/localrc
   39         else
   40           cp devstack/localrc.sample $DEVSTACK_DIR/localrc
   41         fi
   42     fi
   43 
   44     source $DEVSTACK_DIR/stackrc
   45     source $DEVSTACK_DIR/functions
   46     source $DEVSTACK_DIR/functions-common
   47     source $DEVSTACK_DIR/lib/swift
   48     source devstack/plugin.sh
   49 }
   50 
   51 function start_s2aio {
   52     set -e
   53     swift-init --run-dir ${SWIFT_DATA_DIR}/run/ all start
   54     /usr/local/bin/uwsgi /etc/keystone/keystone-uwsgi-public.ini &> /dev/null &
   55     /usr/local/bin/uwsgi /etc/keystone/keystone-uwsgi-admin.ini &> /dev/null &
   56     exit 0
   57 }
   58 
   59 function _stop_s2aio {
   60     set +e
   61     swift-init --run-dir ${SWIFT_DATA_DIR}/run/ all stop
   62     sh -c 'ps aux | pgrep uwsgi | xargs kill -9'
   63     set -e
   64 }
   65 
   66 function stop_s2aio {
   67     _stop_s2aio
   68     exit 0
   69 }
   70 
   71 function install_swift_using_devstack {
   72     cd $DEVSTACK_DIR
   73     ./stack.sh
   74     stop_swift
   75     cd -
   76 
   77     # add entry to fstab
   78     mount_added=$(grep swift.img /etc/fstab | wc -l)
   79     if [ $mount_added -eq 0 ]; then
   80         sudo sh -c 'echo "/opt/stack/data/swift/drives/images/swift.img /opt/stack/data/swift/drives/sdb1 xfs loop" >> /etc/fstab'
   81     fi
   82 }
   83 
   84 function install_s2aio {
   85     _prepare_devstack_env
   86 
   87     install_swift_using_devstack
   88     install_storlets
   89 
   90     echo "export OS_IDENTITY_API_VERSION=$KEYSTONE_IDENTITY_API_VERSION" >> ~/.bashrc
   91     echo "export OS_USERNAME=$SWIFT_DEFAULT_USER; export OS_PASSWORD=$SWIFT_DEFAULT_USER_PWD" >> ~/.bashrc
   92     echo "export OS_PROJECT_NAME=$SWIFT_DEFAULT_PROJECT; export OS_DEFAULT_DOMAIN=default" >> ~/.bashrc
   93     echo "export OS_AUTH_URL=$KEYSTONE_PUBLIC_URL" >> ~/.bashrc
   94 }
   95 
   96 function uninstall_swift_using_devstack {
   97     _stop_s2aio
   98     cd $DEVSTACK_DIR
   99     ./unstack.sh
  100     cd -
  101 
  102     echo "Removing swift device mount, creating /etc/fstab.bak"
  103     sudo sed -i.bak '/swift.img/d'  /etc/fstab
  104 }
  105 
  106 
  107 function uninstall_s2aio {
  108     _prepare_devstack_env
  109 
  110     echo "Removing all storlets run time data"
  111     uninstall_storlets
  112 
  113     echo "Uninstalling Swift"
  114     uninstall_swift_using_devstack
  115 }
  116 
  117 COMMAND="$1"
  118 case $COMMAND in
  119   "install" )
  120     install_s2aio
  121     ;;
  122 
  123   "uninstall" )
  124     uninstall_s2aio
  125     ;;
  126 
  127   "start" )
  128     start_s2aio
  129     ;;
  130 
  131   "stop" )
  132     stop_s2aio
  133     ;;
  134   * )
  135     usage
  136 esac
  137 
  138 set +e