Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -eu
- function print_help ()
- {
- echo <<EOF "Usage:
- Access to remote hosts:
- deploy.sh access <user> <password> <public_key> [host_list]
- Prepare remote machines:
- deploy.sh prepare_developer <user> [host_list]
- deploy.sh prepare_chroot <user> [host_list]
- deploy.sh prepare_runtime <user> [host_list]
- Build packages/repositories:
- deploy.sh build <packages_path>
- deploy.sh build_deps <packages_path>
- SciDB control on remote machines:
- deploy.sh scidb_install <packages_path> [host_list]
- deploy.sh scidb_remove <packages_path> [host_list]
- deploy.sh scidb_prepare <user> [host_list]
- deploy.sh scidb_start <user> <coordinator>
- Description:
- access provide access by ssh-key to [host_list] for <user>
- prepare_developer prepare [host_list] on <user> for build SciDB
- prepare_chroot prepare [host_list] on <user> for build SciDB packages
- prepare_runtime prepare [host_list] on <user> for run SciDB
- build build SciDB packages to <packages_path>
- build_deps build packages for dependencies to <packages_path>
- scidb_install install SciDB on [host_list] (expects you are registered required repositories)
- scidb_remove remove SciDB from [host_list]
- scidb_prepare prepare for run SciDB cluster on [host_list] (first host would considered as coordinator)"
- EOF
- exit 1
- }
- # detect directory where we run
- source_path=`dirname $0`
- source_path=`readlink -f ${source_path}/../`
- bin_path=${source_path}/deployment/common
- if [ -z "${bin_path}" ] ; then
- bin_path=./common
- fi
- echo "Source path: ${source_path}"
- echo "Script common path: ${bin_path}"
- function remote_no_pass ()
- {
- local username=${1}
- local password=${2}
- local hostname=${3}
- shift 3
- expect <<EOF
- set timeout -1
- spawn $@
- expect {
- "${username}@${hostname}'s password:" { send "${password}\r"; exp_continue }
- eof { }
- }
- EOF
- }
- function remote ()
- {
- local username=${1}
- local password=${2}
- local hostname=${3}
- local files=${5-""}
- remote_no_pass "${username}" "${password}" "${hostname}" "scp -q -o StrictHostKeyChecking=no -r ${bin_path} ${username}@${hostname}:/tmp/deployment"
- if [ -n "${files}" ]; then
- remote_no_pass "${username}" "${password}" "${hostname}" "scp -q -o StrictHostKeyChecking=no -r ${files} ${username}@${hostname}:/tmp/deployment"
- fi;
- remote_no_pass "${username}" "${password}" "${hostname}" "ssh -o StrictHostKeyChecking=no ${username}@${hostname} \"cd /tmp/deployment && ${4}\""
- remote_no_pass "${username}" "${password}" "${hostname}" "ssh -o StrictHostKeyChecking=no ${username}@${hostname}" "\"rm -rf /tmp/deployment\""
- }
- function provide_access ()
- {
- local username=${1}
- local password="${2}"
- local key=${3}
- local hostname=${4}
- if [ "${username}" != "root" ]; then
- echo "Check for ${username} on ${hostname}"
- remote root "${password}" "${hostname}" "./user_create.sh \\\"${username}\\\" \\\"${password}\\\""
- fi;
- echo "Provide access by ~/.ssh/id_rsa.pub to ${username}@${hostname}"
- remote "${username}" "${password}" "${hostname}" "./user_access.sh \\\"${username}\\\" \\\"${key}\\\""
- }
- function push_source ()
- {
- local username=${1}
- local result_path=`readlink -f ${2}`
- local hostname=${3}
- echo "Remove ${username}@${hostname}:${result_path}"
- remote_no_pass "${username}" "" "${hostname}" "ssh -o StrictHostKeyChecking=no ${username}@${hostname}" "\"rm -rf ${result_path}\""
- echo "Copy ${source_path} to ${username}@${hostname}:${result_path}"
- remote_no_pass "${username}" "" "${hostname}" "scp -q -o StrictHostKeyChecking=no -r ${source_path} ${username}@${hostname}:${result_path}"
- }
- function configure_rpm ()
- {
- build_kind=centos-6.3-x86_64
- suffix=rpm
- kind=rpm
- function package_info ()
- {
- rpm -qip ${1} | grep Name | awk '{print $3}'
- }
- install="yum install -y *.rpm"
- remove="yum remove -y"
- }
- function configure_deb ()
- {
- build_kind=ubuntu-precise-amd64
- suffix=deb
- kind=deb
- function package_info ()
- {
- dpkg -I ${1} | grep Package | awk '{print $2}'
- }
- install="dpkg -R -i ."
- remove="apt-get remove -y"
- }
- function configure_package_manager ()
- {
- local hostname=${1}
- local with_redhat=${2}
- FILE=/etc/issue
- if [ "${hostname}" != "localhost" ]; then
- remote_no_pass root "" "${hostname}" "scp -q -o StrictHostKeyChecking=no -r root@${hostname}:/etc/issue ./issue"
- FILE=./issue
- fi;
- local OS=`${bin_path}/os_detect.sh ${FILE}`
- if [ "${hostname}" != "localhost" ]; then
- rm -f ./issue
- fi;
- case "${OS}" in
- "CentOS 6.3")
- configure_rpm
- ;;
- "RedHat 6.3")
- if [ ${with_redhat} == 1 ]; then
- configure_rpm
- else
- echo "We do not support build SciDB under RedHat 6.3. Please use CentOS 6.3 instead"
- exit 1
- fi;
- ;;
- "Ubuntu 12.04")
- configure_deb
- ;;
- *)
- echo "Not supported OS"
- exit 1;
- ;;
- esac
- }
- function push_and_pull_packages ()
- {
- local username=${2}
- local hostname=${3}
- local push=${5}
- configure_package_manager ${hostname} 1
- local path_local=`readlink -f ${1}`
- local path_remote=`readlink -f ${4}`
- local scp_args_remote="${username}@${hostname}:${path_remote}/*"
- if [ $push == 1 ]; then
- remote_no_pass "${username}" "" "${hostname}" "rm -rf ${path_remote}"
- remote_no_pass "${username}" "" "${hostname}" "mkdir -p ${path_remote}"
- remote_no_pass "${username}" "" "${hostname}" "scp -q -o StrictHostKeyChecking=no ${path_local} ${scp_args_remote}"
- else
- rm -rf ${path_local}
- mkdir -p ${path_local}
- remote_no_pass "${username}" "" "${hostname}" "scp -q -o StrictHostKeyChecking=no ${scp_args_remote} ${path_local}"
- fi;
- }
- function build ()
- {
- configure_package_manager "localhost" 0
- local packages_path=`readlink -f ${1}`
- rm -rf ${packages_path}
- #(cd ${source_path}; cmake .; make -j5)
- (cd ${source_path}; ./utils/make_packages.sh ${kind} chroot ${packages_path} ${build_kind})
- #cp /tmp/scidb_packaging/chroot_result/* ${packages_path} || true
- }
- function setup_ccache ()
- {
- local username=${1}
- local hostname=${2}
- remote ${username} "" ${hostname} "./setup_ccache.sh"
- }
- function setup_main_scidb_repository()
- {
- local hostname=${1}
- echo "Setup main SciDB repository on ${hostname}"
- remote root "" ${hostname} "./setup_main_scidb_repository.sh"
- }
- function stop_virtual_bridge_zero ()
- {
- local hostname=${1}
- remote root "" ${hostname} "./stop_virbr0.sh"
- }
- function configure_postgresql ()
- {
- local username=${1}
- local hostname=${2}
- remote root "" ${hostname} "./configure_postgresql.sh ${username} 127.0.0.1/8"
- }
- function prepare_developer ()
- {
- local username=${1}
- local hostname=${2}
- echo "Prepare ${username}@${hostname} for developer"
- setup_main_scidb_repository "${hostname}"
- remote root "" ${hostname} "./prepare_developer.sh"
- setup_ccache ${username} ${hostname}
- configure_postgresql ${username} ${hostname}
- stop_virtual_bridge_zero "${hostname}"
- }
- function prepare_chroot ()
- {
- local username=${1}
- local hostname=${2}
- echo "Prepare for build SciDB packages in chroot on ${host}"
- setup_main_scidb_repository "${hostname}"
- remote root "" ${host} "./prepare_chroot.sh ${username}"
- remote ${username} "" ${host} "./chroot_build.sh" "${source_path}/utils/chroot_build.py"
- }
- function prepare_runtime ()
- {
- local username=${1}
- local hostname=${2}
- setup_main_scidb_repository "${hostname}"
- remote root "" ${hostname} "./prepare_runtime.sh"
- stop_virtual_bridge_zero "${hostname}"
- }
- function prepare_runtime_postgresql ()
- {
- local username=${1}
- local hostname=${2}
- configure_postgresql ${username} ${hostname}
- #echo "Perhaps you also need 'sudo -u postgres ./init-db.sh <user_name> <database_name> <user_password> <port=5432>'"
- }
- function package_names()
- {
- for file in $@; do
- package_info ${file}
- done;
- }
- function scidb_remove()
- {
- local hostname=${2}
- configure_package_manager ${hostname} 1
- local packages_path=`readlink -f ${1}`
- local packages=`ls ${packages_path}/*.${kind} | xargs`
- remote root "" "${hostname}" "${remove} `package_names ${packages} | xargs`"
- }
- function scidb_install()
- {
- local hostname=${2}
- local with_coordinator=${3}
- configure_package_manager ${hostname} 1
- local packages_path=`readlink -f ${1}`
- if [ ${with_coordinator} -eq 1 ]; then
- local packages=`ls ${packages_path}/*.${kind} | xargs`
- remote root "" "${hostname}" "${install}" "${packages}"
- else
- local packages=`ls ${packages_path}/*.${kind} | grep -v coord | xargs`
- remote root "" "${hostname}" "${install}" "${packages}"
- fi;
- }
- function scidb_config ()
- {
- local username="${1}"
- local password="${2}"
- local coordinator="${3}"
- shift 3
- echo "[scidb]"
- echo "server-0=${coordinator},1"
- node_number=1
- for hostname in $@; do
- echo "server-${node_number}=${hostname},2"
- let node_number++
- done;
- echo "db_user=${username}"
- echo "db_passwd=${password}"
- echo "install_root=/opt/scidb/12.11"
- echo "pluginsdir=/opt/scidb/12.11/lib/scidb/plugins"
- echo "logconf=/opt/scidb/12.11/share/scidb/log4cxx.properties"
- echo "base-path=/home/scidb/database"
- echo "tmp-path=/tmp"
- echo "base-port=1239"
- echo "interface=eth0"
- echo "no-watchdog=false"
- }
- function scidb_prepare_node ()
- {
- local username=${1}
- local hostname=${2}
- remote ${username} "" ${hostname} "./scidb_prepare.sh"
- remote root "" ${hostname} "cat config.ini > /opt/scidb/12.11/etc/config.ini" `readlink -f ./config.ini`
- }
- function scidb_prepare ()
- {
- local username=${1}
- local coordinator=${2}
- shift 2
- local coordinator_key="`ssh -o StrictHostKeyChecking=no scidb@${coordinator} \"cat ~/.ssh/id_rsa.pub\"`"
- scidb_config ${username} "scidb123" ${coordinator} "$@" | tee ./config.ini
- scidb_prepare_node ${username} ${coordinator}
- for hostname in $@; do
- scidb_prepare_node ${username} ${hostname}
- provide_access ${username} "" "${coordinator_key}" ${hostname}
- done;
- rm -f ./config.ini
- remote ${username} "" ${coordinator} "./scidb_prepare_coordinator.sh ${username} scidb123 ${username}"
- }
- function scidb_start ()
- {
- local username=${1}
- local coordinator=${2}
- remote ${username} "" ${coordinator} "scidb.py startall ${username}"
- }
- function prepare_httpd_cdash ()
- {
- username=${1}
- build_machine=${2}
- remote root "" ${build_machine} "./prepare_httpd_cdash.sh ${username}"
- }
- if [ $# -lt 1 ]; then
- print_help
- fi
- action=$1
- case ${action} in
- access)
- if [ $# -lt 4 ]; then
- print_help
- fi
- user=${2}
- password=${3}
- key="${4}"
- shift 4
- for host in $@; do
- provide_access ${user} "${password}" "${key}" "${host}"
- done;
- ;;
- push_source)
- if [ $# -lt 4 ]; then
- print_help
- fi
- user=${2}
- path=${3}
- shift 3
- for host in $@; do
- push_source ${user} ${path} ${host}
- done;
- ;;
- pull_packages)
- if [ $# -lt 5 ]; then
- print_help
- fi
- path_local=`readlink -f ${2}`
- username=${3}
- path_remote=`readlink -f ${4}`
- shift 4
- for hostname in $@; do
- push_and_pull_packages ${path_local} ${username} ${hostname} ${path_remote} 0
- done;
- ;;
- push_packages)
- if [ $# -lt 5 ]; then
- print_help
- fi
- path_local=`readlink -f ${2}`
- username=${3}
- path_remote=`readlink -f ${4}`
- shift 4
- for hostname in $@; do
- push_and_pull_packages ${path_local} ${username} ${hostname} ${path_remote} 1
- done;
- ;;
- prepare_developer)
- if [ $# -lt 3 ]; then
- print_help
- fi
- user=$2
- shift 2
- for host in $@; do
- prepare_developer ${user} "${host}"
- done;
- ;;
- prepare_chroot)
- if [ $# -lt 3 ]; then
- print_help
- fi
- user=$2
- shift 2
- for host in $@; do
- prepare_developer ${user} "${host}"
- prepare_chroot ${user} "${host}"
- done;
- ;;
- prepare_runtime)
- if [ $# -lt 3 ]; then
- print_help
- fi
- username=$2
- coordinator=${3}
- echo "Coordinator IP: ${coordinator}"
- shift 3
- for hostname in ${coordinator} $@; do
- prepare_runtime ${username} ${hostname}
- done;
- prepare_runtime_postgresql ${username} ${coordinator}
- ;;
- build)
- if [ $# -ne 2 ]; then
- print_help
- fi
- packages_path=${2}
- build "${packages_path}"
- ;;
- build_deps)
- if [ $# -ne 2 ]; then
- print_help
- fi
- packages_path=${2}
- echo "TODO build SciDB dependencies packages"
- ;;
- scidb_install)
- if [ $# -lt 3 ]; then
- print_help
- fi
- packages_path=${2}
- coordinator=${3}
- echo "Coordinator IP: ${coordinator}"
- shift 3
- scidb_install ${packages_path} ${coordinator} 1
- for hostname in $@; do
- scidb_install ${packages_path} ${hostname} 0
- done;
- ;;
- scidb_remove)
- if [ $# -lt 3 ]; then
- print_help
- fi
- packages_path=${2}
- shift 2
- for host in $@; do
- scidb_remove ${packages_path} ${host}
- done;
- ;;
- scidb_prepare)
- if [ $# -lt 3 ]; then
- print_help
- fi
- username=${2}
- shift 2
- scidb_prepare ${username} $@
- ;;
- scidb_start)
- if [ $# -lt 3 ]; then
- print_help
- fi
- username=${2}
- coordinator=${3}
- scidb_start ${username} ${coordinator}
- ;;
- prepare_httpd_cdash)
- if [ $# -lt 3 ]; then
- print_help
- fi;
- username=${2}
- shift 2
- for hostname in $@; do
- prepare_httpd_cdash ${username} ${hostname}
- done;
- ;;
- *)
- print_help
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement