echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging"
echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)"
echo -e " -m <MODULE>: install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)"
- echo -e " -o <ADDON>: do not install OSM, but ONLY one of the addons (vimemu, elk_stack, pm_stack) (assumes OSM is already installed)"
+ echo -e " -o <ADDON>: ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)"
echo -e " -D <devops path> use local devops installation path"
echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)"
+ echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)"
echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules"
echo -e " --source: install OSM from source code using the latest stable tag"
echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch"
#Uninstall lightweight OSM: remove dockers
function uninstall_lightweight() {
- echo -e "\nUninstalling lightweight OSM"
- remove_stack osm
- echo "Now osm docker images and volumes will be deleted"
- newgrp docker << EONG
- docker image rm osm/ro
- docker image rm osm/lcm
- docker image rm osm/light-ui
- docker image rm osm/nbi
- docker image rm osm/mon
- docker image rm osm/pm
- docker volume rm osm_mon_db
- docker volume rm osm_mongo_db
- docker volume rm osm_osm_packages
- docker volume rm osm_ro_db
+ if [ -n "$INSTALL_ONLY" ]; then
+ if [ -n "$INSTALL_ELK" ]; then
+ echo -e "\nUninstalling OSM ELK stack"
+ remove_stack osm_elk
+ sudo rm -rf /etc/osm/docker/osm_elk
+ fi
+ if [ -n "$INSTALL_PERFMON" ]; then
+ echo -e "\nUninstalling OSM Performance Monitoring stack"
+ remove_stack osm_metrics
+ sg docker -c "docker image rm osm/kafka-exporter"
+ sudo rm -rf /etc/osm/docker/osm_metrics
+ fi
+ else
+ echo -e "\nUninstalling OSM"
+ remove_stack osm
+ remove_stack osm_elk
+ remove_stack osm_metrics
+ echo "Now osm docker images and volumes will be deleted"
+ newgrp docker << EONG
+ docker image rm osm/ro
+ docker image rm osm/lcm
+ docker image rm osm/light-ui
+ docker image rm osm/nbi
+ docker image rm osm/mon
+ docker image rm osm/pm
+ docker image rm osm/kafka-exporter
+ docker volume rm osm_mon_db
+ docker volume rm osm_mongo_db
+ docker volume rm osm_osm_packages
+ docker volume rm osm_ro_db
EONG
- echo "Removing /etc/osm and /var/log/osm files"
- rm -rf /etc/osm
- rm -rf /var/log/osm
+ echo "Removing /etc/osm and /var/log/osm files"
+ sudo rm -rf /etc/osm
+ sudo rm -rf /var/log/osm
+ fi
+ echo "Some docker images will be kept in case they are used by other docker stacks"
+ echo "To remove them, just run 'docker image prune' in a terminal"
return 0
}
function generate_docker_images() {
echo "Pulling and generating docker images"
+ _build_from=$COMMIT_ID
+ [ -z "$_build_from" ] && _build_from="master"
+
+ echo "OSM Docker images generated from $_build_from"
+
if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then
sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image"
sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image"
echo "Finished generation of docker env files"
}
-function deploy_lightweight() {
- echo "Deploying lightweight build"
+function init_docker_swarm() {
if [ "${DEFAULT_MTU}" != "1500" ]; then
DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s`
DOCKER_GW_NET=`sg docker -c "docker network inspect ${DOCKER_NETS}" | grep Subnet | awk -F\" '{print $4}' | egrep "^172" | sort -u | tail -1 | awk -F\. '{if ($2 != 255) print $1"."$2+1"."$3"."$4; else print "-1";}'`
fi
sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}"
sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} netOSM"
+ return 0
+}
+
+function deploy_lightweight() {
+ echo "Deploying lightweight build"
+ [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm
remove_stack osm
sg docker -c "docker stack deploy -c /etc/osm/docker/docker-compose.yaml osm"
#docker-compose -f /etc/osm/docker/docker-compose.yaml up -d
}
function deploy_elk() {
+ echo "Pulling docker images for ELK"
+ sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
+ sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
+ sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
+ echo "Finished pulling elk docker images"
sudo mkdir -p /etc/osm/docker/osm_elk
sudo cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* /etc/osm/docker/osm_elk
remove_stack osm_elk
sg docker -c "docker stack deploy -c /etc/osm/docker/osm_elk/docker-compose.yml osm_elk"
echo "Waiting for ELK stack to be up and running"
time=0
- step=2
- timelength=20
+ step=5
+ timelength=40
elk_is_up=1
while [ $time -le $timelength ]; do
- if [[ $(curl -XGET http://127.0.0.1:5601/status -I | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
+ if [[ $(curl -f -XGET http://127.0.0.1:5601/status -I 2>/dev/null | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
elk_is_up=0
break
fi
#Create index pattern
curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
"http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
- -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"
+ -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
#Make it the default index
- curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+ curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
"http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
- -d"{\"value\":\"logstash-*\"}"
+ -d"{\"value\":\"logstash-*\"}" 2>/dev/null
else
echo "Cannot connect to Kibana to create index pattern."
echo "Once Kibana is running, you can use the following instructions to create index pattern:"
}
function deploy_perfmon() {
+ echo "Pulling docker images for PM (Grafana and Prometheus)"
+ sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
+ sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
+ echo "Finished pulling PM docker images"
echo "Generating osm/kafka-exporter docker image"
sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter --no-cache" || FATAL "cannot build kafka-exporter docker image"
echo "Finished generation of osm/kafka-exporter docker image"
function install_lightweight() {
[ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges."
+ [ -z "$ASSUME_YES" ] && ! ask_user "The installation will configure LXD, install juju, install docker CE and init a docker swarm, as pre-requirements. Do you want to proceed (Y/n)? " y && echo "Cancelled!" && exit 1
+ track proceed
echo "Installing lightweight build of OSM"
LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")"
trap 'rm -rf "${LWTEMPDIR}"' EXIT
DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'`
+ [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0"
DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'`
+ [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route"
DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}')
if [ -z "$INSTALL_NOLXD" ]; then
need_packages_lw="lxd"
|| sudo apt-get install -y $need_packages_lw \
|| FATAL "failed to install $need_packages_lw"
fi
+ track prereqok
install_juju
OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'`
OSMLCM_VCA_SECRET=`grep password ${HOME}/.local/share/juju/accounts.yaml |awk '{print $2}'`
[ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address"
[ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret"
track juju
- install_docker_ce
+ [ -n "$INSTALL_NODOCKER" ] || install_docker_ce
track docker_ce
#install_docker_compose
generate_docker_images
echo "Starting vim-emu Docker container 'vim-emu' ..."
if [ -n "$INSTALL_LIGHTWEIGHT" ]; then
# in lightweight mode, the emulator needs to be attached to netOSM
- sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
+ sudo docker run --name vim-emu -t -d --restart always --privileged --pid='host' --network=netOSM -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
else
# classic build mode
- sudo docker run --name vim-emu -t -d --rm --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
+ sudo docker run --name vim-emu -t -d --restart always --privileged --pid='host' -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py
fi
echo "Waiting for 'vim-emu' container to start ..."
sleep 5
echo "INSTALL_PERFMON=$INSTALL_PERFMON"
echo "TO_REBUILD=$TO_REBUILD"
echo "INSTALL_NOLXD=$INSTALL_NOLXD"
+ echo "INSTALL_NODOCKER=$INSTALL_NODOCKER"
echo "RELEASE=$RELEASE"
echo "REPOSITORY=$REPOSITORY"
echo "REPOSITORY_BASE=$REPOSITORY_BASE"
INSTALL_PERFMON=""
TO_REBUILD=""
INSTALL_NOLXD=""
+INSTALL_NODOCKER=""
NOCONFIGURE=""
RELEASE_DAILY=""
SESSION_ID=`date +%s`
[ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue
[ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue
[ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue
+ [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue
[ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue
[ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue
[ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue
[ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui"
[ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui"
[ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui"
+[ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui"
[ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui"
[ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options"
# if develop, we force master
[ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master"
-# forcing source from master removed. Now only install from source when explicit
-# [ -n "$COMMIT_ID" ] && [ "$COMMIT_ID" == "master" ] && INSTALL_FROM_SOURCE="y"
-
-if [ -z "$OSM_DEVOPS" ]; then
- if [ -n "$TEST_INSTALLER" ]; then
- echo -e "\nUsing local devops repo for OSM installation"
- TEMPDIR="$(dirname $(realpath $(dirname $0)))"
- else
- echo -e "\nCreating temporary dir for OSM installation"
- TEMPDIR="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
- trap 'rm -rf "$TEMPDIR"' EXIT
- fi
-fi
-
need_packages="git jq wget curl tar"
echo -e "Checking required packages: $need_packages"
dpkg -l $need_packages &>/dev/null \
|| FATAL "failed to install $need_packages"
if [ -z "$OSM_DEVOPS" ]; then
- if [ -z "$TEST_INSTALLER" ]; then
- echo -e "\nCloning devops repo temporarily"
- git clone https://osm.etsi.org/gerrit/osm/devops.git $TEMPDIR
- RC_CLONE=$?
- fi
+ if [ -n "$TEST_INSTALLER" ]; then
+ echo -e "\nUsing local devops repo for OSM installation"
+ OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))"
+ else
+ echo -e "\nCreating temporary dir for OSM installation"
+ OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")"
+ trap 'rm -rf "$OSM_DEVOPS"' EXIT
- echo -e "\nGuessing the current stable release"
- LATEST_STABLE_DEVOPS=`git -C $TEMPDIR tag -l v[0-9].* | sort -V | tail -n1`
- [ -z "$COMMIT_ID" ] && [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
- echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
- [ -z "$COMMIT_ID" ] && [ -n "$LATEST_STABLE_DEVOPS" ] && COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
-
- if [ -n "$RELEASE_DAILY" ]; then
- echo "Using master/HEAD devops"
- git -C $TEMPDIR checkout master
- elif [ -z "$TEST_INSTALLER" ]; then
- git -C $TEMPDIR checkout tags/$LATEST_STABLE_DEVOPS
+ git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS
+
+ if [ -z "$COMMIT_ID" ]; then
+ echo -e "\nGuessing the current stable release"
+ LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1`
+ [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0
+
+ echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS"
+ COMMIT_ID="tags/$LATEST_STABLE_DEVOPS"
+ else
+ echo -e "\nDEVOPS Using commit $COMMIT_ID"
+ fi
+ git -C $OSM_DEVOPS checkout $COMMIT_ID
fi
- OSM_DEVOPS=$TEMPDIR
fi
OSM_JENKINS="$OSM_DEVOPS/jenkins"