Make compass work on both remote and local install.

Change-Id: I7a9b03bcf5fa6e2a4686a4e2a68dbcc2654cb93d
This commit is contained in:
Xicheng Chang 2016-09-14 11:32:07 -07:00
parent 682ca408d1
commit 0e61a12c76
13 changed files with 243 additions and 83 deletions

View File

@ -1,22 +1,3 @@
#!/bin/bash #!/bin/bash
set -e /opt/compass/bin/refresh_agent.sh
# systemctl restart mysql.service /opt/compass/bin/refresh_server.sh
# systemctl status mysql.service || exit $?
# /opt/compass/bin/manage_db.py createdb
/opt/compass/bin/clean_installers.py --noasync
/opt/compass/bin/clean_installation_logs.py
rm -rf /var/ansible/run/*
# systemctl restart httpd.service
# systemctl status httpd.service || exit $?
systemctl restart rsyslog.service
systemctl status rsyslog.service || exit $?
systemctl restart redis.service
systemctl status redis.service || exit $?
redis-cli flushall
systemctl restart cobblerd.service
systemctl status cobblerd.service || exit $?
systemctl restart compass-celeryd.service
systemctl status compass-celeryd.service || exit $?
# systemctl restart compass-progress-updated.service
# systemctl status compass-progress-updated.service || exit $?

22
bin/refresh_agent.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -e
# systemctl restart mysql.service
# systemctl status mysql.service || exit $?
# /opt/compass/bin/manage_db.py createdb
/opt/compass/bin/clean_installers.py --noasync
/opt/compass/bin/clean_installation_logs.py
rm -rf /var/ansible/run/*
# systemctl restart httpd.service
# systemctl status httpd.service || exit $?
systemctl restart rsyslog.service
systemctl status rsyslog.service || exit $?
systemctl restart redis.service
systemctl status redis.service || exit $?
redis-cli flushall
systemctl restart cobblerd.service
systemctl status cobblerd.service || exit $?
systemctl restart compass-celeryd.service
systemctl status compass-celeryd.service || exit $?
# systemctl restart compass-progress-updated.service
# systemctl status compass-progress-updated.service || exit $?

22
bin/refresh_server.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -e
systemctl restart mysql.service
systemctl status mysql.service || exit $?
/opt/compass/bin/manage_db.py createdb
# /opt/compass/bin/clean_installers.py --noasync
# /opt/compass/bin/clean_installation_logs.py
# rm -rf /var/ansible/run/*
systemctl restart httpd.service
systemctl status httpd.service || exit $?
systemctl restart rsyslog.service
systemctl status rsyslog.service || exit $?
systemctl restart redis.service
systemctl status redis.service || exit $?
redis-cli flushall
# systemctl restart cobblerd.service
# systemctl status cobblerd.service || exit $?
# systemctl restart compass-celeryd.service
# systemctl status compass-celeryd.service || exit $?
# systemctl restart compass-progress-updated.service
# systemctl status compass-progress-updated.service || exit $?

12
conf/celeryconfig_local Normal file
View File

@ -0,0 +1,12 @@
## Celery related setting: this is the default setting
CELERY_RESULT_BACKEND ="amqp://"
BROKER_URL = "amqp://guest:guest@localhost:5672//"
CELERY_IMPORTS=("compass.tasks.tasks",)
CELERY_ACCEPT_CONTENT = ['pickle', 'json', 'msgpack', 'yaml']
C_FORCE_ROOT = 1
CELERY_DEFAULT_QUEUE = 'admin@huawei.com'
CELERY_DEFAULT_EXCHANGE = 'admin@huawei.com'
CELERY_DEFAULT_ROUTING_KEY = 'admin@huawei.com'

View File

@ -42,6 +42,11 @@ sudo ln -s -f /opt/compass/bin/compass_wsgi.py /var/www/compass/compass.wsgi
sudo cp -rf $COMPASSDIR/bin/chef/* /opt/compass/bin/ sudo cp -rf $COMPASSDIR/bin/chef/* /opt/compass/bin/
sudo cp -rf $COMPASSDIR/bin/cobbler/* /opt/compass/bin/ sudo cp -rf $COMPASSDIR/bin/cobbler/* /opt/compass/bin/
if [ "$FULL_COMPASS_SERVER" == "false" ]; then
sudo rm -rf /opt/compass/bin/refresh.sh
sudo rm -rf /opt/compass/bin/refresh_server.sh
fi
if [[ $SUPPORT_CENTOS_7_2 != "y" ]]; then if [[ $SUPPORT_CENTOS_7_2 != "y" ]]; then
sudo rm -f /etc/compass/os/centos7.0.conf sudo rm -f /etc/compass/os/centos7.0.conf
fi fi
@ -88,6 +93,9 @@ sudo sed -i "s/\$hostname/$HOSTNAME/g" /etc/compass/setting
sudo sed -i "s/\$gateway/$OPTION_ROUTER/g" /etc/compass/setting sudo sed -i "s/\$gateway/$OPTION_ROUTER/g" /etc/compass/setting
domains=$(echo $NAMESERVER_DOMAINS | sed "s/,/','/g") domains=$(echo $NAMESERVER_DOMAINS | sed "s/,/','/g")
sudo sed -i "s/\$domains/$domains/g" /etc/compass/setting sudo sed -i "s/\$domains/$domains/g" /etc/compass/setting
if [ "$FULL_COMPASS_SERVER" == "true" ]; then
sudo sed -i "/DATABASE_SERVER =/c\DATABASE_SERVER = '127.0.0.1:3306'" /etc/compass/setting
fi
sudo sed -i "s/\$cobbler_ip/$IPADDR/g" /etc/compass/os_installer/cobbler.conf sudo sed -i "s/\$cobbler_ip/$IPADDR/g" /etc/compass/os_installer/cobbler.conf
#sudo sed -i "s/\$chef_ip/$IPADDR/g" /etc/compass/package_installer/chef-icehouse.conf #sudo sed -i "s/\$chef_ip/$IPADDR/g" /etc/compass/package_installer/chef-icehouse.conf
@ -120,17 +128,26 @@ else
echo "redis is not running" echo "redis is not running"
exit 1 exit 1
fi fi
if [ "$FULL_COMPASS_SERVER" == "true" ]; then
wget -O /tmp/aws_credentials "http://www.stack360.io/aws_credentials" sudo mv /etc/compass/celeryconfig_local /etc/compass/celeryconfig
filename='/tmp/aws_credentials' else
id=$(sed -n '1p' < $filename) sudo mv /etc/compass/celeryconfig_remote /etc/compass/celeryconfig
key=$(sed -n '2p' < $filename) wget -O /tmp/aws_credentials "http://www.stack360.io/aws_credentials"
sudo sed -i "s~ACCESS_ID~$id~g" /etc/compass/celeryconfig filename='/tmp/aws_credentials'
sudo sed -i "s~ACCESS_KEY~$key~g" /etc/compass/celeryconfig id=$(sed -n '1p' < $filename)
key=$(sed -n '2p' < $filename)
sudo sed -i "s~ACCESS_ID~$id~g" /etc/compass/celeryconfig
sudo sed -i "s~ACCESS_KEY~$key~g" /etc/compass/celeryconfig
fi
sudo systemctl enable compass-progress-updated.service sudo systemctl enable compass-progress-updated.service
sudo systemctl enable compass-celeryd.service sudo systemctl enable compass-celeryd.service
/opt/compass/bin/refresh.sh if [ "$FULL_COMPASS_SERVER" == "true" ]; then
/opt/compass/bin/refresh.sh
else
/opt/compass/bin/refresh_agent.sh
fi
if [[ "$?" != "0" ]]; then if [[ "$?" != "0" ]]; then
echo "failed to refresh compassd service" echo "failed to refresh compassd service"
exit 1 exit 1
@ -154,11 +171,22 @@ else
echo "redis has already started" echo "redis has already started"
fi fi
# sudo systemctl status mysql.service |grep running if [ "$FULL_COMPASS_SERVER" == "true" ]; then
# if [[ "$?" != "0" ]]; then sudo systemctl status mysql.service |grep running
# echo "mysqld is not started" if [[ "$?" != "0" ]]; then
# exit 1 echo "mysqld is not started"
# fi exit 1
fi
#sudo systemctl status compass-progress-updated.service |grep running
#if [[ "$?" != "0" ]]; then
# echo "compass-progress-updated is not started"
# exit 1
#else
# echo "compass-progress-updated has already started"
#fi
fi
sudo systemctl status compass-celeryd.service |grep running sudo systemctl status compass-celeryd.service |grep running
if [[ "$?" != "0" ]]; then if [[ "$?" != "0" ]]; then
@ -168,14 +196,6 @@ else
echo "compass-celeryd has already started" echo "compass-celeryd has already started"
fi fi
# sudo systemctl status compass-progress-updated.service |grep running
# if [[ "$?" != "0" ]]; then
# echo "compass-progress-updated is not started"
# exit 1
#else
# echo "compass-progress-updated has already started"
#fi
sleep 10 sleep 10
#compass check #compass check
#if [[ "$?" != "0" ]]; then #if [[ "$?" != "0" ]]; then

14
install/env.conf Executable file
View File

@ -0,0 +1,14 @@
NIC=${NIC:-eth1}
IPADDR=${IPADDR:-10.1.10.15}
NETMASK=${NETMASK:-255.255.255.0}
WEB_SOURCE=${WEB_SOURCE:-http://git.openstack.org/openstack/compass-web}
ADAPTERS_SOURCE=${ADAPTERS_SOURCE:-https://gerrit.opnfv.org/gerrit/compass4nfv}
OPTION_ROUTER=${OPTION_ROUTER:-10.1.10.15}
NAMESERVER_DOMAINS=${NAMESERVER_DOMAINS:-ods.com}
NAMESERVER_REVERSE_ZONES=${NAMESERVER_REVERSE_ZONES:-unused}
NEXTSERVER=${NEXTSERVER:-10.1.10.15}
IP_START=${IP_START:-10.1.10.100}
IP_END=${IP_END:-10.1.10.200}
LOCAL_REPO=${LOCAL_REPO:-}
SUPPORT_CENTOS_7_2=${SUPPORT_CENTOS_7_2:-}
SUPPORT_UBUNTU_14_04_03=${SUPPORT_UBUNTU_14_04_03:-}

View File

@ -2,9 +2,11 @@
# Config File for Compass Installer # # Config File for Compass Installer #
##################################### #####################################
# Agent or Fullserver # Agent or Fullserver
export FULL_COMPASS_SERVER="false" export FULL_COMPASS_SERVER="true"
# User Email # User Email
export USER_EMAIL="lab@huawei.com" export USER_EMAIL="test@huawei.com"
# User Password
export USER_PASSWORD=
# OS_INSTALLER indicates the tool for OS provisioning, default is 'cobbler'. # OS_INSTALLER indicates the tool for OS provisioning, default is 'cobbler'.
export OS_INSTALLER="cobbler" export OS_INSTALLER="cobbler"
@ -33,17 +35,17 @@ export PUBLIC_GATEWAY=
# Install network config, it is a private network # Install network config, it is a private network
export NIC="eth1" export NIC="eth1"
export IPADDR="10.1.0.15" export IPADDR="10.1.10.15"
export NETMASK="255.255.255.0" export NETMASK="255.255.255.0"
# DHCP config for install network # DHCP config for install network
# DHCP option router address(Default is your management interface IP address )" # DHCP option router address(Default is your management interface IP address )"
export OPTION_ROUTER="10.1.0.15" export OPTION_ROUTER="10.1.10.15"
# The IP range for DHCP clients (Default: local subnet start from 100 to 254) # The IP range for DHCP clients (Default: local subnet start from 100 to 254)
export IP_START="10.1.0.100" export IP_START="10.1.10.100"
export IP_END="10.1.0.200" export IP_END="10.1.10.200"
# TFTP server's IP address(Default: Management Interface/eth0 IP) # TFTP server's IP address(Default: Management Interface/eth0 IP)
export NEXTSERVER="10.1.0.15" export NEXTSERVER="10.1.10.15"
# The machines MAC list. it must be filled, any space or null is wrong in quotes: # The machines MAC list. it must be filled, any space or null is wrong in quotes:
export switch_IP="127.0.0.1" export switch_IP="127.0.0.1"

View File

@ -346,7 +346,7 @@ source ${COMPASSDIR}/install/ansible.sh || exit $?
echo "Install log agent." echo "Install log agent."
source ${COMPASSDIR}/install/logstash-forwarder.sh || exit $? source ${COMPASSDIR}/install/logstash-forwarder.sh || exit $?
if [ "$FULL_COMPASS_SERVER" == "true"]; then if [ "$FULL_COMPASS_SERVER" == "true" ]; then
echo "Download and install Compass Web" echo "Download and install Compass Web"
source ${COMPASSDIR}/install/compass_web.sh || exit $? source ${COMPASSDIR}/install/compass_web.sh || exit $?
fi fi
@ -357,7 +357,7 @@ source ${COMPASSDIR}/install/compass.sh || exit $?
figlet -ctf slant Installation Complete! figlet -ctf slant Installation Complete!
echo -e "It takes\x1b[32m $SECONDS \x1b[0mseconds during the installation." echo -e "It takes\x1b[32m $SECONDS \x1b[0mseconds during the installation."
if [[ "${FULL_COMPASS_SERVER}" == "false" ]]; then if [ "$FULL_COMPASS_SERVER" == "false" ]; then
machine_list_conf="MACHINE_LIST = [ { '${switch_IP}': [ " machine_list_conf="MACHINE_LIST = [ { '${switch_IP}': [ "
for host in ${PXE_MACs[@]}; do for host in ${PXE_MACs[@]}; do
port=$(echo ${host} | awk -F , '{print $1}' | awk -F = '{print $2}') port=$(echo ${host} | awk -F , '{print $1}' | awk -F = '{print $2}')
@ -375,31 +375,34 @@ if [[ "${FULL_COMPASS_SERVER}" == "false" ]]; then
# rm -rf /var/ansible/openstack_mitaka/HA-ansible-multinodes.yml 2>/dev/null # rm -rf /var/ansible/openstack_mitaka/HA-ansible-multinodes.yml 2>/dev/null
# cp ${COMPASSDIR}/misc/adapter_changes/HA-ansible-multinodes.yml /var/ansible/openstack_mitaka/ # cp ${COMPASSDIR}/misc/adapter_changes/HA-ansible-multinodes.yml /var/ansible/openstack_mitaka/
rm -rf /var/lib/cobbler/snippets/preseed_post_anamon 2>/dev/null rm -rf /var/lib/cobbler/snippets/preseed_post_anamon 2>/dev/null
cp ${COMPASSDIR}/misc/adapter_changes/preseed_post_anamon /var/lib/cobbler/snippets/ cp ${COMPASSDIR}/misc/adapter_changes/preseed_post_anamon_remote /var/lib/cobbler/snippets/preseed_post_anamon
else
sed -i 's/^CELERY_DEFAULT_QUEUE.*/CELERY_DEFAULT_QUEUE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig rm -rf /var/lib/cobbler/snippets/preseed_post_anamon 2>/dev/null
sed -i 's/^CELERY_DEFAULT_EXCHANGE.*/CELERY_DEFAULT_EXCHANGE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig cp ${COMPASSDIR}/misc/adapter_changes/preseed_post_anamon_local /var/lib/cobbler/snippets/preseed_post_anamon
sed -i 's/^CELERY_DEFAULT_ROUTING_KEY.*/CELERY_DEFAULT_ROUTING_KEY = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig fi
# Restart services # sudo sed -i 's/^CELERY_DEFAULT_QUEUE.*/CELERY_DEFAULT_QUEUE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig
systemctl restart httpd.service # sudo sed -i 's/^CELERY_DEFAULT_EXCHANGE.*/CELERY_DEFAULT_EXCHANGE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig
sleep 10 # sudo sed -i 's/^CELERY_DEFAULT_ROUTING_KEY.*/CELERY_DEFAULT_ROUTING_KEY = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig
echo "Checking if httpd is running"
sudo systemctl status httpd.service # Restart services
if [[ "$?" == "0" ]]; then systemctl restart httpd.service
echo "httpd is running" sleep 10
else echo "Checking if httpd is running"
echo "httpd is not running" sudo systemctl status httpd.service
exit 1 if [[ "$?" == "0" ]]; then
fi echo "httpd is running"
else
systemctl restart compass-celeryd.service echo "httpd is not running"
echo "Checking if httpd is running" exit 1
sudo systemctl status compass-celeryd.service fi
if [[ "$?" == "0" ]]; then
echo "celeryd is running" systemctl restart compass-celeryd.service
else echo "Checking if httpd is running"
echo "celeryd is not running" sudo systemctl status compass-celeryd.service
exit 1 if [[ "$?" == "0" ]]; then
fi echo "celeryd is running"
else
echo "celeryd is not running"
exit 1
fi fi

