diff --git a/scripts/centos_prepare_ovpl.sh b/scripts/centos_prepare_ovpl.sh index 94003a2..6449a6d 100755 --- a/scripts/centos_prepare_ovpl.sh +++ b/scripts/centos_prepare_ovpl.sh @@ -2,55 +2,152 @@ # Script to setup a fresh installation of CentOS to run OVPL # Installs: Dependencies: python-devel, git, pip; mongodb; openvz. +# read proxy settings from config file +if [[ -f "config.sh" ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Reading config.sh file for proxy settings" 2>&1 | tee -a $LOGFILE + source ./config.sh + if [[ -n $http_proxy ]]; then + + export http_proxy=$http_proxy + echo "[[$DATE:: $0 :: Line $LINENO::]] export http_proxy = $http_proxy" 2>&1 | tee -a $LOGFILE + fi + if [[ -n $https_proxy ]]; then + export https_proxy=$https_proxy + echo "[[$DATE:: $0 :: Line $LINENO::]] export https_proxy = $https_proxy" 2>&1 | tee -a $LOGFILE + fi +else + echo "[[$DATE:: $0 :: Line $LINENO::]] config.sh file not exist" 2>&1 | tee -a $LOGFILE + exit 1 +fi + +if [[ -f $LOGFILE ]];then + echo "=================================================" + echo "logfilepath = setup-ovpl-centos/scripts/$LOGFILE" + echo "=================================================" +else + touch $LOGFILE + echo "=================================================" + echo "logfilepath = setup-ovpl-centos/scripts/$LOGFILE" + echo "=================================================" +fi + # check if script is run as root if [[ $UID -ne 0 ]]; then echo "" echo "$0 must be run as root!" - echo "Exiting.." + echo "[[$DATE:: $0 :: Line $LINENO::]] $0 must be run as root...." 2>&1 | tee -a $LOGFILE + echo "check log file exiting...." exit 1 + +else + echo "[[$DATE:: $0 :: Line $LINENO::]] Started Invoking centos_prepare_ovpl.sh...." 2>&1 | tee -a $LOGFILE + fi # check if meta directory exists if [[ ! -d "../meta" ]]; then echo "" - echo "You don't have the necessary files." - echo "Please contact the author of the script." + echo "[[$DATE:: $0 :: Line $LINENO::]] You don't have the necessary files please contact the author of the script...." 2>&1 | tee -a $LOGFILE + echo "Check log file exiting...." exit 1 -fi -# read proxy settings from config file -source ./config.sh +fi -if [[ -n $http_proxy ]]; then - echo $http_proxy - export http_proxy=$http_proxy +#updating system +echo "" +echo "========================== UPDATING SYSTEM ================================" +echo "[[$DATE:: $0 :: Line $LINENO::]] Updating System...." 2>&1 | tee -a $LOGFILE +yum update -y +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in updating system " 2>&1 | tee -a $LOGFILE + exit 1 +else + echo "" + echo "[[$DATE:: $0 :: Line $LINENO::]] System updation complete.." 2>&1 | tee -a $LOGFILE + echo "" fi -if [[ -n $https_proxy ]]; then - export https_proxy=$https_proxy + + +if [[ -f "install_dependencies.sh" ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Invoking install_dependencies.sh" 2>&1 | tee -a $LOGFILE + ./install_dependencies.sh + if [ $? -ne 0 ]; then + echo "" + echo "[[$DATE:: $0 :: Line $LINENO::]] Error installing dependencies. Quitting!" 2>&1 | tee -a $LOGFILE + echo "======================" + echo "See logs at $LOGFILE" + echo "=====================" + exit 1 + else + echo "[[$DATE:: $0 :: Line $LINENO::]] successfully installed dependencies..." 2>&1 | tee -a $LOGFILE + + fi +else + echo "[[$DATE:: $0 :: Line $LINENO::]] install_dependencies.sh file not exist" 2>&1 | tee -a $LOGFILE + exit 1 fi -echo "Invoking install_dependencies.sh" -./install_dependencies.sh -if [ $? -ne 0 ]; then - echo "" - echo "Error installing dependencies. Quitting!" - exit 1 +if [[ -f "install_openvz.sh" ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Invoking install_openvz.sh" 2>&1 | tee -a $LOGFILE + ./install_openvz.sh + if [ $? -ne 0 ]; then + echo "" + echo "[[$DATE:: $0 :: Line $LINENO::]] Error installing openvz. Quitting!" 2>&1 | tee -a $LOGFILE + echo "======================" + echo "See logs at $LOGFILE" + echo "=====================" + exit 1 + else + echo "[[$DATE:: $0 :: Line $LINENO::]] successfully installed openvz..." 2>&1 | tee -a $LOGFILE + + + fi +else + echo "[[$DATE:: $0:: Line $LINENO::]] install_openvz.sh file not exist" 2>&1 | tee -a $LOGFILE + exit 1 fi -echo "Invoking install_openvz.sh" -./install_openvz.sh -if [ $? -ne 0 ]; then - echo "" - echo "Error installing OpenVZ. Quitting!" - exit 1 +if [[ -f "install_mongodb.sh" ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Invoking install_mongodb.sh" 2>&1 | tee -a $LOGFILE + ./install_mongodb.sh + if [ $? -ne 0 ]; then + echo "" + echo "[[$DATE:: $0 :: Line $LINENO::]] Error installing mongodb. Quitting! " 2>&1 | tee -a $LOGFILE + echo "======================" + echo "See logs at $LOGFILE" + echo "=====================" + exit 1 + + else + echo "[[$DATE:: $0 :: Line $LINENO::]] successfully installed mongodb..." 2>&1 | tee -a $LOGFILE + + fi +else + echo "[[$DATE:: $0 :: Line $LINENO::]] install_mongodb.sh file not exist" 2>&1 | tee -a $LOGFILE + exit 1 fi -echo "Invoking install_mongodb.sh" -./install_mongodb.sh -if [ $? -ne 0 ]; then - echo "" - echo "Error installing MongoDB. Quitting!" - exit 1 +if [[ -f "install_ovpl.sh" ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Invoking install_ovpl.sh" 2>&1 | tee -a $LOGFILE + ./install_ovpl.sh + if [ $? -ne 0 ]; then + echo "" + echo "[[$DATE:: $0 :: Line $LINENO::]] Error installing ovpl. Quitting! " 2>&1 | tee -a $LOGFILE + echo "======================" + echo "See logs at $LOGFILE" + echo "=====================" + exit 1 + else + + echo "==========================================================================================================" + echo "[[$DATE:: $0 :: Line $LINENO::]] Congrats! You have setup OVPL successfully!!! :-)" 2>&1 | tee -a $LOGFILE + echo "Now run 'make' from inside the src directory" + echo " of OVPL to start the services." + echo "==========================================================================================================" + fi +else + echo "[[$DATE:: $0 :: Line $LINENO::]] install_ovpl.sh file not exist" 2>&1 | tee -a $LOGFILE + exit 1 fi exit 0 diff --git a/scripts/config.sh b/scripts/config.sh index 68f2415..1d46944 100755 --- a/scripts/config.sh +++ b/scripts/config.sh @@ -8,3 +8,7 @@ export http_proxy="" #set your https proxy. Similar to the above. export https_proxy="" + +#Loggfile name +export LOGFILE="setup-ovpl.log" +export DATE=$(date) diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index c36cf6f..694ccca 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -2,14 +2,18 @@ meta_dir="../meta" -echo "" -echo "Setting up EPEL repo.." #wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm +echo "[[$DATE:: $0 :: Line $LINENO::]] Setting up EPEL repo.." 2>&1 | tee -a $LOGFILE rpm -ivh $meta_dir/epel-release-6-8.noarch.rpm -#rm epel-release-6.8.noarch.rpm -echo "" -echo "Installing dependencies.. yum -y install gcc python-devel.x86_64 python-pip ssh git" -yum -y install gcc python-devel.x86_64 python-pip ssh git +echo "[[$DATE:: $0 :: Line $LINENO::]] Installing dependencies.. " 2>&1 | tee -a $LOGFILE +echo "[[$DATE:: $0 :: Line $LINENO::]] Running yum -y install gcc python-devel.x86_64 python-pip openssh-clients openssh-server git" 2>&1 | tee -a $LOGFILE +yum -y install gcc python-devel.x86_64 python-pip openssh-clients openssh-server git +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in installing dependencies.." 2>&1 | tee -a $LOGFILE + exit 1 +else + echo "[[$DATE:: $0 :: Line $LINENO::]] Completed installation of gcc python-devel.x86_64 python-pip openssh-clients openssh-server git" 2>&1 | tee -a $LOGFILE +fi exit 0 diff --git a/scripts/install_mongodb.sh b/scripts/install_mongodb.sh index a612310..59883d9 100755 --- a/scripts/install_mongodb.sh +++ b/scripts/install_mongodb.sh @@ -2,18 +2,30 @@ # Script to setup repo and install MongoDB meta_dir="../meta" +DATE=$(date) +LOGGFILE="setup-ovpl.log" -echo "" -echo "Setting up MongoDB repo.." +echo "[[$DATE:: $0 :: Line $LINENO::]] Setting up MongoDB repo...." 2>&1 | tee -a $LOGFILE cp $meta_dir/mongodb.repo /etc/yum.repos.d/mongodb.repo - -echo "" -echo "Installing MongoDB.." +echo "[[$DATE:: $0 :: Line $LINENO::]] Installing MongoDB......" 2>&1 | tee -a $LOGFILE yum -y install mongodb-org +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in installing mongodb.." 2>&1 | tee -a $LOGFILE + exit 1 +fi -echo "" -echo "Starting mongod service.." +echo "[[$DATE:: $0 :: Line $LINENO::]] Starting mongod service.." 2>&1 | tee -a $LOGFILE service mongod start - +if [ $? -eq 0 ];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Mongodb service started.." 2>&1 | tee -a $LOGFILE +elif [ $? -eq 1 ];then + sed 's/.*deamon.*/new/g' /etc/init.d/mongod + service mongod restart + +else + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in starting Mongodb service.." 2>&1 | tee -a $LOGFILE + exit 1 + +fi exit 0 diff --git a/scripts/install_openvz.sh b/scripts/install_openvz.sh index 9d0c52b..0e3ba48 100755 --- a/scripts/install_openvz.sh +++ b/scripts/install_openvz.sh @@ -1,59 +1,76 @@ #!/bin/bash -# Script to setup OpenVZ repo, install and configure OpenVZ +# Script to setup OpenVZ repo, install and configure meta_dir="../meta" vz_template_file="ubuntu-12.04-custom-x86_64.tar.gz" +cd $meta_dir +echo "[[$DATE:: $0 :: Line $LINENO::]] Downloading $vz_template_file file to $meta_dir directory" 2>&1 | tee -a $LOGFILE echo "" -echo "Setting up OpenVZ repo.." +wget http://community.virtual-labs.ac.in/downloads/ubuntu-12.04-custom-x86_64.tar.gz +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in Downloading $vz_template_file file to $meta_dir directory.." 2>&1 | tee -a $LOGFILE +fi + #wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo +echo "[$DATE:: $0 :: Line $LINENO::]] copying openvz.repo into /etc/yum/repos.d/" 2>&1 | tee -a $LOGFILE cp $meta_dir/openvz.repo /etc/yum.repos.d/openvz.repo + +echo "[$DATE:: $0 :: Line $LINENO::]] Importing RPM-GPG-Key for openvz.." 2>&1 | tee -a $LOGFILE rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ -echo "" -echo "Installing the OpenVZ kernel.." +echo "[[$DATE:: $0 :: Line $LINENO::]] Installing the OpenVZ kernel.." 2>&1 | tee -a $LOGFILE yum -y install vzkernel +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in Installing the OpenVZ kernel...." 2>&1 | tee -a $LOGFILE + exit 1 +fi -echo "" -echo "Configuring OpenVZ.." +echo "[[$DATE:: $0 :: Line $LINENO::]] Configuring OpenVZ.." 2>&1 | tee -a $LOGFILE cat $meta_dir/updated_sysctl.conf >> /etc/sysctl.conf echo "SELINUX=disabled" > /etc/sysconfig/selinux +echo "[[$DATE:: $0 :: Line $LINENO::]] Disabled SELINUX.." 2>&1 | tee -a $LOGFILE -echo "" -echo "Installing OpenVZ tools.." +echo "[[$DATE:: $0 :: Line $LINENO::]] Installing OpenVZ tools.." 2>&1 | tee -a $LOGFILE yum -y install vzctl vzquota ploop vzstats +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in Installing the OpenVZ tools...." 2>&1 | tee -a $LOGFILE + exit 1 +fi if [[ ! -f $meta_dir/$vz_template_file ]]; then echo "" - echo "VZ OS template file not found!" + echo "[[$DATE:: $0 :: Line $LINENO::]] VZ OS template file not found!" 2>&1 | tee -a $LOGFILE echo "Please obtain an VZ OS template image and manually" echo "copy that into /vz/template/cache folder." echo "Failing the above step will result in OVPL not working." echo "Please contact VLEAD for further clarifications." else - echo "" - echo "Copying the default OS template for containers.." + + echo "[[$DATE:: $0 :: Line $LINENO::]] Copying the default OS template for containers....." 2>&1 | tee -a $LOGFILE cp $meta_dir/$vz_template_file /vz/template/cache fi # Not needed!? Not sure. -#echo "Allowing multiple subnets to reside on the same network interface.." -#sed -i 's/#NEIGHBOUR_DEVS=all/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf -#sed -i 's/NEIGHBOUR_DEVS=detect/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf -# -#echo "Setting container layout to default to ploop (VM in a file).." -#sed -i 's/#VE_LAYOUT=ploop/VE_LAYOUT=ploop/g' /etc/vz/vz.conf -# -#echo "Setting Ubuntu 12.04 64bit to be the default template.." -#sed -i 's/centos-6-x86/ubuntu-12.04-x86_64/g' /etc/vz/vz.conf +echo "[[$DATE:: $0 :: Line $LINENO::]] Allowing multiple subnets to reside on the same network interface.." 2>&1 | tee -a $LOGFILE +sed -i 's/#NEIGHBOUR_DEVS=all/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf +sed -i 's/#NEIGHBOUR_DEVS=detect/NEIGHBOUR_DEVS=all/g' /etc/vz/vz.conf + +echo "[[$DATE:: $0 :: Line $LINENO::]] Setting container layout to default to ploop (VM in a file).." 2>&1 | tee -a $LOGFILE +sed -i 's/VE_LAYOUT=simfs/VE_LAYOUT=ploop/g' /etc/vz/vz.conf + +echo "[[$DATE:: $0 :: Line $LINENO::]] Setting Ubuntu 12.04 64bit to be the default template.." 2>&1 | tee -a $LOGFILE +sed -i 's/centos-6-x86/ubuntu-12.04-x86_64/g' /etc/vz/vz.conf # #sysctl -p # #echo "Disabling iptables.." #/etc/init.d/iptables stop && chkconfig iptables off - -echo "" -echo "Finished installing OpenVZ" +echo "[[$DATE:: $0 :: Line $LINENO::]] Setting iptables" 2>&1 | tee -a $LOGFILE +iptables -F FORWARD +echo "[[$DATE:: $0 :: Line $LINENO::]] Saving iptables" 2>&1 | tee -a $LOGFILE +service iptables save +echo "[[$DATE:: $0 :: Line $LINENO::]] Finished installing OpenVZ" 2>&1 | tee -a $LOGFILE exit 0 diff --git a/scripts/install_ovpl.sh b/scripts/install_ovpl.sh index f16336a..c0528fa 100755 --- a/scripts/install_ovpl.sh +++ b/scripts/install_ovpl.sh @@ -1,22 +1,35 @@ #!/bin/bash -echo "" -echo "Fetching OVPL from GitHub.." cd /root -git clone https://github.com/vlead/ovpl.git -cd ovpl -echo "changed to OVPL directory.." -echo "Checking out version v1.0.0 .." -git checkout tags/v1.0.0 -echo "" +if [ ! -d "ovpl" ];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Cloning https://github.com/vlead/ovpl.git into /root/" 2>&1 | tee -a $LOGFILE + git clone https://github.com/vlead/ovpl.git + if [ $? -eq 0 ] + then + echo "[[$DATE:: $0 :: Line $LINENO::]] Finished Cloning https://github.com/vlead/ovpl.git into /root/" 2>&1 | tee -a $LOGFILE + else + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in Cloning https://github.com/vlead/ovpl.git into /root/" 2>&1 | tee -a $LOGFILE + exit 1 + fi +else + echo "[[$DATE:: $0 :: Line $LINENO::]] Pulling ovpl from origin master" 2>&1 | tee -a $LOGFILE + cd ovpl/ + git pull origin master + echo "[[$DATE:: $0 :: Line $LINENO::]] finished pulling https://github.com/vlead/ovpl.git into /root/" 2>&1 | tee -a $LOGFILE + echo "[[$DATE:: $0 :: Line $LINENO::]] Checking out version v1.0.0 .." 2>&1 | tee -a $LOGFILE + git checkout tags/v1.0.0 -echo "Installing OVPL.." +fi +cd ovpl +echo "[[$DATE:: $0 :: Line $LINENO::]] Running 'python setup.py install' to install pre-requisites for run ovpl " 2>&1 | tee -a $LOGFILE python setup.py install +if [[ $? -ne 0 ]];then + echo "[[$DATE:: $0 :: Line $LINENO::]] Error in installing 'python setup.py install' " 2>&1 | tee -a $LOGFILE + exit 1 -echo "" -echo "Congrats! You have setup OVPL successfully!!! :-)" -echo "Now run 'make' from inside the src directory" -echo " of OVPL to start the services." +else + echo "[[$DATE:: $0 :: Line $LINENO::]] Finished installing ovpl" 2>&1 | tee -a $LOGFILE +fi exit 0 diff --git a/scripts/setup-ovpl.log b/scripts/setup-ovpl.log new file mode 100644 index 0000000..119efee --- /dev/null +++ b/scripts/setup-ovpl.log @@ -0,0 +1,17 @@ +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 53::]] Updating System.... +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 60::]] System updation complete.. +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 66::]] Invoking install_dependencies.sh +[[Tue Dec 16 11:25:53 IST 2014:: ./install_dependencies.sh :: Line 6::]] Setting up EPEL repo.. +[[Tue Dec 16 11:25:53 IST 2014:: ./install_dependencies.sh :: Line 9::]] Installing dependencies.. +[[Tue Dec 16 11:25:53 IST 2014:: ./install_dependencies.sh :: Line 10::]] Running yum -y install gcc python-devel.x86_64 python-pip openssh-clients openssh-server git +[[Tue Dec 16 11:25:53 IST 2014:: ./install_dependencies.sh :: Line 16::]] Completed installation of gcc python-devel.x86_64 python-pip openssh-clients openssh-server git +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 76::]] successfully installed dependencies... +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 85::]] Invoking install_openvz.sh +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 95::]] successfully installed openvz... +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 105::]] Invoking install_mongodb.sh +[[Tue Dec 16 11:27:22 IST 2014:: ./install_mongodb.sh :: Line 8::]] Setting up MongoDB repo.... +[[Tue Dec 16 11:27:22 IST 2014:: ./install_mongodb.sh :: Line 11::]] Installing MongoDB...... +[[Tue Dec 16 11:27:22 IST 2014:: ./install_mongodb.sh :: Line 18::]] Starting mongod service.. +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 116::]] successfully installed mongodb... +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 125::]] Invoking install_ovpl.sh +[[Tue Dec 16 11:25:53 IST 2014:: ./centos_prepare_ovpl.sh :: Line 137::]] Congrats! You have setup OVPL successfully!!! :-)