[jira-272] This script is to check whether the ports required to run SEBA services are already being used by other application before installation of SEBA. If no ports that we require are already used then this script will reserve all the required ports on the OS, so that these ports will not be assigned by the OS to any other services later. If ports we need are already used, then execution of make will be terminated with error code 255.
Change-Id: I2928d2e6dc6611603669c695d6846f509bcf2600
Included the license on header of the script
Change-Id: I2928d2e6dc6611603669c695d6846f509bcf2600
diff --git a/scripts/portcheck.sh b/scripts/portcheck.sh
new file mode 100755
index 0000000..591a2a8
--- /dev/null
+++ b/scripts/portcheck.sh
@@ -0,0 +1,65 @@
+#!/bin/bash
+
+# Copyright 2017-present Open Networking Foundation
+#
+# 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.
+
+#Below are the list of ports which are required to be free, for the SEBA services to use. If any new services get added into SEBA, Update the required node ports below and also add it to the arrray portlist.
+
+#Service name : node Port number
+#onos-debugger: 30555
+#onos-openflow: 31653
+#onos-ssh: 30115
+#onos-ui: 30120
+#xos-chameleon: 30006
+#xos-core: 30010, 30011
+#xos-core-prometheus: 30009
+#xos-gui: 30001
+#xos-tosca: 30007
+#xos-ws: 30008
+#ingress-nginx: 30080, 30443
+#vcli: 30110
+#voltha: 30125, 30613, 32443, 31390
+#kpi-exporter: 31080
+#logging-elasticsearch-client: 31636
+#logging-kibana: 30601
+#nem-monitoring-grafana: 31300
+#nem-monitoring-prometheus-server: 31301
+
+declare -a portlist=("30555" "31653" "30115" "30120" "30006" "30010" "30011" "30009" "30001" "30007" "30008" "30080" "30443" "30110" "30125" "30613" "32443" "31390" "31080" "31636" "30601" "31300" "31301")
+
+number_of_ports_in_use=0
+
+#Below loop is to check whether any port in the list is already being used
+for port in "${portlist[@]}"
+do
+ if netstat -lntp | grep :":$port" > /dev/null ; then
+ used_process=$(netstat -lntp | grep :":$port" | tr -s ' ' | cut -f7 -d' ')
+ echo "ERROR: Process with PID/Program_name $used_process is already listening on port: $port needed by SEBA"
+ number_of_ports_in_use=$((number_of_ports_in_use+1))
+ fi
+done
+
+#If any of the ports are already used then the user will be notified to kill the running services before installing SEBA
+if [ $number_of_ports_in_use -gt 0 ]
+ then
+ echo "Kill the running services mentioned above before proceeding to install SEBA"
+ echo "Terminating make"
+ exit -1
+fi
+
+#The ports that are required by SEBA components will be added to the reserved port list
+var=$(printf '%s,' "${portlist[@]}")
+echo "$var" > /proc/sys/net/ipv4/ip_local_reserved_ports
+echo "SUCCESS: Added ports required for SEBA services to ip_local_reserved_ports"
+
diff --git a/seba-in-a-box/Makefile b/seba-in-a-box/Makefile
index 85a2555..5395edb 100644
--- a/seba-in-a-box/Makefile
+++ b/seba-in-a-box/Makefile
@@ -51,6 +51,7 @@
siab-1.0: $(M)/seba-1.0.0 $(M)/siab
$(M)/setup:
+ sudo $(WORKSPACE)/cord/automation-tools/scripts/portcheck.sh
mkdir -p $(M)
sudo apt update
sudo apt install -y httpie jq software-properties-common