Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 77 additions & 26 deletions contrail.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# proto is https or ssh
#! /bin/bash

set -o errexit
# Contrail NFV
# ------------
source localrc
if [[ $EUID -eq 0 ]]; then
echo "You are running this script as root."
echo "Cut it out."
Expand All @@ -13,11 +14,12 @@ if [[ "$CONTRAIL_DEFAULT_INSTALL" != "True" ]]; then
else
ENABLED_SERVICES=redis,cass,zk,ifmap,disco,apiSrv,schema,svc-mon,control,collector,analytics-api,query-engine,agent,redis-w
fi

# Save trace setting
TOP_DIR=`pwd`
CONTRAIL_USER=$(whoami)
source functions
source localrc


# Determine what system we are running on. This provides ``os_VENDOR``,
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
Expand Down Expand Up @@ -271,6 +273,7 @@ function download_dependencies {
apt_get install python-setuptools
apt_get install python-novaclient
apt_get install curl
#trusty is not supporting chkconfig, so sysv-rc-conf used as equivalent
if [[ "$DISTRO" != "trusty" ]]; then
apt_get install chkconfig
else
Expand All @@ -280,7 +283,10 @@ function download_dependencies {
apt_get install default-jdk javahelper
apt_get install libcommons-codec-java libhttpcore-java liblog4j1.2-java
apt_get install python-software-properties
sudo -E add-apt-repository -y cloud-archive:havana
#havana is supported in precise only
if [[ "$DISTRO" != "trusty" ]]; then
sudo -E add-apt-repository -y cloud-archive:havana
fi
sudo -E add-apt-repository -y ppa:opencontrail/ppa
apt_get update

Expand All @@ -290,13 +296,13 @@ function download_dependencies {
apt_get install python-dev autoconf automake build-essential libtool protobuf-compiler libprotobuf-dev
apt_get install libevent-dev libxml2-dev libxslt-dev
apt_get install uml-utilities
apt_get install libvirt-bin
apt_get install python-software-properties
apt_get install python-lxml python-redis python-jsonpickle
apt_get install ant debhelper
apt_get install linux-headers-$(uname -r)
apt_get install libipfix
fi
fi
apt_get install libvirt-bin
apt_get install python-neutron
if [[ ${DISTRO} =~ (trusty) ]]; then
apt_get install software-properties-common
Expand Down Expand Up @@ -508,8 +514,11 @@ function build_contrail() {
C_GUID=$( id -g )
sudo mkdir -p /var/log/contrail
sudo chown $C_UID:$C_GUID /var/log/contrail
#changing the permissions if dir has some files
if [ "$(ls -A /var/log/contrail/ 2 > /dev/null)" != "" ]
then
sudo chmod 755 /var/log/contrail/*

fi
# basic dependencies
if ! which repo > /dev/null 2>&1 ; then
wget http://commondatastorage.googleapis.com/git-repo-downloads/repo
Expand Down Expand Up @@ -663,8 +672,10 @@ function install_contrail() {
apt_get install neutron-plugin-contrail
apt_get install contrail-config-openstack
#apt_get install neutron-plugin-contrail-agent contrail-config-openstack
apt_get install contrail-nova-driver
apt_get install contrail-web-core
apt_get install contrail-nova-driver
#installing nodejs version required by contrail-web-core
apt_get install nodejs=0.8.15-1contrail1
apt_get install contrail-web-core
apt_get install contrail-web-controller
apt_get install ifmap-server
apt_get install python-ncclient
Expand Down Expand Up @@ -847,9 +858,13 @@ function pywhere() {
function stop_contrail_services() {

services=(supervisor-analytics supervisor-control supervisor-config supervisor-vrouter contrail-analytics-api contrail-control contrail-query-engine contrail-vrouter-agent contrail-api contrail-discovery contrail-schema contrail-webui-jobserver contrail-collector contrail-dns contrail-svc-monitor contrail-webui-webserver ifmap-server)

for service in ${services[@]}
do
#checking for the services whice are started.
if [ "$(sudo service $service status | grep "start" 2>/dev/null)" != "" ];then
sudo service $service stop
fi
done
}

Expand Down Expand Up @@ -939,9 +954,14 @@ function start_contrail() {
screen_it query-engine "sudo PATH=$PATH:/usr/bin LD_LIBRARY_PATH=/usr/lib /usr/bin/contrail-query-engine"
fi
sleep 2


#use contrail-utils for provisioning another control node. To do so uncomment the below code
#provision control
python $TOP_DIR/provision_control.py --api_server_ip $SERVICE_HOST --api_server_port 8082 --host_name $HOSTNAME --host_ip $HOST_IP
#if [[ "$CONTRAIL_DEFAULT_INSTALL" != "True" ]]; then
# python /usr/share/contrail/provision_control.py --api_server_ip $SERVICE_HOST --api_server_port 8082 --host_name $HOSTNAME --host_ip $HOST_IP
#else
# python /usr/share/contrail-utils/provision_control.py --api_server_ip $SERVICE_HOST --api_server_port 8082 --host_name $HOSTNAME --host_ip $HOST_IP
#fi

# Provision Vrouter - must be run after API server and schema transformer are up
sleep 2
Expand Down Expand Up @@ -984,8 +1004,9 @@ openstack-dashboard.noarch 2012.1.3-1.fc17 updates
contrail-agent 1-1304091654 contrail-agent-1-1304091654.x86_64
EOF
EOF2
chmod a+x $TOP_DIR/bin/contrail-version
fi
chmod a+x $TOP_DIR/bin/contrail-version


if [[ "$CONTRAIL_DEFAULT_INSTALL" != "True" ]]; then
cat > $TOP_DIR/bin/vnsw.hlpr <<END
Expand Down Expand Up @@ -1035,8 +1056,22 @@ END
fi
fi
fi


#Checking whether all screens attached to contrail are up or not
SERVICES_ENABLED="$(echo $ENABLED_SERVICES | sed 's/,/ /g')"
echo "Enabled Services: $SERVICES_ENABLED"
screens_failed=""
for screen_name in $SERVICES_ENABLED
do
screen_log_name="screen-$screen_name.log"

if [ $(grep -c "failed to start" $TOP_DIR/log/screens/$screen_log_name) -eq 2 ];then
screens_failed="$screen_name,$screens_failed"
fi
done
if [ "$screens_failed" != "" ];then
echo "$screens_failed are failed to start. So exiting..."
exit 1
fi
# restore saved screen settings
SCREEN_NAME=$SAVED_SCREEN_NAME
return
Expand Down Expand Up @@ -1071,7 +1106,11 @@ function configure_contrail() {
sudo chown -R `whoami` /etc/contrail
sudo chmod 664 /etc/contrail/*
sudo chown -R `whoami` /etc/sysconfig/network-scripts
#changing permissions if dir is not empty
if [ "$(ls -A /etc/sysconfig/network-scripts/ 2 > /dev/null)" != "" ]
then
sudo chmod 664 /etc/sysconfig/network-scripts/*
fi
cd $TOP_DIR

#un-comment if required after review
Expand All @@ -1086,7 +1125,7 @@ function configure_contrail() {
#invoke functions to change the files
if [ "$INSTALL_PROFILE" = "ALL" ]; then
replace_api_server_conf
replace_contrail_plugin_conf
#replace_contrail_plugin_conf #same functionality is coming with devstack.
replace_contrail_schema_conf
replace_svc_monitor_conf
replace_discovery_conf
Expand Down Expand Up @@ -1124,12 +1163,12 @@ function stop_contrail() {
SAVED_SCREEN_NAME=$SCREEN_NAME
SCREEN_NAME="contrail"
SCREEN=$(which screen)
if [[ -n "$SCREEN" ]]; then
SESSION=$(screen -ls | awk '/[0-9].contrail/ { print $1 }')
if [[ -n "$SESSION" ]]; then
screen -X -S $SESSION quit
fi
fi
#if [[ -n "$SCREEN" ]]; then
# SESSION=$(screen -ls | awk '/[0-9].contrail/ { print $1 }')
# if [[ -n "$SESSION" ]]; then
# screen -X -S $SESSION quit
# fi
#fi
(cd $CONTRAIL_SRC/third_party/zookeeper-3.4.6; ./bin/zkServer.sh stop)
echo_summary "-----------------------STOPPING CONTRAIL--------------------------"
if [ "$INSTALL_PROFILE" = "ALL" ]; then
Expand All @@ -1149,16 +1188,28 @@ function stop_contrail() {
screen_stop ui-jobs
screen_stop ui-webs
fi
screen_stop agent
rm $CONTRAIL_DIR/status/contrail/*.failure /dev/null 2>&1
cmd=$(lsmod | grep vrouter)
if [ $? == 0 ]; then

screen_stop agent
if [[ -n "$SCREEN" ]]; then
SESSION=$(screen -ls | awk '/[0-9].contrail/ { print $1 }')
if [[ -n "$SESSION" ]]; then
screen -X -S $SESSION quit
fi
fi

CONTRAIL_DIR="/home/tcs/contrail-installer"
if [ $(ls $CONTRAIL_DIR/status/contrail/*.failure 2>/dev/null | wc -l) != 0 ];then
rm $CONTRAIL_DIR/status/contrail/*.failure 2>/dev/null
fi
#cmd=$(lsmod | grep vrouter)
#if [ $? == 0 ]; then
if [ "$(lsmod | grep vrouter 2>/dev/null)" != "" ]; then
cmd=$(sudo rmmod vrouter)
if [ $? == 0 ]; then
source /etc/contrail/contrail-compute.conf
if is_ubuntu; then
sudo ifdown $dev
sudo ifup $dev
sudo ifdown $dev
sudo ifup $dev
sudo ifdown vhost0

else
Expand Down
43 changes: 27 additions & 16 deletions contrail_config_functions
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ function replace_vnc_api_lib_conf()
file="/etc/contrail/vnc_api_lib.ini"
if [ "$CONTRAIL_DEFAULT_INSTALL" == "True" ]; then
check_replace_value $file global WEB_SERVER '127.0.0.1'
check_replace_value $file global WEB_PORT 8082 ; connection to api-server directly
check_replace_value $file global WEB_PORT 8082 #connection to api-server directly
check_replace_value $file global BASE_URL '/'

check_replace_value $file auth AUTHN_TYPE 'keystone'
Expand Down Expand Up @@ -492,7 +492,8 @@ function _rewrite_ifcfg_file()

if [[ ! -f $ifcfg_file ]]; then
ifcfg_file=$temp_dir_name'/ifcfg-'$dev
rm $ifcfg_file
#checking if the file exists before removing
[ -e $ifcfg_file ] && rm $ifcfg_file
echo "#Contrail-$dev" >> $ifcfg_file
echo "TYPE=Ethernet" >> $ifcfg_file
echo "ONBOOT=yes" >> $ifcfg_file
Expand Down Expand Up @@ -602,9 +603,10 @@ function replace_irond_basic_auth_users()
sudo chmod 664 $file1
fi
tmp_file="/etc/contrail/basicauthusers.properties"
sudo grep -q ^"# Contrail" $file
value=$?
if [[ $value -eq 1 ]]; then
#sudo grep -q ^"# Contrail" $file
#value=$?
#if [[ $value -eq 1 ]]; then
if [[ "$(sudo grep ^"# Contrail" $file)" = "" ]]; then
echo '# Contrail users' >> $file
sudo echo 'api-server:api-server' >> $file
sudo echo 'schema-transformer:schema-transformer' >> $file
Expand Down Expand Up @@ -660,9 +662,10 @@ function write_qemu_conf()
{
file="/etc/libvirt/qemu.conf"
temp_file="qemu.conf"
sudo grep -q ^"cgroup_device_acl" $file
value=$?
if [[ $value -eq 1 ]] ; then
#sudo grep -q ^"cgroup_device_acl" $file
#value=$?
#if [[ $value -eq 1 ]] ; then
if [[ $(sudo grep ^"cgroup_device_acl" $file) = "" ]] ; then
sudo cp $file $temp_file
sudo chown `whoami` $temp_file
sudo echo "cgroup_device_acl = [" >> $temp_file
Expand Down Expand Up @@ -713,19 +716,25 @@ function fixup_config_files()
fi

# Disable selinux
sudo sed 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config > config.new
sudo mv config.new /etc/selinux/config
setenforce 0
#selinux is not installed properly. So missing the config file. To selinux, it needs system reboot.
#sudo sed 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config > config.new
#sudo mv config.new /etc/selinux/config
#setenforce 0

# Disable iptables
# Disable iptables
# Trusty is not supporting chkconfig. sysv-rc-conf is used as equivalent package. iptables process is not present in precise
if [[ "$DISTRO" != "trusty" ]]; then
sudo chkconfig iptables off
#sudo chkconfig iptables off
:
else
sudo sysv-rc-conf iptables off
sudo sysv-rc-conf iptables off
fi

sudo iptables --flush

if [[ -f /etc/contrail/ctrl-details ]];then
sudo rm /etc/contrail/ctrl-details
fi
echo 'SERVICE_TOKEN='$SERVICE_TOKEN >> "/etc/contrail/ctrl-details"
echo 'ADMIN_PASSWORD='$ADMIN_PASSWORD >> "/etc/contrail/ctrl-details"
echo 'CONTROLLER='$OPENSTACK_IP >> "/etc/contrail/ctrl-details"
Expand Down Expand Up @@ -808,10 +817,12 @@ function fixup_config_files()
#migrate_routes $dev
:
fi
# Trusty is not supporting chkconfig. sysv-rc-conf is used as equivalent package. network process is not present in precise
if [[ "$DISTRO" != "trusty" ]]; then
sudo chkconfig network on
#sudo chkconfig network on
:
else
sudo sysv-rc-conf network on
fi

}
17 changes: 11 additions & 6 deletions functions
Original file line number Diff line number Diff line change
Expand Up @@ -1186,21 +1186,26 @@ function screen_stop() {
if is_service_enabled $1; then
# Kill via pid if we have one available
if [[ -r $SERVICE_DIR/$SCREEN_NAME/$1.pid ]]; then
sudo pkill -TERM -P $(cat $SERVICE_DIR/$SCREEN_NAME/$1.pid)
ret_val=$?
#sudo pkill -TERM -P $(cat $SERVICE_DIR/$SCREEN_NAME/$1.pid)
#ret_val=$?
#If the pid is not parent pid then kill the same process itself
if [[ $ret_val -ne 0 ]]; then
#if [[ $ret_val -ne 0 ]]; then
if [[ $(ps -ef | grep $(cat $SERVICE_DIR/$SCREEN_NAME/$1.pid) | wc -l 2>/dev/null) -gt 1 ]]; then
sudo kill -9 $(cat $SERVICE_DIR/$SCREEN_NAME/$1.pid)
fi
rm $SERVICE_DIR/$SCREEN_NAME/$1.pid
fi
if [[ "$1" == "agent" ]]; then
# Checking for .pid file before killing the screen
if [[ "$1" == "agent" ]] && [[ -r $SERVICE_DIR/$SCREEN_NAME/$1_1.pid ]]; then
sudo kill -9 $(cat $SERVICE_DIR/$SCREEN_NAME/$1_1.pid)
rm $SERVICE_DIR/$SCREEN_NAME/$1_1.pid
fi
if [[ "$USE_SCREEN" = "True" ]]; then
# Clean up the screen window
screen -S $SCREEN_NAME -p $1 -X kill
#assaign the status of killing the screen to a variable to avoid exiting from script.
status=$(echo $(screen -S $SCREEN_NAME -p $1 -X kill))
echo $status
#screen -S $SCREEN_NAME -p $1 -X kill
fi
fi
}
Expand Down Expand Up @@ -1243,7 +1248,7 @@ function screen_rc {
# This is used for ``service_check`` when all the ``screen_it`` are called finished
# init_service_check
function init_service_check() {
SCREEN_NAME=${SCREEN_NAME:-stack}
SCREEN_NAME=${SCREEN_NAME:-contrail}
SERVICE_DIR=${SERVICE_DIR:-${DEST}/status}

if [[ ! -d "$SERVICE_DIR/$SCREEN_NAME" ]]; then
Expand Down