From: tierno Date: Mon, 19 Dec 2016 17:50:49 +0000 (+0100) Subject: merge v1.0.2 -commit 8940f6c- into master X-Git-Tag: v2.0.0~67 X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2Fopenvim.git;a=commitdiff_plain;h=a07bb94512b45d83da8ae3fdcc42c9f2084a0fa0;hp=87505141528f5528a1f354d2b913f36a6e445b47 merge v1.0.2 -commit 8940f6c- into master Change-Id: Iecc046a8c277b66c11037376b2ce3a821049be2a Signed-off-by: tierno --- diff --git a/host_thread.py b/host_thread.py index e877505..173634b 100644 --- a/host_thread.py +++ b/host_thread.py @@ -36,7 +36,8 @@ import time import Queue import paramiko from jsonschema import validate as js_v, exceptions as js_e -import libvirt +#import libvirt +import imp from vim_schema import localinfo_schema, hostinfo_schema import random #from logging import Logger @@ -44,6 +45,9 @@ import random #TODO: insert a logging system +global lvirt_module +lvirt_module=None #libvirt module is charged only if not in test mode + class host_thread(threading.Thread): def __init__(self, name, host, user, db, db_lock, test, image_path, host_id, version, develop_mode, develop_bridge_iface): '''Init a thread. @@ -60,6 +64,13 @@ class host_thread(threading.Thread): self.db = db self.db_lock = db_lock self.test = test + if not test: + try: + lvirt_module = imp.find_module("libvirt") + except (IOError, ImportError) as e: + raise ImportError("Cannot import python-libvirt. Openvim not properly installed" +str(e)) + + self.develop_mode = develop_mode self.develop_bridge_iface = develop_bridge_iface self.image_path = image_path @@ -120,7 +131,7 @@ class host_thread(threading.Thread): except paramiko.ssh_exception.SSHException as e: text = e.args[0] print self.name, ": load_localinfo ssh Exception:", text - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: text = e.get_error_message() print self.name, ": load_localinfo libvirt Exception:", text except yaml.YAMLError as exc: @@ -165,7 +176,7 @@ class host_thread(threading.Thread): except paramiko.ssh_exception.SSHException as e: text = e.args[0] print self.name, ": load_hostinfo ssh Exception:", text - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: text = e.get_error_message() print self.name, ": load_hostinfo libvirt Exception:", text except yaml.YAMLError as exc: @@ -206,7 +217,7 @@ class host_thread(threading.Thread): print self.name, ": save_localinfo ssh Exception:", text if "SSH session not active" in text: self.ssh_connect() - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: text = e.get_error_message() print self.name, ": save_localinfo libvirt Exception:", text except yaml.YAMLError as exc: @@ -933,7 +944,7 @@ class host_thread(threading.Thread): print self.name, ": create xml server error:", xml return -2, xml print self.name, ": create xml:", xml - atribute = libvirt.VIR_DOMAIN_START_PAUSED if paused == "yes" else 0 + atribute = lvirt_module.VIR_DOMAIN_START_PAUSED if paused == "yes" else 0 #4 Start the domain if not rebuild: #ensures that any pending destroying server is done self.server_forceoff(True) @@ -948,7 +959,7 @@ class host_thread(threading.Thread): print self.name, ": launch_server(%s) ssh Exception: %s" %(server_id, text) if "SSH session not active" in text: self.ssh_connect() - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: text = e.get_error_message() print self.name, ": launch_server(%s) libvirt Exception: %s" %(server_id, text) except Exception as e: @@ -971,26 +982,26 @@ class host_thread(threading.Thread): return try: - conn = libvirt.open("qemu+ssh://"+self.user+"@"+self.host+"/system") + conn = lvirt_module.open("qemu+ssh://"+self.user+"@"+self.host+"/system") domains= conn.listAllDomains() domain_dict={} for domain in domains: uuid = domain.UUIDString() ; libvirt_status = domain.state() #print libvirt_status - if libvirt_status[0] == libvirt.VIR_DOMAIN_RUNNING or libvirt_status[0] == libvirt.VIR_DOMAIN_SHUTDOWN: + if libvirt_status[0] == lvirt_module.VIR_DOMAIN_RUNNING or libvirt_status[0] == lvirt_module.VIR_DOMAIN_SHUTDOWN: new_status = "ACTIVE" - elif libvirt_status[0] == libvirt.VIR_DOMAIN_PAUSED: + elif libvirt_status[0] == lvirt_module.VIR_DOMAIN_PAUSED: new_status = "PAUSED" - elif libvirt_status[0] == libvirt.VIR_DOMAIN_SHUTOFF: + elif libvirt_status[0] == lvirt_module.VIR_DOMAIN_SHUTOFF: new_status = "INACTIVE" - elif libvirt_status[0] == libvirt.VIR_DOMAIN_CRASHED: + elif libvirt_status[0] == lvirt_module.VIR_DOMAIN_CRASHED: new_status = "ERROR" else: new_status = None domain_dict[uuid] = new_status conn.close - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: print self.name, ": get_state() Exception '", e.get_error_message() return @@ -1056,15 +1067,15 @@ class host_thread(threading.Thread): self.create_image(None, req) else: try: - conn = libvirt.open("qemu+ssh://"+self.user+"@"+self.host+"/system") + conn = lvirt_module.open("qemu+ssh://"+self.user+"@"+self.host+"/system") try: dom = conn.lookupByUUIDString(server_id) - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: text = e.get_error_message() if 'LookupByUUIDString' in text or 'Domain not found' in text or 'No existe un dominio coincidente' in text: dom = None else: - print self.name, ": action_on_server(",server_id,") libvirt exception:", text + print self.name, ": action_on_server(",server_id,") libvirt exception:", text raise e if 'forceOff' in req['action']: @@ -1185,7 +1196,7 @@ class host_thread(threading.Thread): conn.close() - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: if conn is not None: conn.close text = e.get_error_message() new_status = "ERROR" @@ -1242,7 +1253,7 @@ class host_thread(threading.Thread): return 0, None try: if not lib_conn: - conn = libvirt.open("qemu+ssh://"+self.user+"@"+self.host+"/system") + conn = lvirt_module.open("qemu+ssh://"+self.user+"@"+self.host+"/system") else: conn = lib_conn @@ -1253,7 +1264,7 @@ class host_thread(threading.Thread): iface.destroy() iface.create() print self.name, ": restore_iface '%s' %s" % (name, mac) - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: error_text = e.get_error_message() print self.name, ": restore_iface '%s' '%s' libvirt exception: %s" %(name, mac, error_text) ret=-1 @@ -1343,12 +1354,12 @@ class host_thread(threading.Thread): try: conn=None - conn = libvirt.open("qemu+ssh://"+self.user+"@"+self.host+"/system") + conn = lvirt_module.open("qemu+ssh://"+self.user+"@"+self.host+"/system") dom = conn.lookupByUUIDString(port["instance_id"]) if old_net: text="\n".join(xml) print self.name, ": edit_iface detaching SRIOV interface", text - dom.detachDeviceFlags(text, flags=libvirt.VIR_DOMAIN_AFFECT_LIVE) + dom.detachDeviceFlags(text, flags=lvirt_module.VIR_DOMAIN_AFFECT_LIVE) if new_net: xml[-1] =" " self.xml_level = 1 @@ -1356,9 +1367,9 @@ class host_thread(threading.Thread): xml.append('') text="\n".join(xml) print self.name, ": edit_iface attaching SRIOV interface", text - dom.attachDeviceFlags(text, flags=libvirt.VIR_DOMAIN_AFFECT_LIVE) + dom.attachDeviceFlags(text, flags=lvirt_module.VIR_DOMAIN_AFFECT_LIVE) - except libvirt.libvirtError as e: + except lvirt_module.libvirtError as e: text = e.get_error_message() print self.name, ": edit_iface(",port["instance_id"],") libvirt exception:", text diff --git a/httpserver.py b/httpserver.py index 9f26737..ecf878c 100644 --- a/httpserver.py +++ b/httpserver.py @@ -37,7 +37,8 @@ import threading import datetime import hashlib import os -import RADclass +import imp +#import only if needed because not needed in test mode. To allow an easier installation import RADclass from jsonschema import validate as js_v, exceptions as js_e import host_thread as ht from vim_schema import host_new_schema, host_edit_schema, tenant_new_schema, \ @@ -50,6 +51,8 @@ from vim_schema import host_new_schema, host_edit_schema, tenant_new_schema, \ global my global url_base global config_dic +global RADclass_module +RADclass=None #RADclass module is charged only if not in test mode url_base="/openvim" @@ -535,9 +538,14 @@ def http_post_hosts(): ip_name=host['ip_name'] user=host['user'] password=host.get('password', None) + if not RADclass_module: + try: + RADclass_module = imp.find_module("RADclass") + except (IOError, ImportError) as e: + raise ImportError("Cannot import RADclass.py Openvim not properly installed" +str(e)) #fill rad info - rad = RADclass.RADclass() + rad = RADclass_module.RADclass() (return_status, code) = rad.obtain_RAD(user, password, ip_name) #return diff --git a/scripts/configure-compute-node-UBUNTU16.0.4.sh b/scripts/configure-compute-node-UBUNTU16.0.4.sh new file mode 100755 index 0000000..9d82c19 --- /dev/null +++ b/scripts/configure-compute-node-UBUNTU16.0.4.sh @@ -0,0 +1,543 @@ +#!/bin/bash + +## +# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# This file is part of openvim +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# For those usages not covered by the Apache License, Version 2.0 please +# contact with: nfvlabs@tid.es +## + +# Authors: Antonio Lopez, Pablo Montes, Alfonso Tierno +# June 2015 + +# Personalize RHEL7.1 on compute nodes +# Prepared to work with the following network card drivers: +# tg3, igb drivers for management interfaces +# ixgbe (Intel Niantic) and i40e (Intel Fortville) drivers for data plane interfaces + +# To download: +# wget https://raw.githubusercontent.com/nfvlabs/openmano/master/scripts/configure-compute-node-UBUNTU14.04.sh +# To execute: +# chmod +x ./configure-compute-node-UBUNTU14.04.sh +# sudo ./configure-compute-node-RHEL7.1.sh + +# Assumptions: +# All virtualization options activated on BIOS (vt-d, vt-x, SR-IOV, no power savings...) +# RHEL7.1 installed without /home partition and with the following packages selection: +# @base, @core, @development, @network-file-system-client, @virtualization-hypervisor, @virtualization-platform, @virtualization-tools + + +function usage(){ + echo -e "Usage: sudo $0 [-y] [ [|dhcp] ]" + echo -e " Configure compute host for VIM usage. (version 0.4). Params:" + echo -e " -y do not prompt for confirmation. If a new user is created, the user name is set as password" + echo -e " Create if not exist and configure this user for openvim to connect" + echo -e " if suplied creates bridge interfaces on this interface, needed for openvim" + echo -e " ip or dhcp if suplied, configure the interface with this ip address (/24) or 'dhcp' " +} + + +#1 CHECK input parameters +#1.1 root privileges +[ "$USER" != "root" ] && echo "Needed root privileges" && usage && exit -1 + +#1.2 input parameters +FORCE="" +while getopts "y" o; do + case "${o}" in + y) + FORCE="yes" + ;; + *) + usage + exit -1 + ;; + esac +done +shift $((OPTIND-1)) + + + +if [ $# -lt 1 ] +then + usage + exit +fi + + +user_name=$1 +interface=$2 +ip_iface=$3 + +if [ -n "$interface" ] && ! ifconfig $interface &> /dev/null +then + echo "Error: interface '$interface' is not present in the system" + usage + exit 1 +fi + +echo ' +################################################################# +##### INSTALL NEEDED PACKETS ##### +#################################################################' + +# Required packages +apt-get -y update +#apt-get -y install grub-common screen virt-manager ethtool build-essential x11-common x11-utils x11-apps libguestfs-tools hwloc libguestfs-tools numactl vlan nfs-common nfs-kernel-server +apt-get -y install grub-common screen virt-manager ethtool build-essential x11-common x11-utils libguestfs-tools hwloc libguestfs-tools numactl vlan nfs-common nfs-kernel-server + +echo "Remove unneeded packages....." +apt-get -y autoremove +# Selinux management +#yum install -y policycoreutils-python + + + +echo ' +################################################################# +##### INSTALL USER ##### +#################################################################' + +# Add required groups +groupadd -f admin +groupadd -f libvirt #for other operating systems may be libvirtd + +# Adds user, default password same as name +if grep -q "^${user_name}:" /etc/passwd +then + #user exist, add to group + echo "adding user ${user_name} to groups libvirt,admin" + usermod -a -G libvirt,admin -g admin $user_name +else + #create user if it does not exist + [ -z "$FORCE" ] && read -p "user '${user_name}' does not exist, create (Y/n)" kk + if ! [ -z "$kk" -o "$kk"="y" -o "$kk"="Y" ] + then + exit + fi + echo "creating and configuring user {user_name}" + useradd -m -G libvirt,admin -g admin $user_name + #Password + if [ -z "$FORCE" ] + then + echo "Provide a password for $user_name" + passwd $user_name + else + echo -e "$user_name\n$user_name" | passwd --stdin $user_name + fi +fi + +## Allow admin users to access without password +#if ! grep -q "#openmano" /etc/sudoers +#then +# cat >> /home/${user_name}/script_visudo.sh << EOL +##!/bin/bash +#cat \$1 | awk '(\$0~"requiretty"){print "#"\$0}(\$0!~"requiretty"){print \$0}' > tmp +#cat tmp > \$1 +#rm tmp +#echo "" >> \$1 +#echo "#openmano allow to group admin to grant root privileges without password" >> \$1 +#echo "%admin ALL=(ALL) NOPASSWD: ALL" >> \$1 +#EOL +# chmod +x /home/${user_name}/script_visudo.sh +# echo "allowing admin user to get root privileges withut password" +# export EDITOR=/home/${user_name}/script_visudo.sh && sudo -E visudo +# rm -f /home/${user_name}/script_visudo.sh +#fi + + +echo ' +################################################################# +##### INSTALL HUGEPAGES ISOLCPUS GRUB ##### +#################################################################' + +# Huge pages 1G auto mount +mkdir -p /mnt/huge +if ! grep -q "Huge pages" /etc/fstab +then + echo "" >> /etc/fstab + echo "# Huge pages" >> /etc/fstab + echo "nodev /mnt/huge hugetlbfs pagesize=1GB 0 0" >> /etc/fstab + echo "" >> /etc/fstab +fi + +# Huge pages reservation service +if ! [ -f /lib/systemd/system/hugetlb-gigantic-pages.service ] +then + echo "configuring huge pages service" + echo "[Unit] +Description=HugeTLB Gigantic Pages Reservation +DefaultDependencies=no +Before=dev-hugepages.mount +ConditionPathExists=/sys/devices/system/node +ConditionKernelCommandLine=hugepagesz=1G + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/lib/systemd/hugetlb-reserve-pages + +[Install] +WantedBy=sysinit.target" >> /lib/systemd/system/hugetlb-gigantic-pages.service + + # cat > /usr/lib/systemd/system/hugetlb-gigantic-pages.service << EOL + #[Unit] + #Description=HugeTLB Gigantic Pages Reservation + #DefaultDependencies=no + #Before=dev-hugepages.mount + #ConditionPathExists=/sys/devices/system/node + #ConditionKernelCommandLine=hugepagesz=1G + # + #[Service] + #Type=oneshot + #RemainAfterExit=yes + #ExecStart=/usr/lib/systemd/hugetlb-reserve-pages + # + #[Install] + #WantedBy=sysinit.target + #EOL +fi + + +# Get isolcpus +isolcpus=`gawk 'BEGIN{pre=-2;} + ($1=="processor"){pro=$3;} + ($1=="core" && $4!=0){ + if (pre+1==pro){endrange="-" pro} + else{cpus=cpus endrange sep pro; sep=","; endrange="";}; + pre=pro;} + END{printf("%s",cpus endrange);}' /proc/cpuinfo` + + +echo "CPUS: $isolcpus" + +# Huge pages reservation file: reserving all memory apart from 4GB per NUMA node +# Get the number of hugepages: all memory but 8GB reserved for the OS +#totalmem=`dmidecode --type 17|grep Size |grep MB |gawk '{suma+=$2} END {print suma/1024}'` +#hugepages=$(($totalmem-8)) + +if ! [ -f /usr/lib/systemd/hugetlb-reserve-pages ] +then + cat > /usr/lib/systemd/hugetlb-reserve-pages << EOL +#!/bin/bash +nodes_path=/sys/devices/system/node/ +if [ ! -d \$nodes_path ]; then + echo "ERROR: \$nodes_path does not exist" + exit 1 +fi + +reserve_pages() +{ + echo \$1 > \$nodes_path/\$2/hugepages/hugepages-1048576kB/nr_hugepages +} + +# This example reserves all available memory apart from 4 GB for linux +# using 1GB size. You can modify it to your needs or comment the lines +# to avoid reserve memory in a numa node +EOL + for f in /sys/devices/system/node/node?/meminfo + do + node=`head -n1 $f | gawk '($5=="kB"){print $2}'` + memory=`head -n1 $f | gawk '($5=="kB"){print $4}'` + memory=$((memory+1048576-1)) #memory must be ceiled + memory=$((memory/1048576)) #from `kB to GB + #if memory + [ $memory -gt 4 ] && echo "reserve_pages $((memory-4)) node$node" >> /usr/lib/systemd/hugetlb-reserve-pages + done + + # Run the following commands to enable huge pages early boot reservation: + chmod +x /usr/lib/systemd/hugetlb-reserve-pages + systemctl enable hugetlb-gigantic-pages +fi + +# Prepares the text to add at the end of the grub line, including blacklisting ixgbevf driver in the host +memtotal=`grep MemTotal /proc/meminfo | awk '{ print $2 }' ` +hpages=$(( ($memtotal/(1024*1024))-8 )) + +memtotal=$((memtotal+1048576-1)) #memory must be ceiled +memtotal=$((memtotal/1048576)) #from `kB to GBa +hpages=$((memtotal-8)) +[[ $hpages -lt 0 ]] && hpages=0 + + +echo "------> memtotal: $memtotal" + +textokernel=" intel_iommu=on default_hugepagesz=1G hugepagesz=1G hugepages=$hpages isolcpus=$isolcpus modprobe.blacklist=ixgbevf modprobe.blacklist=i40evf" + +echo "Text to kernel: $textokernel" + + +# Add text to the kernel line +if ! grep -q " intel_iommu=on default_hugepagesz=1G hugepagesz=1G" /etc/default/grub +then + echo ">>>>>>> adding cmdline ${textokernel}" + sed -i "/^GRUB_CMDLINE_LINUX_DEFAULT=/s/\"\$/${textokernel}\"/" /etc/default/grub + sed -i "/^GRUB_CMDLINE_LINUX=/s/\"\$/${textokernel}\"/" /etc/default/grub + + update-grub + # BIOS based systems + grub-mkconfig -o /boot/efi/EFI/ubuntu/grub.cfg + # UEFI based systems + grub-mkconfig -o /boot/grub/grub.cfg +fi + +echo ' +################################################################# +##### OTHER CONFIGURATION ##### +#################################################################' + +# Links the OpenMANO required folder /opt/VNF/images to /var/lib/libvirt/images. The OS installation +# should have only a / partition with all possible space available + +echo " link /opt/VNF/images to /var/lib/libvirt/images" +if [ "$user_name" != "" ] +then + #mkdir -p /home/${user_name}/VNF_images + #chown -R ${user_name}:admin /home/${user_name}/VNF_images + #chmod go+x $HOME + + # The orchestator needs to link the images folder + rm -f /opt/VNF/images + mkdir -p /opt/VNF/ + ln -s /var/lib/libvirt/images /opt/VNF/images + chown -R ${user_name}:admin /opt/VNF + chown -R root:admin /var/lib/libvirt/images + chmod g+rwx /var/lib/libvirt/images + + # Selinux management + #echo "configure Selinux management" + #semanage fcontext -a -t virt_image_t "/home/${user_name}/VNF_images(/.*)?" + #cat /etc/selinux/targeted/contexts/files/file_contexts.local |grep virt_image + #restorecon -R -v /home/${user_name}/VNF_images +else + mkdir -p /opt/VNF/images + chmod o+rx /opt/VNF/images +fi + +echo "creating local information /opt/VNF/images/hostinfo.yaml" +echo "#By default openvim assumes control plane interface naming as em1,em2,em3,em4 " > /opt/VNF/images/hostinfo.yaml +echo "#and bridge ifaces as virbrMan1, virbrMan2, ..." >> /opt/VNF/images/hostinfo.yaml +echo "#if compute node contain a different name it must be indicated in this file" >> /opt/VNF/images/hostinfo.yaml +echo "#with the format extandard-name: compute-name" >> /opt/VNF/images/hostinfo.yaml +if [ "$interface" != "" -a "$interface" != "em1" ] +then + echo "iface_names:" >> /opt/VNF/images/hostinfo.yaml + echo " em1: ${interface}" >> /opt/VNF/images/hostinfo.yaml +fi +chmod o+r /opt/VNF/images/hostinfo.yaml + +# deactivate memory overcommit +#echo "deactivate memory overcommit" +#service ksmtuned stop +#service ksm stop +#chkconfig ksmtuned off +#chkconfig ksm off + + +# Libvirt options (uncomment the following) +echo "configure Libvirt options" +sed -i 's/#unix_sock_group = "libvirt"/unix_sock_group = "libvirt"/' /etc/libvirt/libvirtd.conf +sed -i 's/#unix_sock_rw_perms = "0770"/unix_sock_rw_perms = "0770"/' /etc/libvirt/libvirtd.conf +sed -i 's/#unix_sock_dir = "\/var\/run\/libvirt"/unix_sock_dir = "\/var\/run\/libvirt"/' /etc/libvirt/libvirtd.conf +sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf + + +echo ' +################################################################# +##### NETWORK CONFIGURATION ##### +#################################################################' +# Network config (if the second parameter is net) +echo "Interface ==> $interface" +if [ -n "$interface" ] +then + + + # For management and data interfaces + rm -f /etc/udev/rules.d/pci_config.rules # it will be created to define VFs + + + # Set ONBOOT=on and MTU=9000 on the interface used for the bridges + echo "configuring iface $interface" + +#MTU for interfaces and bridges +MTU=9000 + +cp /etc/network/interfaces interfaces.tmp + + + #Create infrastructure bridge, normally used for connecting to compute nodes, openflow controller, ... + + + #Create VLAN for infrastructure bridge + + echo " +######### CUTLINE ######### + +auto ${interface} +iface ${interface} inet manual + post-up ip link set dev ${interface} mtu ${MTU} + +auto ${interface}.1001 +iface ${interface}.1001 inet manual + vlan-raw-device ${interface} + post-up ip link set mtu $MTU dev ${interface}.1001 +" >> interfaces.tmp + +# echo "ifconfig ${interface} mtu $MTU +# ifconfig ${interface} up +#" > mtu.tmp + + + #Create bridge interfaces + echo "Creating bridge ifaces: " + for ((i=1;i<=20;i++)) + do + i2digits=$i + [ $i -lt 10 ] && i2digits="0$i" + echo " virbrMan$i vlan 20$i2digits" + + j=$i + + echo " +auto ${interface}.20$i2digits +iface ${interface}.20$i2digits inet manual + post-up ip link set mtu $MTU dev ${interface}.20$i2digits + +auto virbrMan$j +iface virbrMan$j inet manual + bridge_ports ${interface}.20$i2digits + post-up ip link set dev virbrMan$j && ip link set mtu 9000 dev virbrMan$j +" >> interfaces.tmp + +# echo "ifconfig ${interface}.20$i2digits mtu $MTU +#ifconfig virbrMan$j mtu $MTU +#ifconfig virbrMan$j up +#" >> mtu.tmp + + done + + echo " +auto em2.1001 +iface em2.1001 inet manual + post-up ip link set dev em2.1001 mtu 9000 + +auto virbrInf +iface virbrInf inet manual + bridge_ports em2.1001 + post-up ip link set dev virbrInf && ip link set mtu 9000 dev virbrInf +" >> interfaces.tmp + +# echo "ifconfig em2.1001 mtu $MTU +#ifconfig virbrInf mtu $MTU +#ifconfig virbrInf up +#" >> mtu.tmp + +if ! grep -q "#### CUTLINE ####" /etc/network/interfaces +then + echo "====== Copying interfaces.tmp to /etc/network/interfaces" + cp interfaces.tmp /etc/network/interfaces +fi + + + #popd +fi + + +# Activate 8 Virtual Functions per PF on Niantic cards (ixgbe driver) +if [[ `lsmod | cut -d" " -f1 | grep "ixgbe" | grep -v vf` ]] +then + if ! grep -q "ixgbe" /etc/modprobe.d/ixgbe.conf + then + echo "options ixgbe max_vfs=8" >> /etc/modprobe.d/ixgbe.conf + fi + +fi + +echo "#!/bin/bash" > /etc/activate-vfs.sh +chmod +x /etc/activate-vfs.sh +for iface in `ip -o link show | awk -F': ' '{print $2}' | grep -v -e "\." -e "lo" -e "virbr" -e "tap"` +do +# 10/40 Gbps interfaces +# Intel X520 cards: driver ixgbe +# Intel XL710 Fortville cards: driver i40e +driver=`ethtool -i $iface| awk '($0~"driver"){print $2}'` +if [ "$driver" = "i40e" -o "$driver" = "ixgbe" ] +then + echo "configuring dataplane iface $iface" + + # Create 8 SR-IOV per PF by udev rules only for Fortville cards (i40e driver) + if [ "$driver" = "i40e" ] + then + pci=`ethtool -i $iface | awk '($0~"bus-info"){print $2}'` + echo "echo 8 > /sys/bus/pci/devices/$pci/sriov_numvfs" >> /etc/activate-vfs.sh + fi +fi +done + +# Set dataplane MTU + +#echo "sleep 10" >> mtu.tmp + +#interfaces=`ifconfig -a | grep ^p | cut -d " " -f 1` +#for ph in $interfaces +#do +# echo "ifconfig $ph mtu $MTU" >> mtu.tmp +# echo "ifconfig $ph up" >> mtu.tmp +#done + + + +#cp mtu.tmp /etc/setmtu.sh +#chmod +x /etc/setmtu.sh + +# To define 8 VFs per PF we do it on rc.local, because the driver needs to be unloaded and loaded again +#if ! grep -q "NFV" /etc/rc.local +#then + echo "#!/bin/sh -e +" > /etc/rc.local + echo "# NFV" >> /etc/rc.local + echo "modprobe -r ixgbe" >> /etc/rc.local + echo "modprobe ixgbe max_vfs=8" >> /etc/rc.local + echo "/etc/activate-vfs.sh" >> /etc/rc.local + #echo "/etc/setmtu.sh" >> /etc/rc.local + echo " +exit 0" >> /etc/rc.local + echo "" >> /etc/rc.local + + chmod +x /etc/rc.local + chmod +x /etc/activate-vfs.sh + +#fi + +chmod a+rwx /var/lib/libvirt/images +mkdir /usr/libexec/ +pushd /usr/libexec/ +ln -s /usr/bin/qemu-system-x86_64 qemu-kvm +popd + +#Deactivating apparmor while looking for a better solution +/etc/init.d/apparmor stop +update-rc.d -f apparmor remove + +echo +echo "Do not forget to create a shared (NFS, Samba, ...) where original virtual machine images are allocated" +echo +echo "Do not forget to copy the public ssh key into /home/${user_name}/.ssh/authorized_keys for authomatic login from openvim controller" +echo + +echo "Reboot the system to make the changes effective" + diff --git a/scripts/get-options.sh b/scripts/get-options.sh old mode 100644 new mode 100755 diff --git a/scripts/host-add.sh b/scripts/host-add.sh index c52f3fa..8aa9bde 100755 --- a/scripts/host-add.sh +++ b/scripts/host-add.sh @@ -1,7 +1,7 @@ #!/bin/bash ## -# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# Copyright 2015 Telef�nica Investigaci�n y Desarrollo, S.A.U. # This file is part of openvim # All Rights Reserved. # @@ -134,7 +134,7 @@ function xmlpath_args() [[ "$#" -lt "2" ]] && echo "Missing parameters" && usage load_vf_driver ixgbe load_vf_driver i40e - +/etc/rc.local HOST_NAME=`cat /etc/hostname` FEATURES=`grep "^flags" /proc/cpuinfo` FEATURES_LIST="" @@ -265,7 +265,7 @@ then eval $underscored_pci["switch_port"]=$switch_port fi - #Añado el pci de cada uno de los hijos + #A�ado el pci de cada uno de los hijos SRIOV_counter=0 for child in `xmlpath_args "device/capability/capability/address" < parent_xml` do diff --git a/scripts/install-openvim-service.sh b/scripts/install-openvim-service.sh index 05384ea..4cf393d 100755 --- a/scripts/install-openvim-service.sh +++ b/scripts/install-openvim-service.sh @@ -26,18 +26,19 @@ function usage(){ echo -e "usage: sudo $0 [OPTIONS]" - echo -e "Configures openvim to run as a service" + echo -e "Configures openvim to run as a service at /opt" echo -e " OPTIONS" echo -e " -u USER_OWNER user owner of the service, 'root' by default" echo -e " -f PATH path where openvim source is located. If missing it is downloaded from git" - #echo -e " -q: install in an unattended mode" + echo -e " -d --delete: if -f is provided, delete this path after copying to /opt" echo -e " -h: show this help" echo -e " --uninstall: remove created service and files" } function uninstall(){ - service openvim stop - for file in /opt/openvim /etc/default/openvimd.cfg /var/log/openvim /etc/systemd/system/openvim.service /usr/sbin/openvim /usr/sbin/initopenvim /usr/sbin/openvim + echo "systemctl disable openvim.service " && systemctl disable openvim.service 2>/dev/null || echo " Already done" + echo "service openvim stop " && service openvim stop 2>/dev/null || echo " Already done" + for file in /opt/openvim /etc/default/openvimd.cfg /var/log/openvim /etc/systemd/system/openvim.service /usr/bin/openvim /usr/bin/initopenvim /usr/sbin/service-openvim /usr/bin/openvim-report /usr/bin/openflow do rm -rf $file || ! echo "Can not delete '$file'. Needed root privileges?" >&2 || exit 1 done @@ -45,12 +46,12 @@ function uninstall(){ } BAD_PATH_ERROR="Path '$FILE' does not contain a valid openvim distribution" -GIT_URL=https://osm.etsi.org/gerrit/osm/RO.git +GIT_URL=https://osm.etsi.org/gerrit/osm/openvim.git USER_OWNER="root" QUIET_MODE="" FILE="" DELETE="" -while getopts ":u:f:hq-:" o; do +while getopts ":u:f:hdq-:" o; do case "${o}" in u) export USER_OWNER="$OPTARG" @@ -64,10 +65,14 @@ while getopts ":u:f:hq-:" o; do h) usage && exit 0 ;; + d) + DELETE=y + ;; -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "uninstall" ] && uninstall && exit 0 - echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 + [ "${OPTARG}" == "delete" ] && DELETE=y && continue + echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; \?) @@ -84,6 +89,7 @@ while getopts ":u:f:hq-:" o; do ;; esac done +BAD_PATH_ERROR="Path '$FILE' does not contain a valid openvim distribution" #check root privileges [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit 1 @@ -111,28 +117,29 @@ fi if [[ -z $FILE ]] then - git clone $GIT_URL __temp__ || ! echo "Cannot get openvim source code from $GIT_URL" >&2 || exit 1 - #git checkout - FILE=./__temp__ + FILE=__temp__${RANDOM} + git clone $GIT_URL $FILE || ! echo "Cannot get openvim source code from $GIT_URL" >&2 || exit 1 DELETE=y + #git checkout +else + [[ -d "$FILE" ]] || ! echo $BAD_PATH_ERROR >&2 || exit 1 fi #make idenpotent -rm -rf /opt/openvim -rm -f /etc/default/openvimd.cfg -rm -f /var/log/openvim -cp -r $FILE /opt/openvim || ! echo $BAD_PATH_ERROR >&2 || exit 1 +uninstall +#copy files +cp -r "$FILE" /opt/openvim || ! echo $BAD_PATH_ERROR >&2 || exit 1 mkdir -p /opt/openvim/logs -rm -rf /usr/sbin/openvim -rm -rf /usr/sbin/initopenvim -#cp ${FILE}/openvim /usr/sbin/ || ! echo $BAD_PATH_ERROR >&2 || exit 1 -ln -s /opt/openvim/openvimd.cfg /etc/default/openvimd.cfg || echo "warning cannot create link '/etc/default/openvimd.cfg'" -ln -s /opt/openvim/logs /var/log/openvim || echo "warning cannot create link '/var/log/openvim'" -ln -s /opt/openvim/openvim /usr/sbin/openvim -ln -s /opt/openvim/scripts/service-openvim.sh /usr/sbin/initopenvim +#makes links +ln -s -v /opt/openvim/openvimd.cfg /etc/default/openvimd.cfg || echo "warning cannot create link '/etc/default/openvimd.cfg'" +ln -s -v /opt/openvim/logs /var/log/openvim || echo "warning cannot create link '/var/log/openvim'" +ln -s -v /opt/openvim/openvim /usr/bin/openvim +ln -s -v /opt/openvim/scripts/service-openvim.sh /usr/sbin/service-openvim +ln -s -v /opt/openvim/scripts/openvim-report.sh /usr/bin/openvim-report +ln -s -v /opt/openvim/scripts/initopenvim.sh /usr/bin/initopenvim +ln -s -v /opt/openvim/openflow /usr/bin/openflow -chown $USER_OWNER /opt/openvim/openvimd.cfg -chown -R $USER_OWNER /opt/openvim +chown -R $SUDO_USER /opt/openvim mkdir -p /etc/systemd/system/ cat > /etc/systemd/system/openvim.service << EOF @@ -151,6 +158,7 @@ EOF [[ -n $DELETE ]] && rm -rf $FILE service openvim start +systemctl enable openvim.service echo Done exit diff --git a/scripts/install-openvim.sh b/scripts/install-openvim.sh index 88a92dd..747c8e6 100755 --- a/scripts/install-openvim.sh +++ b/scripts/install-openvim.sh @@ -25,6 +25,8 @@ #Get needed packages, source code and configure to run openvim #Ask for database user and password if not provided + + function usage(){ echo -e "usage: sudo $0 [OPTIONS]" echo -e "Install last stable source code in ./openvim and the needed packages" @@ -35,7 +37,10 @@ function usage(){ echo -e " -q --quiet: install in an unattended mode" echo -e " -h --help: show this help" echo -e " --develop: install last version for developers, and do not configure as a service" - echo -e " --skip-install-packages: use this option to skip and update and install the requires packages. This avoid wasting time if you are sure requires packages are present for e.g. a previous installation" + echo -e " --forcedb: reinstall vim_db DB, deleting previous database if exists and creating a new one" + echo -e " --force: makes idenpotent, delete previous installations folders if needed" + echo -e " --noclone: assumes that openvim was cloned previously and that this script is run from the local repo" + echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This avoid wasting time if you are sure requires packages are present e.g. because of a previous installation" } function install_packages(){ @@ -56,6 +61,16 @@ function install_packages(){ done } +function db_exists() { + RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -o $1` + if [ "$RESULT" == "$1" ]; then + echo " DB $1 exists" + return 0 + fi + echo " DB $1 does not exist" + return 1 +} + GIT_URL=https://osm.etsi.org/gerrit/osm/openvim.git DBUSER="root" @@ -63,6 +78,9 @@ DBPASSWD="" DBPASSWD_PARAM="" QUIET_MODE="" DEVELOP="" +FORCEDB="" +FORCE="" +NOCLONE="" NO_PACKAGES="" while getopts ":u:p:hiq-:" o; do case "${o}" in @@ -83,8 +101,11 @@ while getopts ":u:p:hiq-:" o; do -) [ "${OPTARG}" == "help" ] && usage && exit 0 [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue + [ "${OPTARG}" == "forcedb" ] && FORCEDB="y" && continue + [ "${OPTARG}" == "force" ] && FORCEDB="y" && FORCE="y" && continue + [ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue - [ "${OPTARG}" == "skip-install-packages" ] && export NO_PACKAGES=yes && continue + [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 exit 1 ;; @@ -150,6 +171,23 @@ else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0 fi +#check if installed as a service +INSTALL_AS_A_SERVICE="" +[[ "$_DISTRO" == "Ubuntu" ]] && [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] && INSTALL_AS_A_SERVICE="y" + +#Next operations require knowing BASEFOLDER +if [[ -z "$NOCLONE" ]]; then + if [[ -n "$INSTALL_AS_A_SERVICE" ]] ; then + OPENVIM_BASEFOLDER=__openvim__${RANDOM} + else + OPENVIM_BASEFOLDER="${PWD}/openvim" + fi + [[ -n "$FORCE" ]] && rm -rf $OPENVIM_BASEFOLDER #make idempotent +else + HERE=$(realpath $(dirname $0)) + OPENVIM_BASEFOLDER=$(dirname $HERE) +fi + if [[ -z "$NO_PACKAGES" ]] then @@ -232,30 +270,75 @@ echo ' fi #[[ -z "$NO_PACKAGES" ]] -echo ' +if [[ -z $NOCLONE ]]; then + echo ' ################################################################# ##### DOWNLOAD SOURCE ##### #################################################################' -su $SUDO_USER -c 'git clone '"${GIT_URL}"' openvim' -[[ -z $DEVELOP ]] && su $SUDO_USER -c 'git -C openvim checkout tags/v1.0.1' + if [[ -d "${OPENVIM_BASEFOLDER}" ]] + then + if [[ -n "$FORCE" ]] + then + echo "deleting '${OPENVIM_BASEFOLDER}' folder" + rm -rf "$OPENVIM_BASEFOLDER" #make idempotent + elif [[ -z "$QUIET_MODE" ]] + then + read -e -p "${OPENVIM_BASEFOLDER} folder exist, overwrite? (y/N)" KK + if [[ "$KK" == "y" ]] || [[ "$KK" == "yes" ]] + then rm -rf "$OPENVIM_BASEFOLDER" + else + echo "canceled" + exit 1 + fi + else + echo "'${OPENVIM_BASEFOLDER}' folder exist" >&2 && exit 1 + fi + fi -#Unncoment to use a concrete branch, if not main branch -#pushd openvim -#su $SUDO_USER -c 'git checkout v0.4' -#popd + + su $SUDO_USER -c "git clone ${GIT_URL} ${OPENVIM_BASEFOLDER}" + su $SUDO_USER -c "cp ${OPENVIM_BASEFOLDER}/.gitignore-common ${OPENVIM_BASEFOLDER}/.gitignore" + [[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${OPENVIM_BASEFOLDER} checkout tags/v1.0.2" +fi echo ' ################################################################# ##### CREATE DATABASE ##### #################################################################' -mysqladmin -u$DBUSER $DBPASSWD_PARAM -s create vim_db || ! echo "Cannot create database vim_db" || exit 1 - -echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql -u$DBUSER $DBPASSWD_PARAM || ! echo "Failed while creating user vim at dabase" || exit 1 -echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql -u$DBUSER $DBPASSWD_PARAM || ! echo "Failed while creating user vim at dabase" || exit 1 -echo " Database 'vim_db' created, user 'vim' password 'vimpw'" - +echo -e "\nCreating temporary file form MYSQL installation and initialization" +TEMPFILE="$(mktemp -q --tmpdir "installopenvim.XXXXXX")" +trap 'rm -f "$TEMPFILE"' EXIT +chmod 0600 "$TEMPFILE" +echo -e "[client]\n user='$DBUSER'\n password='$DBPASSWD'">"$TEMPFILE" + +if db_exists "vim_db" $TEMPFILE ; then + if [[ -n $FORCEDB ]]; then + echo " Deleting previous database vim_db" + DBDELETEPARAM="" + [[ -n $QUIET_MODE ]] && DBDELETEPARAM="-f" + mysqladmin --defaults-extra-file=$TEMPFILE -s drop vim_db $DBDELETEPARAM || ! echo "Could not delete vim_db database" || exit 1 + #echo "REVOKE ALL PRIVILEGES ON vim_db.* FROM 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + #echo "DELETE USER 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + mysqladmin --defaults-extra-file=$TEMPFILE -s create vim_db || ! echo "Error creating vim_db database" || exit 1 + echo "DROP USER 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + echo " Database 'vim_db' created, user 'vim' password 'vimpw'" + else + echo "Database exists. Use option '--forcedb' to force the deletion of the existing one" && exit 1 + fi +else + mysqladmin -u$DBUSER $DBPASSWD_PARAM -s create vim_db || ! echo "Error creating vim_db database" || exit 1 + echo "CREATE USER 'vim'@'localhost' identified by 'vimpw';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + echo "GRANT ALL PRIVILEGES ON vim_db.* TO 'vim'@'localhost';" | mysql --defaults-extra-file=$TEMPFILE -s || ! echo "Failed while creating user vim at database" || exit 1 + echo " Database 'vim_db' created, user 'vim' password 'vimpw'" +fi -su $SUDO_USER -c './openvim/database_utils/init_vim_db.sh -u vim -p vimpw' || ! echo "Failed while creating user vim at dabase" || exit 1 +echo ' +################################################################# +##### INIT DATABASE ##### +#################################################################' +su $SUDO_USER -c "${OPENVIM_BASEFOLDER}/database_utils/init_vim_db.sh -u vim -p vimpw -d vim_db" || ! echo "Failed while initializing database" || exit 1 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] @@ -292,40 +375,42 @@ echo ' ################################################################# ##### CONFIGURE openvim CLIENT ##### #################################################################' -#creates a link at ~/bin -su $SUDO_USER -c 'mkdir -p ~/bin' -su $SUDO_USER -c 'rm -f ${HOME}/bin/openvim' -su $SUDO_USER -c 'rm -f ${HOME}/bin/openflow' -su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openvim' -su $SUDO_USER -c 'rm -f ${HOME}/bin/initopenvim' -su $SUDO_USER -c 'rm -f ${HOME}/bin/service-floodlight' -su $SUDO_USER -c 'rm -f ${HOME}/bin/service-opendaylight' -su $SUDO_USER -c 'rm -f ${HOME}/bin/get_dhcp_lease.sh' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/openvim ${HOME}/bin/openvim' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/openflow ${HOME}/bin/openflow' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/scripts/service-openvim.sh ${HOME}/bin/service-openvim' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/scripts/initopenvim.sh ${HOME}/bin/initopenvim' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/scripts/service-floodlight.sh ${HOME}/bin/service-floodlight' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/scripts/service-opendaylight.sh ${HOME}/bin/service-opendaylight' -su $SUDO_USER -c 'ln -s ${PWD}/openvim/scripts/get_dhcp_lease.sh ${HOME}/bin/get_dhcp_lease.sh' - -#insert /home//bin in the PATH -#skiped because normally this is done authomatically when ~/bin exist -#if ! su $SUDO_USER -c 'echo $PATH' | grep -q "/home/${SUDO_USER}/bin" -#then -# echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc" -# su $SUDO_USER -c 'echo "PATH=\$PATH:/home/\${USER}/bin" >> ~/.bashrc' -#fi - -if [[ $SUDO_USER == root ]] +#creates a link at ~/bin if not configured as a service +if [[ -z "$INSTALL_AS_A_SERVICE" ]] then - if ! echo $PATH | grep -q "${HOME}/bin" + su $SUDO_USER -c 'mkdir -p ~/bin' + su $SUDO_USER -c 'rm -f ${HOME}/bin/openvim' + su $SUDO_USER -c 'rm -f ${HOME}/bin/openflow' + su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openvim' + su $SUDO_USER -c 'rm -f ${HOME}/bin/initopenvim' + su $SUDO_USER -c 'rm -f ${HOME}/bin/service-floodlight' + su $SUDO_USER -c 'rm -f ${HOME}/bin/service-opendaylight' + su $SUDO_USER -c 'rm -f ${HOME}/bin/get_dhcp_lease.sh' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/openvim' "'${HOME}/bin/openvim' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/openflow' "'${HOME}/bin/openflow' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-openvim.sh' "'${HOME}/bin/service-openvim' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/initopenvim.sh' "'${HOME}/bin/initopenvim' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-floodlight.sh' "'${HOME}/bin/service-floodlight' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-opendaylight.sh' "'${HOME}/bin/service-opendaylight' + su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/get_dhcp_lease.sh' "'${HOME}/bin/get_dhcp_lease.sh' + + #insert /home//bin in the PATH + #skiped because normally this is done authomatically when ~/bin exist + #if ! su $SUDO_USER -c 'echo $PATH' | grep -q "/home/${SUDO_USER}/bin" + #then + # echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc" + # su $SUDO_USER -c 'echo "PATH=\$PATH:/home/\${USER}/bin" >> ~/.bashrc' + #fi + + if [[ $SUDO_USER == root ]] then - echo "PATH=\$PATH:\${HOME}/bin" >> ${HOME}/.bashrc + if ! echo $PATH | grep -q "${HOME}/bin" + then + echo "PATH=\$PATH:\${HOME}/bin" >> ${HOME}/.bashrc + fi fi fi - #configure arg-autocomplete for this user #in case of minmal instalation this package is not installed by default [[ "$_DISTRO" == "CentOS" || "$_DISTRO" == "Red" ]] && yum install -y bash-completion @@ -339,19 +424,21 @@ fi -if [[ "$_DISTRO" == "Ubuntu" ]] && [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] +if [[ -n "$INSTALL_AS_A_SERVICE" ]] then echo ' ################################################################# ##### CONFIGURE OPENVIM SERVICE ##### #################################################################' - ./openvim/scripts/install-openvim-service.sh -f openvim #-u $SUDO_USER + DELETE_PARAM="" && [[ -z "$NOCLONE" ]] && DELETE_PARAM="-d" + ${OPENVIM_BASEFOLDER}/scripts/install-openvim-service.sh -f ${OPENVIM_BASEFOLDER} ${DELETE_PARAM} # alias service-openvim="service openvim" # echo 'alias service-openvim="service openvim"' >> ${HOME}/.bashrc echo - echo "Done! you may need to logout and login again for loading client configuration" + echo + echo "Done! installed at /opt/openvim" echo " Manage server with 'service openvim start|stop|status|...' " @@ -359,6 +446,6 @@ else echo echo "Done! you may need to logout and login again for loading client configuration" - echo " Run './openvim/scripts/service-openvim.sh start' for starting openvim in a screen" + echo " Run 'service-openvim start' for starting openvim in a screen" fi