View File

@ -104,7 +104,7 @@ else
fi fi
#update mysqld #update mysqld
if [ "$FULL_COMPASS_SERVER" == "true"]; then if [ "$FULL_COMPASS_SERVER" == "true" ]; then
echo "update mysqld" echo "update mysqld"
mkdir -p /var/log/mysql mkdir -p /var/log/mysql
chmod -R 777 /var/log/mysql chmod -R 777 /var/log/mysql

View File

@ -6,15 +6,19 @@ source install.conf
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
echo "The email address you use to register is ${USER_EMAIL}" echo "The email address you use to register is ${USER_EMAIL}"
password=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6` password=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c6`
data=`echo "{\"email\":\"${USER_EMAIL}\",\"password\":\"${password}\"}"` USER_PASSWORD="${USER_PASSWORD:-$password}"
wget -O /tmp/user_info --post-data=$data --header=Content-Type:application/json "http://www.stack360.io/api/users/register" data=`echo "{\"email\":\"${USER_EMAIL}\",\"password\":\"${USER_PASSWORD}\"}"`
COMPASS_API_SERVER="c.stack360.io"
if [ "$FULL_COMPASS_SERVER" == "true" ]; then
COMPASS_API_SERVER="127.0.0.1"
fi
wget -O /tmp/user_info --post-data=$data --header=Content-Type:application/json "http://$COMPASS_API_SERVER/api/users/register"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "Register failed" echo "Register failed"
exit 1 exit 1
fi fi
echo "Register suceeded, your password is $password, please remember your password at all times." echo "Register suceeded, your password is $USER_PASSWORD, please remember your password at all times."
sudo sed -i 's/^CELERY_DEFAULT_QUEUE.*/CELERY_DEFAULT_QUEUE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig sudo sed -i 's/^CELERY_DEFAULT_QUEUE.*/CELERY_DEFAULT_QUEUE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig
sudo sed -i 's/^CELERY_DEFAULT_EXCHANGE.*/CELERY_DEFAULT_EXCHANGE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig sudo sed -i 's/^CELERY_DEFAULT_EXCHANGE.*/CELERY_DEFAULT_EXCHANGE = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig
sudo sed -i 's/^CELERY_DEFAULT_ROUTING_KEY.*/CELERY_DEFAULT_ROUTING_KEY = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig sudo sed -i 's/^CELERY_DEFAULT_ROUTING_KEY.*/CELERY_DEFAULT_ROUTING_KEY = \"'"${USER_EMAIL}"'\"/g' /etc/compass/celeryconfig

View File

@ -0,0 +1,80 @@
#if $str($getVar('anamon_enabled','')) == "1"
## install anamon script
#if $getVar("compass_server", "") != ""
wget -O /usr/local/sbin/anamon "http://$compass_server:$http_port/cobbler/aux/anamon"
#else
wget -O /usr/local/sbin/anamon "http://$server:$http_port/cobbler/aux/anamon"
#end if
## install anamon system service
cat << EOF > /etc/init.d/anamon.init
#raw
#!/bin/bash
## BEGIN INIT INFO
# Provides: anamon.init
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Required-Start: $network
# Short-Description: Starts the cobbler anamon boot notification program
# Description: anamon runs the first time a machine is booted after
# installation.
## END INIT INFO
#
# anamon.init: Starts the cobbler post-install boot notification program
#
# chkconfig: 35 95 95
#
# description: anamon runs the first time a machine is booted after
# installation.
#
#end raw
cd /var/log/installer
gunzip initial-status.gz
cd -
#if $getVar("compass_server","") != ""
/usr/local/sbin/anamon --watchfile "/var/log/installer/syslog /var/log/installer/hardware-summary /var/log/installer/initial-status /var/log/installer/status" --name $name --server $compass_server --port $http_port --exit
#else
/usr/local/sbin/anamon --watchfile "/var/log/installer/syslog /var/log/installer/hardware-summary /var/log/installer/initial-status /var/log/installer/status" --name $name --server $server --port $http_port --exit
#end if
update-rc.d -f anamon remove
mv /etc/init.d/anamon.init /tmp/anamon.init
EOF
## adjust permissions
chmod 755 /etc/init.d/anamon.init /usr/local/sbin/anamon
test -d /selinux && restorecon /etc/init.d/anamon.init /usr/local/sbin/anamon
## enable the script
update-rc.d anamon.init defaults 95 95
#end if
## place start-up script for updating os state
#if $getVar('compass_server', '') != ""
#set srv = $getVar('compass_server','')
#else
#set srv = $getVar('server','')
#end if
cat << EOF > /etc/init.d/set_state
#raw
#!/bin/bash
# Provides: set_state
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Required-Start: $network $ssh
# Short-Description: Notifies the os installation is finished
# Description: set_state runs the first time a machine is booted after
# installation.
#end raw
wget -O /tmp/os_state --post-data='{"ready": true}' --header=Content-Type:application/json "http://$srv/api/hosts/${host_id}/state_internal"
update-rc.d -f set_state remove
mv /etc/init.d/set_state /tmp/set_state
EOF
## adjust permissions
chmod 755 /etc/init.d/set_state
test -d /selinux && restorecon /etc/init.d/set_state
update-rc.d set_state defaults 99 99
echo "compass_server=$server" >> /etc/compass.conf