| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2016 Telefónica Investigación y Desarrollo S.A.U. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | function usage(){ |
| 17 | echo -e "usage: $0 [OPTIONS]" |
| 18 | echo -e "Install OSM from binaries or source code (by default, from binaries)" |
| 19 | echo -e " OPTIONS" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 20 | echo -e " -r <repo>: use specified repository name for osm packages" |
| 21 | echo -e " -R <release>: use specified release for osm binaries (deb packages, lxd images, ...)" |
| 22 | echo -e " -u <repo base>: use specified repository url for osm packages" |
| 23 | echo -e " -k <repo key>: use specified repository public key url" |
| 24 | echo -e " -b <refspec>: install OSM from source code using a specific branch (master, v2.0, ...) or tag" |
| 25 | echo -e " -b master (main dev branch)" |
| 26 | echo -e " -b v2.0 (v2.0 branch)" |
| 27 | echo -e " -b tags/v1.1.0 (a specific tag)" |
| 28 | echo -e " ..." |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 29 | echo -e " -s <stack name> user defined stack name, default is osm" |
| 30 | echo -e " -H <VCA host> use specific juju host controller IP" |
| 31 | echo -e " -S <VCA secret> use VCA/juju secret key" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 32 | echo -e " --vimemu: additionally deploy the VIM emulator as a docker container" |
| 33 | echo -e " --elk_stack: additionally deploy an ELK docker stack for event logging" |
| 34 | echo -e " --pm_stack: additionally deploy a Prometheus+Grafana stack for performance monitoring (PM)" |
| garciadeblas | 0e596bc | 2018-05-28 16:04:42 +0200 | [diff] [blame] | 35 | echo -e " -m <MODULE>: install OSM but only rebuild the specified docker images (RO, LCM, NBI, LW-UI, MON, KAFKA, MONGO, NONE)" |
| garciadeblas | 282ff4e | 2018-07-10 09:16:30 +0200 | [diff] [blame] | 36 | echo -e " -o <ADDON>: ONLY (un)installs one of the addons (vimemu, elk_stack, pm_stack)" |
| garciadeblas | e990f66 | 2018-05-18 11:43:39 +0200 | [diff] [blame] | 37 | echo -e " -D <devops path> use local devops installation path" |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 38 | echo -e " --nolxd: do not install and configure LXD, allowing unattended installations (assumes LXD is already installed and confifured)" |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 39 | echo -e " --nodocker: do not install docker, do not initialize a swarm (assumes docker is already installed and a swarm has been initialized)" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 40 | echo -e " --nojuju: do not juju, assumes already installed" |
| 41 | echo -e " --nodockerbuild:do not build docker images (use existing locally cached images)" |
| 42 | echo -e " --nohostports: do not expose docker ports to host (useful for creating multiple instances of osm on the same host)" |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 43 | echo -e " --nohostclient: do not install the osmclient" |
| garciadeblas | e990f66 | 2018-05-18 11:43:39 +0200 | [diff] [blame] | 44 | echo -e " --uninstall: uninstall OSM: remove the containers and delete NAT rules" |
| 45 | echo -e " --source: install OSM from source code using the latest stable tag" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 46 | echo -e " --develop: (deprecated, use '-b master') install OSM from source code using the master branch" |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 47 | echo -e " --soui: install classic build of OSM (Rel THREE v3.1, based on LXD containers, with SO and UI)" |
| 48 | echo -e " --lxdimages: (only for Rel THREE with --soui) download lxd images from OSM repository instead of creating them from scratch" |
| 49 | echo -e " -l <lxd_repo>: (only for Rel THREE with --soui) use specified repository url for lxd images" |
| 50 | echo -e " -p <path>: (only for Rel THREE with --soui) use specified repository path for lxd images" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 51 | # echo -e " --reconfigure: reconfigure the modules (DO NOT change NAT rules)" |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 52 | echo -e " --nat: (only for Rel THREE with --soui) install only NAT rules" |
| 53 | echo -e " --noconfigure: (only for Rel THREE with --soui) DO NOT install osmclient, DO NOT install NAT rules, DO NOT configure modules" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 54 | # echo -e " --update: update to the latest stable release or to the latest commit if using a specific branch" |
| 55 | echo -e " --showopts: print chosen options and exit (only for debugging)" |
| 56 | echo -e " -y: do not prompt for confirmation, assumes yes" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 57 | echo -e " -h / --help: print this help" |
| 58 | } |
| 59 | |
| 60 | #Uninstall OSM: remove containers |
| 61 | function uninstall(){ |
| 62 | echo -e "\nUninstalling OSM" |
| 63 | if [ $RC_CLONE ] || [ -n "$TEST_INSTALLER" ]; then |
| 64 | $OSM_DEVOPS/jenkins/host/clean_container RO |
| 65 | $OSM_DEVOPS/jenkins/host/clean_container VCA |
| 66 | $OSM_DEVOPS/jenkins/host/clean_container MON |
| 67 | $OSM_DEVOPS/jenkins/host/clean_container SO |
| 68 | #$OSM_DEVOPS/jenkins/host/clean_container UI |
| 69 | else |
| 70 | lxc stop RO && lxc delete RO |
| 71 | lxc stop VCA && lxc delete VCA |
| 72 | lxc stop MON && lxc delete MON |
| 73 | lxc stop SO-ub && lxc delete SO-ub |
| 74 | fi |
| 75 | echo -e "\nDeleting imported lxd images if they exist" |
| 76 | lxc image show osm-ro &>/dev/null && lxc image delete osm-ro |
| 77 | lxc image show osm-vca &>/dev/null && lxc image delete osm-vca |
| 78 | lxc image show osm-soui &>/dev/null && lxc image delete osm-soui |
| 79 | return 0 |
| 80 | } |
| 81 | |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 82 | # takes a juju/accounts.yaml file and returns the password specific |
| 83 | # for a controller. I wrote this using only bash tools to minimize |
| 84 | # additions of other packages |
| 85 | function parse_juju_password { |
| 86 | password_file="${HOME}/.local/share/juju/accounts.yaml" |
| 87 | local controller_name=$1 |
| Mike Marchetti | 2fafbba | 2018-09-13 15:35:42 -0400 | [diff] [blame] | 88 | local s='[[:space:]]*' w='[a-zA-Z0-9_-]*' fs=$(echo @|tr @ '\034') |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 89 | sed -ne "s|^\($s\):|\1|" \ |
| 90 | -e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \ |
| 91 | -e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $password_file | |
| 92 | awk -F$fs -v controller=$controller_name '{ |
| 93 | indent = length($1)/2; |
| 94 | vname[indent] = $2; |
| 95 | for (i in vname) {if (i > indent) {delete vname[i]}} |
| 96 | if (length($3) > 0) { |
| 97 | vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")} |
| 98 | if (match(vn,controller) && match($2,"password")) { |
| 99 | printf("%s",$3); |
| 100 | } |
| 101 | } |
| 102 | }' |
| 103 | } |
| 104 | |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 105 | function remove_volumes() { |
| 106 | stack=$1 |
| 107 | volumes="mongo_db mon_db osm_packages ro_db" |
| 108 | for volume in $volumes; do |
| 109 | sg docker -c "docker volume rm ${stack}_${volume}" |
| 110 | done |
| 111 | } |
| 112 | |
| 113 | function remove_network() { |
| 114 | stack=$1 |
| 115 | sg docker -c "docker network rm net${stack}" |
| 116 | } |
| 117 | |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 118 | function remove_stack() { |
| 119 | stack=$1 |
| garciadeblas | 5ef9821 | 2018-05-28 09:25:36 +0200 | [diff] [blame] | 120 | if sg docker -c "docker stack ps ${stack}" ; then |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 121 | echo -e "\nRemoving stack ${stack}" && sg docker -c "docker stack rm ${stack}" |
| 122 | COUNTER=0 |
| 123 | result=1 |
| 124 | while [ ${COUNTER} -lt 30 ]; do |
| 125 | result=$(sg docker -c "docker stack ps ${stack}" | wc -l) |
| 126 | #echo "Dockers running: $result" |
| 127 | if [ "${result}" == "0" ]; then |
| 128 | break |
| 129 | fi |
| 130 | let COUNTER=COUNTER+1 |
| 131 | sleep 1 |
| 132 | done |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 133 | if [ "${result}" == "0" ]; then |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 134 | echo "All dockers of the stack ${stack} were removed" |
| 135 | else |
| 136 | FATAL "Some dockers of the stack ${stack} could not be removed. Could not clean it." |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 137 | fi |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 138 | sleep 5 |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 139 | fi |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | #Uninstall lightweight OSM: remove dockers |
| 143 | function uninstall_lightweight() { |
| garciadeblas | 282ff4e | 2018-07-10 09:16:30 +0200 | [diff] [blame] | 144 | if [ -n "$INSTALL_ONLY" ]; then |
| 145 | if [ -n "$INSTALL_ELK" ]; then |
| 146 | echo -e "\nUninstalling OSM ELK stack" |
| 147 | remove_stack osm_elk |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 148 | rm -rf $OSM_DOCKER_WORK_DIR/osm_elk |
| garciadeblas | 282ff4e | 2018-07-10 09:16:30 +0200 | [diff] [blame] | 149 | fi |
| 150 | if [ -n "$INSTALL_PERFMON" ]; then |
| 151 | echo -e "\nUninstalling OSM Performance Monitoring stack" |
| 152 | remove_stack osm_metrics |
| 153 | sg docker -c "docker image rm osm/kafka-exporter" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 154 | rm -rf $OSM_DOCKER_WORK_DIR/osm_metrics |
| garciadeblas | 282ff4e | 2018-07-10 09:16:30 +0200 | [diff] [blame] | 155 | fi |
| 156 | else |
| 157 | echo -e "\nUninstalling OSM" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 158 | remove_stack $OSM_STACK_NAME |
| garciadeblas | 282ff4e | 2018-07-10 09:16:30 +0200 | [diff] [blame] | 159 | remove_stack osm_elk |
| 160 | remove_stack osm_metrics |
| 161 | echo "Now osm docker images and volumes will be deleted" |
| 162 | newgrp docker << EONG |
| 163 | docker image rm osm/ro |
| 164 | docker image rm osm/lcm |
| 165 | docker image rm osm/light-ui |
| 166 | docker image rm osm/nbi |
| 167 | docker image rm osm/mon |
| 168 | docker image rm osm/pm |
| 169 | docker image rm osm/kafka-exporter |
| garciadeblas | 83ca132 | 2018-05-22 18:31:14 +0200 | [diff] [blame] | 170 | EONG |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 171 | remove_volumes $OSM_STACK_NAME |
| 172 | remove_network $OSM_STACK_NAME |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 173 | echo "Removing $OSM_DOCKER_WORK_DIR" |
| 174 | rm -rf $OSM_DOCKER_WORK_DIR |
| garciadeblas | 282ff4e | 2018-07-10 09:16:30 +0200 | [diff] [blame] | 175 | fi |
| 176 | echo "Some docker images will be kept in case they are used by other docker stacks" |
| 177 | echo "To remove them, just run 'docker image prune' in a terminal" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 178 | return 0 |
| 179 | } |
| 180 | |
| 181 | #Configure NAT rules, based on the current IP addresses of containers |
| 182 | function nat(){ |
| 183 | echo -e "\nChecking required packages: iptables-persistent" |
| 184 | dpkg -l iptables-persistent &>/dev/null || ! echo -e " Not installed.\nInstalling iptables-persistent requires root privileges" || \ |
| 185 | sudo DEBIAN_FRONTEND=noninteractive apt-get -yq install iptables-persistent |
| 186 | echo -e "\nConfiguring NAT rules" |
| 187 | echo -e " Required root privileges" |
| 188 | sudo $OSM_DEVOPS/installers/nat_osm |
| 189 | } |
| 190 | |
| 191 | function FATAL(){ |
| 192 | echo "FATAL error: Cannot install OSM due to \"$1\"" |
| 193 | exit 1 |
| 194 | } |
| 195 | |
| 196 | #Update RO, SO and UI: |
| 197 | function update(){ |
| 198 | echo -e "\nUpdating components" |
| 199 | |
| 200 | echo -e " Updating RO" |
| 201 | CONTAINER="RO" |
| 202 | MDG="RO" |
| 203 | INSTALL_FOLDER="/opt/openmano" |
| 204 | echo -e " Fetching the repo" |
| 205 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 206 | BRANCH="" |
| 207 | BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'` |
| 208 | [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'" |
| 209 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 210 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 211 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 212 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 213 | CHECKOUT_ID=$COMMIT_ID |
| 214 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 215 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 216 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 217 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 218 | else |
| 219 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 220 | fi |
| 221 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 222 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 223 | echo " Nothing to be done." |
| 224 | else |
| 225 | echo " Update required." |
| 226 | lxc exec $CONTAINER -- service osm-ro stop |
| 227 | lxc exec $CONTAINER -- git -C /opt/openmano stash |
| 228 | lxc exec $CONTAINER -- git -C /opt/openmano pull --rebase |
| 229 | lxc exec $CONTAINER -- git -C /opt/openmano checkout $CHECKOUT_ID |
| 230 | lxc exec $CONTAINER -- git -C /opt/openmano stash pop |
| 231 | lxc exec $CONTAINER -- /opt/openmano/database_utils/migrate_mano_db.sh |
| 232 | lxc exec $CONTAINER -- service osm-ro start |
| 233 | fi |
| 234 | echo |
| 235 | |
| 236 | echo -e " Updating SO and UI" |
| 237 | CONTAINER="SO-ub" |
| 238 | MDG="SO" |
| 239 | INSTALL_FOLDER="" # To be filled in |
| 240 | echo -e " Fetching the repo" |
| 241 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 242 | BRANCH="" |
| 243 | BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'` |
| 244 | [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'" |
| 245 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 246 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 247 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 248 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 249 | CHECKOUT_ID=$COMMIT_ID |
| 250 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 251 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 252 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 253 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 254 | else |
| 255 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 256 | fi |
| 257 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 258 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 259 | echo " Nothing to be done." |
| 260 | else |
| 261 | echo " Update required." |
| 262 | # Instructions to be added |
| 263 | # lxc exec SO-ub -- ... |
| 264 | fi |
| 265 | echo |
| 266 | echo -e "Updating MON Container" |
| 267 | CONTAINER="MON" |
| 268 | MDG="MON" |
| 269 | INSTALL_FOLDER="/root/MON" |
| 270 | echo -e " Fetching the repo" |
| 271 | lxc exec $CONTAINER -- git -C $INSTALL_FOLDER fetch --all |
| 272 | BRANCH="" |
| 273 | BRANCH=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status -sb | head -n1 | sed -n 's/^## \(.*\).*/\1/p'|awk '{print $1}' |sed 's/\(.*\)\.\.\..*/\1/'` |
| 274 | [ -z "$BRANCH" ] && FATAL "Could not find the current branch in use in the '$MDG'" |
| 275 | CURRENT=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER status |head -n1` |
| 276 | CURRENT_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse HEAD` |
| 277 | echo " FROM: $CURRENT ($CURRENT_COMMIT_ID)" |
| 278 | # COMMIT_ID either was previously set with -b option, or is an empty string |
| 279 | CHECKOUT_ID=$COMMIT_ID |
| 280 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" == "HEAD" ] && CHECKOUT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 281 | [ -z "$CHECKOUT_ID" ] && [ "$BRANCH" != "HEAD" ] && CHECKOUT_ID="$BRANCH" |
| 282 | if [[ $CHECKOUT_ID == "tags/"* ]]; then |
| 283 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-list -n 1 $CHECKOUT_ID` |
| 284 | else |
| 285 | REMOTE_COMMIT_ID=`lxc exec $CONTAINER -- git -C $INSTALL_FOLDER rev-parse origin/$CHECKOUT_ID` |
| 286 | fi |
| 287 | echo " TO: $CHECKOUT_ID ($REMOTE_COMMIT_ID)" |
| 288 | if [ "$CURRENT_COMMIT_ID" == "$REMOTE_COMMIT_ID" ]; then |
| 289 | echo " Nothing to be done." |
| 290 | else |
| 291 | echo " Update required." |
| 292 | fi |
| 293 | echo |
| 294 | } |
| 295 | |
| 296 | function so_is_up() { |
| 297 | if [ -n "$1" ]; then |
| 298 | SO_IP=$1 |
| 299 | else |
| 300 | SO_IP=`lxc list SO-ub -c 4|grep eth0 |awk '{print $2}'` |
| 301 | fi |
| 302 | time=0 |
| 303 | step=5 |
| 304 | timelength=300 |
| 305 | while [ $time -le $timelength ] |
| 306 | do |
| 307 | if [[ `curl -k -X GET https://$SO_IP:8008/api/operational/vcs/info \ |
| 308 | -H 'accept: application/vnd.yang.data+json' \ |
| 309 | -H 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 310 | -H 'cache-control: no-cache' 2> /dev/null | jq '.[].components.component_info[] | select(.component_name=="RW.Restconf")' 2>/dev/null | grep "RUNNING" | wc -l` -eq 1 ]] |
| 311 | then |
| 312 | echo "RW.Restconf running....SO is up" |
| 313 | return 0 |
| 314 | fi |
| 315 | |
| 316 | sleep $step |
| 317 | echo -n "." |
| 318 | time=$((time+step)) |
| 319 | done |
| 320 | |
| 321 | FATAL "OSM Failed to startup. SO failed to startup" |
| 322 | } |
| 323 | |
| 324 | function vca_is_up() { |
| 325 | if [[ `lxc exec VCA -- juju status | grep "osm" | wc -l` -eq 1 ]]; then |
| 326 | echo "VCA is up and running" |
| 327 | return 0 |
| 328 | fi |
| 329 | |
| 330 | FATAL "OSM Failed to startup. VCA failed to startup" |
| 331 | } |
| 332 | |
| 333 | function mon_is_up() { |
| 334 | if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then |
| 335 | echo "MON is up and running" |
| 336 | return 0 |
| 337 | fi |
| 338 | |
| 339 | FATAL "OSM Failed to startup. MON failed to startup" |
| 340 | } |
| 341 | |
| 342 | function ro_is_up() { |
| 343 | if [ -n "$1" ]; then |
| 344 | RO_IP=$1 |
| 345 | else |
| 346 | RO_IP=`lxc list RO -c 4|grep eth0 |awk '{print $2}'` |
| 347 | fi |
| 348 | time=0 |
| 349 | step=2 |
| 350 | timelength=20 |
| 351 | while [ $time -le $timelength ]; do |
| 352 | if [[ `curl http://$RO_IP:9090/openmano/ | grep "works" | wc -l` -eq 1 ]]; then |
| 353 | echo "RO is up and running" |
| 354 | return 0 |
| 355 | fi |
| 356 | sleep $step |
| 357 | echo -n "." |
| 358 | time=$((time+step)) |
| 359 | done |
| 360 | |
| 361 | FATAL "OSM Failed to startup. RO failed to startup" |
| 362 | } |
| 363 | |
| 364 | |
| 365 | function configure_RO(){ |
| 366 | . $OSM_DEVOPS/installers/export_ips |
| 367 | echo -e " Configuring RO" |
| 368 | lxc exec RO -- sed -i -e "s/^\#\?log_socket_host:.*/log_socket_host: $SO_CONTAINER_IP/g" /etc/osm/openmanod.cfg |
| 369 | lxc exec RO -- service osm-ro restart |
| 370 | |
| 371 | ro_is_up |
| 372 | |
| 373 | lxc exec RO -- openmano tenant-delete -f osm >/dev/null |
| 374 | lxc exec RO -- openmano tenant-create osm > /dev/null |
| 375 | lxc exec RO -- sed -i '/export OPENMANO_TENANT=osm/d' .bashrc |
| 376 | lxc exec RO -- sed -i '$ i export OPENMANO_TENANT=osm' .bashrc |
| 377 | lxc exec RO -- sh -c 'echo "export OPENMANO_TENANT=osm" >> .bashrc' |
| 378 | } |
| 379 | |
| 380 | function configure_VCA(){ |
| 381 | echo -e " Configuring VCA" |
| 382 | JUJU_PASSWD=`date +%s | sha256sum | base64 | head -c 32` |
| 383 | echo -e "$JUJU_PASSWD\n$JUJU_PASSWD" | lxc exec VCA -- juju change-user-password |
| 384 | } |
| 385 | |
| 386 | function configure_SOUI(){ |
| 387 | . $OSM_DEVOPS/installers/export_ips |
| 388 | JUJU_CONTROLLER_IP=`lxc exec VCA -- lxc list -c 4 |grep eth0 |awk '{print $2}'` |
| 389 | RO_TENANT_ID=`lxc exec RO -- openmano tenant-list osm |awk '{print $1}'` |
| 390 | |
| 391 | echo -e " Configuring MON" |
| 392 | #Information to be added about SO socket for logging |
| 393 | |
| 394 | echo -e " Configuring SO" |
| 395 | sudo route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP |
| garciadeblas | 818fa5a | 2018-05-10 13:39:10 +0200 | [diff] [blame] | 396 | sudo ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 397 | sudo sed -i "$ i route add -host $JUJU_CONTROLLER_IP gw $VCA_CONTAINER_IP" /etc/rc.local |
| garciadeblas | 818fa5a | 2018-05-10 13:39:10 +0200 | [diff] [blame] | 398 | sudo sed -i "$ i ip route add 10.44.127.0/24 via $VCA_CONTAINER_IP" /etc/rc.local |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 399 | # make journaling persistent |
| 400 | lxc exec SO-ub -- mkdir -p /var/log/journal |
| 401 | lxc exec SO-ub -- systemd-tmpfiles --create --prefix /var/log/journal |
| 402 | lxc exec SO-ub -- systemctl restart systemd-journald |
| 403 | |
| 404 | echo RIFT_EXTERNAL_ADDRESS=$DEFAULT_IP | lxc exec SO-ub -- tee -a /usr/rift/etc/default/launchpad |
| 405 | |
| 406 | lxc exec SO-ub -- systemctl restart launchpad |
| 407 | |
| 408 | so_is_up $SO_CONTAINER_IP |
| 409 | |
| 410 | #delete existing config agent (could be there on reconfigure) |
| 411 | curl -k --request DELETE \ |
| 412 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent/account/osmjuju \ |
| 413 | --header 'accept: application/vnd.yang.data+json' \ |
| 414 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 415 | --header 'cache-control: no-cache' \ |
| 416 | --header 'content-type: application/vnd.yang.data+json' &> /dev/null |
| 417 | |
| 418 | result=$(curl -k --request POST \ |
| 419 | --url https://$SO_CONTAINER_IP:8008/api/config/config-agent \ |
| 420 | --header 'accept: application/vnd.yang.data+json' \ |
| 421 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 422 | --header 'cache-control: no-cache' \ |
| 423 | --header 'content-type: application/vnd.yang.data+json' \ |
| 424 | --data '{"account": [ { "name": "osmjuju", "account-type": "juju", "juju": { "ip-address": "'$JUJU_CONTROLLER_IP'", "port": "17070", "user": "admin", "secret": "'$JUJU_PASSWD'" } } ]}') |
| 425 | [[ $result =~ .*success.* ]] || FATAL "Failed config-agent configuration: $result" |
| 426 | |
| 427 | #R1/R2 config line |
| 428 | #result=$(curl -k --request PUT \ |
| 429 | # --url https://$SO_CONTAINER_IP:8008/api/config/resource-orchestrator \ |
| 430 | # --header 'accept: application/vnd.yang.data+json' \ |
| 431 | # --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 432 | # --header 'cache-control: no-cache' \ |
| 433 | # --header 'content-type: application/vnd.yang.data+json' \ |
| 434 | # --data '{ "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'" }, "name": "osmopenmano", "account-type": "openmano" }') |
| 435 | |
| 436 | result=$(curl -k --request PUT \ |
| 437 | --url https://$SO_CONTAINER_IP:8008/api/config/project/default/ro-account/account \ |
| 438 | --header 'accept: application/vnd.yang.data+json' \ |
| 439 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 440 | --header 'cache-control: no-cache' \ |
| 441 | --header 'content-type: application/vnd.yang.data+json' \ |
| 442 | --data '{"rw-ro-account:account": [ { "openmano": { "host": "'$RO_CONTAINER_IP'", "port": "9090", "tenant-id": "'$RO_TENANT_ID'"}, "name": "osmopenmano", "ro-account-type": "openmano" }]}') |
| 443 | [[ $result =~ .*success.* ]] || FATAL "Failed resource-orchestrator configuration: $result" |
| 444 | |
| 445 | result=$(curl -k --request PATCH \ |
| 446 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/redirect-uri \ |
| 447 | --header 'accept: application/vnd.yang.data+json' \ |
| 448 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 449 | --header 'cache-control: no-cache' \ |
| 450 | --header 'content-type: application/vnd.yang.data+json' \ |
| 451 | --data '{"redirect-uri": "https://'$DEFAULT_IP':8443/callback" }') |
| 452 | [[ $result =~ .*success.* ]] || FATAL "Failed redirect-uri configuration: $result" |
| 453 | |
| 454 | result=$(curl -k --request PATCH \ |
| 455 | --url https://$SO_CONTAINER_IP:8008/v2/api/config/openidc-provider-config/rw-ui-client/post-logout-redirect-uri \ |
| 456 | --header 'accept: application/vnd.yang.data+json' \ |
| 457 | --header 'authorization: Basic YWRtaW46YWRtaW4=' \ |
| 458 | --header 'cache-control: no-cache' \ |
| 459 | --header 'content-type: application/vnd.yang.data+json' \ |
| 460 | --data '{"post-logout-redirect-uri": "https://'$DEFAULT_IP':8443/?api_server=https://'$DEFAULT_IP'" }') |
| 461 | [[ $result =~ .*success.* ]] || FATAL "Failed post-logout-redirect-uri configuration: $result" |
| 462 | |
| 463 | lxc exec SO-ub -- tee /etc/network/interfaces.d/60-rift.cfg <<EOF |
| 464 | auto lo:1 |
| 465 | iface lo:1 inet static |
| 466 | address $DEFAULT_IP |
| 467 | netmask 255.255.255.255 |
| 468 | EOF |
| 469 | lxc exec SO-ub ifup lo:1 |
| 470 | } |
| 471 | |
| 472 | #Configure RO, VCA, and SO with the initial configuration: |
| 473 | # RO -> tenant:osm, logs to be sent to SO |
| 474 | # VCA -> juju-password |
| 475 | # SO -> route to Juju Controller, add RO account, add VCA account |
| 476 | function configure(){ |
| 477 | #Configure components |
| 478 | echo -e "\nConfiguring components" |
| 479 | configure_RO |
| 480 | configure_VCA |
| 481 | configure_SOUI |
| 482 | } |
| 483 | |
| 484 | function install_lxd() { |
| 485 | sudo apt-get update |
| 486 | sudo apt-get install -y lxd |
| 487 | newgrp lxd |
| 488 | lxd init --auto |
| 489 | lxd waitready |
| 490 | lxc network create lxdbr0 ipv4.address=auto ipv4.nat=true ipv6.address=none ipv6.nat=false |
| 491 | DEFAULT_INTERFACE=$(route -n | awk '$1~/^0.0.0.0/ {print $8}') |
| 492 | DEFAULT_MTU=$(ip addr show $DEFAULT_INTERFACE | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| 493 | lxc profile device set default eth0 mtu $DEFAULT_MTU |
| 494 | #sudo systemctl stop lxd-bridge |
| 495 | #sudo systemctl --system daemon-reload |
| 496 | #sudo systemctl enable lxd-bridge |
| 497 | #sudo systemctl start lxd-bridge |
| 498 | } |
| 499 | |
| 500 | function ask_user(){ |
| 501 | # ask to the user and parse a response among 'y', 'yes', 'n' or 'no'. Case insensitive |
| 502 | # Params: $1 text to ask; $2 Action by default, can be 'y' for yes, 'n' for no, other or empty for not allowed |
| 503 | # Return: true(0) if user type 'yes'; false (1) if user type 'no' |
| 504 | read -e -p "$1" USER_CONFIRMATION |
| 505 | while true ; do |
| 506 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'y' ] && return 0 |
| 507 | [ -z "$USER_CONFIRMATION" ] && [ "$2" == 'n' ] && return 1 |
| 508 | [ "${USER_CONFIRMATION,,}" == "yes" ] || [ "${USER_CONFIRMATION,,}" == "y" ] && return 0 |
| 509 | [ "${USER_CONFIRMATION,,}" == "no" ] || [ "${USER_CONFIRMATION,,}" == "n" ] && return 1 |
| 510 | read -e -p "Please type 'yes' or 'no': " USER_CONFIRMATION |
| 511 | done |
| 512 | } |
| 513 | |
| 514 | function launch_container_from_lxd(){ |
| 515 | export OSM_MDG=$1 |
| 516 | OSM_load_config |
| 517 | export OSM_BASE_IMAGE=$2 |
| 518 | if ! container_exists $OSM_BUILD_CONTAINER; then |
| 519 | CONTAINER_OPTS="" |
| 520 | [[ "$OSM_BUILD_CONTAINER_PRIVILEGED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.privileged=true" |
| 521 | [[ "$OSM_BUILD_CONTAINER_ALLOW_NESTED" == yes ]] && CONTAINER_OPTS="$CONTAINER_OPTS -c security.nesting=true" |
| 522 | create_container $OSM_BASE_IMAGE $OSM_BUILD_CONTAINER $CONTAINER_OPTS |
| 523 | wait_container_up $OSM_BUILD_CONTAINER |
| 524 | fi |
| 525 | } |
| 526 | |
| 527 | function install_osmclient(){ |
| 528 | CLIENT_RELEASE=${RELEASE#"-R "} |
| 529 | CLIENT_REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" |
| 530 | CLIENT_REPOSITORY=${REPOSITORY#"-r "} |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 531 | CLIENT_REPOSITORY_BASE=${REPOSITORY_BASE#"-u "} |
| 532 | key_location=$CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE/$CLIENT_REPOSITORY_KEY |
| 533 | curl $key_location | sudo apt-key add - |
| 534 | sudo add-apt-repository -y "deb [arch=amd64] $CLIENT_REPOSITORY_BASE/$CLIENT_RELEASE $CLIENT_REPOSITORY osmclient" |
| 535 | sudo apt-get update |
| 536 | sudo apt-get install -y python-pip |
| 537 | sudo -H pip install pip==9.0.3 |
| 538 | sudo -H pip install python-magic |
| 539 | sudo apt-get install -y python-osmclient |
| 540 | #sed 's,OSM_SOL005=[^$]*,OSM_SOL005=True,' -i ${HOME}/.bashrc |
| 541 | #echo 'export OSM_HOSTNAME=localhost' >> ${HOME}/.bashrc |
| 542 | #echo 'export OSM_SOL005=True' >> ${HOME}/.bashrc |
| 543 | [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=`lxc list | awk '($2=="SO-ub"){print $6}'` |
| 544 | [ -z "$INSTALL_LIGHTWEIGHT" ] && export OSM_RO_HOSTNAME=`lxc list | awk '($2=="RO"){print $6}'` |
| garciadeblas | 8e6bc15 | 2018-05-14 11:36:11 +0200 | [diff] [blame] | 545 | [ -n "$INSTALL_LIGHTWEIGHT" ] && export OSM_HOSTNAME=127.0.0.1 |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 546 | echo -e "\nOSM client installed" |
| 547 | echo -e "You might be interested in adding the following OSM client env variables to your .bashrc file:" |
| 548 | echo " export OSM_HOSTNAME=${OSM_HOSTNAME}" |
| 549 | [ -n "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_SOL005=True" |
| 550 | [ -z "$INSTALL_LIGHTWEIGHT" ] && echo " export OSM_RO_HOSTNAME=${OSM_RO_HOSTNAME}" |
| 551 | return 0 |
| 552 | } |
| 553 | |
| 554 | function install_from_lxdimages(){ |
| 555 | LXD_RELEASE=${RELEASE#"-R "} |
| 556 | if [ -n "$LXD_REPOSITORY_PATH" ]; then |
| 557 | LXD_IMAGE_DIR="$LXD_REPOSITORY_PATH" |
| 558 | else |
| 559 | LXD_IMAGE_DIR="$(mktemp -d -q --tmpdir "osmimages.XXXXXX")" |
| 560 | trap 'rm -rf "$LXD_IMAGE_DIR"' EXIT |
| 561 | fi |
| 562 | echo -e "\nDeleting previous lxd images if they exist" |
| 563 | lxc image show osm-ro &>/dev/null && lxc image delete osm-ro |
| 564 | lxc image show osm-vca &>/dev/null && lxc image delete osm-vca |
| 565 | lxc image show osm-soui &>/dev/null && lxc image delete osm-soui |
| 566 | echo -e "\nImporting osm-ro" |
| 567 | [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-ro.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-ro.tar.gz |
| 568 | lxc image import $LXD_IMAGE_DIR/osm-ro.tar.gz --alias osm-ro |
| 569 | rm -f $LXD_IMAGE_DIR/osm-ro.tar.gz |
| 570 | echo -e "\nImporting osm-vca" |
| 571 | [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-vca.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-vca.tar.gz |
| 572 | lxc image import $LXD_IMAGE_DIR/osm-vca.tar.gz --alias osm-vca |
| 573 | rm -f $LXD_IMAGE_DIR/osm-vca.tar.gz |
| 574 | echo -e "\nImporting osm-soui" |
| 575 | [ -z "$LXD_REPOSITORY_PATH" ] && wget -O $LXD_IMAGE_DIR/osm-soui.tar.gz $LXD_REPOSITORY_BASE/$LXD_RELEASE/osm-soui.tar.gz |
| 576 | lxc image import $LXD_IMAGE_DIR/osm-soui.tar.gz --alias osm-soui |
| 577 | rm -f $LXD_IMAGE_DIR/osm-soui.tar.gz |
| 578 | launch_container_from_lxd RO osm-ro |
| 579 | ro_is_up && track RO |
| 580 | launch_container_from_lxd VCA osm-vca |
| 581 | vca_is_up && track VCA |
| 582 | launch_container_from_lxd MON osm-mon |
| 583 | mon_is_up && track MON |
| 584 | launch_container_from_lxd SO osm-soui |
| 585 | #so_is_up && track SOUI |
| 586 | track SOUI |
| 587 | } |
| 588 | |
| 589 | function install_docker_ce() { |
| 590 | # installs and configures Docker CE |
| 591 | echo "Installing Docker CE ..." |
| 592 | sudo apt-get -qq update |
| 593 | sudo apt-get install -y apt-transport-https ca-certificates software-properties-common |
| 594 | curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - |
| 595 | sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" |
| 596 | sudo apt-get -qq update |
| 597 | sudo apt-get install -y docker-ce |
| 598 | echo "Adding user to group 'docker'" |
| 599 | sudo groupadd -f docker |
| 600 | sudo usermod -aG docker $USER |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 601 | sleep 2 |
| 602 | sudo service docker restart |
| 603 | echo "... restarted Docker service" |
| garciadeblas | 67ce97c | 2018-05-18 10:22:09 +0200 | [diff] [blame] | 604 | sg docker -c "docker version" || FATAL "Docker installation failed" |
| 605 | echo "... Docker CE installation done" |
| 606 | return 0 |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | function install_docker_compose() { |
| 610 | # installs and configures docker-compose |
| 611 | echo "Installing Docker Compose ..." |
| 612 | sudo curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose |
| 613 | sudo chmod +x /usr/local/bin/docker-compose |
| 614 | echo "... Docker Compose installation done" |
| 615 | } |
| 616 | |
| 617 | function install_juju() { |
| 618 | echo "Installing juju" |
| 619 | sudo snap install juju --classic |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 620 | [ -z "$INSTALL_NOLXD" ] && sudo dpkg-reconfigure -p medium lxd |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 621 | echo "Finished installation of juju" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 622 | return 0 |
| 623 | } |
| 624 | |
| 625 | function juju_createcontroller() { |
| 626 | if ! sg lxd -c "juju show-controller $OSM_STACK_NAME &> /dev/null"; then |
| 627 | # Not found created, create the controller |
| 628 | sg lxd -c "juju bootstrap --bootstrap-series=xenial localhost $OSM_STACK_NAME" |
| 629 | fi |
| 630 | [ $(sg lxd -c "juju controllers" |grep "$OSM_STACK_NAME" |wc -l) -eq 1 ] || FATAL "Juju installation failed" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | function generate_docker_images() { |
| 634 | echo "Pulling and generating docker images" |
| Michael Marchetti | ee37414 | 2018-08-02 22:47:16 +0200 | [diff] [blame] | 635 | _build_from=$COMMIT_ID |
| 636 | [ -z "$_build_from" ] && _build_from="master" |
| 637 | |
| 638 | echo "OSM Docker images generated from $_build_from" |
| 639 | |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 640 | BUILD_ARGS+=(--build-arg REPOSITORY="$REPOSITORY") |
| 641 | BUILD_ARGS+=(--build-arg RELEASE="$RELEASE") |
| 642 | BUILD_ARGS+=(--build-arg REPOSITORY_KEY="$REPOSITORY_KEY") |
| 643 | BUILD_ARGS+=(--build-arg REPOSITORY_BASE="$REPOSITORY_BASE") |
| 644 | |
| garciadeblas | 0e596bc | 2018-05-28 16:04:42 +0200 | [diff] [blame] | 645 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q KAFKA ; then |
| 646 | sg docker -c "docker pull wurstmeister/zookeeper" || FATAL "cannot get zookeeper docker image" |
| 647 | sg docker -c "docker pull wurstmeister/kafka" || FATAL "cannot get kafka docker image" |
| 648 | fi |
| 649 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MONGO ; then |
| 650 | sg docker -c "docker pull mongo" || FATAL "cannot get mongo docker image" |
| 651 | fi |
| 652 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q MON ; then |
| 653 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/MON |
| 654 | git -C ${LWTEMPDIR}/MON checkout ${COMMIT_ID} |
| 655 | sg docker -c "docker build ${LWTEMPDIR}/MON -f ${LWTEMPDIR}/MON/docker/Dockerfile -t osm/mon --no-cache" || FATAL "cannot build MON docker image" |
| 656 | sg docker -c "docker build ${LWTEMPDIR}/MON/policy_module -f ${LWTEMPDIR}/MON/policy_module/Dockerfile -t osm/pm --no-cache" || FATAL "cannot build PM docker image" |
| 657 | fi |
| 658 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q NBI ; then |
| 659 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/NBI |
| 660 | git -C ${LWTEMPDIR}/NBI checkout ${COMMIT_ID} |
| 661 | sg docker -c "docker build ${LWTEMPDIR}/NBI -f ${LWTEMPDIR}/NBI/Dockerfile.local -t osm/nbi --no-cache" || FATAL "cannot build NBI docker image" |
| 662 | fi |
| 663 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q RO ; then |
| 664 | sg docker -c "docker pull mysql:5" || FATAL "cannot get mysql docker image" |
| 665 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/RO |
| 666 | git -C ${LWTEMPDIR}/RO checkout ${COMMIT_ID} |
| 667 | sg docker -c "docker build ${LWTEMPDIR}/RO -f ${LWTEMPDIR}/RO/docker/Dockerfile-local -t osm/ro --no-cache" || FATAL "cannot build RO docker image" |
| 668 | fi |
| 669 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LCM ; then |
| 670 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LCM |
| 671 | git -C ${LWTEMPDIR}/LCM checkout ${COMMIT_ID} |
| 672 | sg docker -c "docker build ${LWTEMPDIR}/LCM -f ${LWTEMPDIR}/LCM/Dockerfile.local -t osm/lcm --no-cache" || FATAL "cannot build LCM docker image" |
| 673 | fi |
| 674 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-UI ; then |
| 675 | git -C ${LWTEMPDIR} clone https://osm.etsi.org/gerrit/osm/LW-UI |
| 676 | git -C ${LWTEMPDIR}/LW-UI checkout ${COMMIT_ID} |
| 677 | sg docker -c "docker build ${LWTEMPDIR}/LW-UI -t osm/light-ui -f ${LWTEMPDIR}/LW-UI/Dockerfile --no-cache" || FATAL "cannot build LW-UI docker image" |
| 678 | fi |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 679 | if [ -z "$TO_REBUILD" ] || echo $TO_REBUILD | grep -q LW-osmclient; then |
| 680 | sg docker -c "docker build -t osm/osmclient ${BUILD_ARGS[@]} -f $OSM_DEVOPS/docker/osmclient ." |
| 681 | fi |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 682 | echo "Finished generation of docker images" |
| 683 | } |
| 684 | |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 685 | function cmp_overwrite() { |
| 686 | file1="$1" |
| 687 | file2="$2" |
| 688 | if ! $(cmp "${file1}" "${file2}" >/dev/null 2>&1); then |
| 689 | if [ -f "${file2}" ]; then |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 690 | ask_user "The file ${file2} already exists. Overwrite (y/N)? " n && cp -b ${file1} ${file2} |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 691 | else |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 692 | cp -b ${file1} ${file2} |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 693 | fi |
| 694 | fi |
| 695 | } |
| 696 | |
| garciadeblas | cf0e34a | 2018-05-24 10:45:53 +0200 | [diff] [blame] | 697 | function generate_config_log_folders() { |
| 698 | echo "Generating config and log folders" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 699 | cp -b ${OSM_DEVOPS}/installers/docker/docker-compose.yaml $OSM_DOCKER_WORK_DIR/docker-compose.yaml |
| garciadeblas | cf0e34a | 2018-05-24 10:45:53 +0200 | [diff] [blame] | 700 | echo "Finished generation of config and log folders" |
| 701 | } |
| 702 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 703 | function generate_docker_env_files() { |
| 704 | echo "Generating docker env files" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 705 | echo "OSMLCM_VCA_HOST=${OSMLCM_VCA_HOST}" | tee $OSM_DOCKER_WORK_DIR/lcm.env |
| 706 | echo "OSMLCM_VCA_SECRET=${OSMLCM_VCA_SECRET}" | tee -a $OSM_DOCKER_WORK_DIR/lcm.env |
| 707 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 708 | MYSQL_ROOT_PASSWORD=`date +%s | sha256sum | base64 | head -c 32` |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 709 | if [ ! -f $OSM_DOCKER_WORK_DIR/ro-db.env ]; then |
| 710 | echo "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro-db.env |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 711 | fi |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 712 | if [ ! -f $OSM_DOCKER_WORK_DIR/ro.env ]; then |
| 713 | echo "RO_DB_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}" |tee $OSM_DOCKER_WORK_DIR/ro.env |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 714 | fi |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 715 | echo "OS_NOTIFIER_URI=http://${DEFAULT_IP}:8662" |tee $OSM_DOCKER_WORK_DIR/mon.env |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 716 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 717 | echo "Finished generation of docker env files" |
| 718 | } |
| 719 | |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 720 | function generate_osmclient_script () { |
| 721 | cat >"$OSM_DOCKER_WORK_DIR/osm" <<-EOF |
| 722 | docker run -ti --network net${OSM_STACK_NAME} osm/osmclient |
| 723 | EOF |
| 724 | chmod +x "$OSM_DOCKER_WORK_DIR/osm" |
| 725 | echo "osmclient sidecar container can be found at: $OSM_DOCKER_WORK_DIR/osm" |
| 726 | } |
| 727 | |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 728 | function init_docker_swarm() { |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 729 | if [ "${DEFAULT_MTU}" != "1500" ]; then |
| 730 | DOCKER_NETS=`sg docker -c "docker network list" | awk '{print $2}' | egrep -v "^ID$" | paste -d " " -s` |
| 731 | 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";}'` |
| 732 | sg docker -c "docker network create --subnet ${DOCKER_GW_NET} --opt com.docker.network.bridge.name=docker_gwbridge --opt com.docker.network.bridge.enable_icc=false --opt com.docker.network.bridge.enable_ip_masquerade=true --opt com.docker.network.driver.mtu=${DEFAULT_MTU} docker_gwbridge" |
| 733 | fi |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 734 | sg docker -c "docker swarm init --advertise-addr ${DEFAULT_IP}" |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 735 | return 0 |
| 736 | } |
| 737 | |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 738 | function create_docker_network() { |
| 739 | echo "creating network" |
| 740 | sg docker -c "docker network create --driver=overlay --attachable --opt com.docker.network.driver.mtu=${DEFAULT_MTU} net${OSM_STACK_NAME}" |
| 741 | echo "creating network DONE" |
| 742 | } |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 743 | |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 744 | function deploy_lightweight() { |
| 745 | |
| 746 | echo "Deploying lightweight build" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 747 | OSM_NBI_PORT=9999 |
| 748 | OSM_RO_PORT=9090 |
| 749 | OSM_UI_PORT=80 |
| 750 | |
| 751 | if [ -n "$NO_HOST_PORTS" ]; then |
| 752 | OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT) |
| 753 | OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT) |
| 754 | OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT) |
| 755 | else |
| 756 | OSM_PORTS+=(OSM_NBI_PORTS=$OSM_NBI_PORT:$OSM_NBI_PORT) |
| 757 | OSM_PORTS+=(OSM_RO_PORTS=$OSM_RO_PORT:$OSM_RO_PORT) |
| 758 | OSM_PORTS+=(OSM_UI_PORTS=$OSM_UI_PORT:$OSM_UI_PORT) |
| 759 | fi |
| 760 | echo "export ${OSM_PORTS[@]}" > $OSM_DOCKER_WORK_DIR/osm_ports.sh |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 761 | echo "export OSM_NETWORK=net${OSM_STACK_NAME}" >> $OSM_DOCKER_WORK_DIR/osm_ports.sh |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 762 | |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 763 | pushd $OSM_DOCKER_WORK_DIR |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 764 | sg docker -c "source ./osm_ports.sh; docker stack deploy -c $OSM_DOCKER_WORK_DIR/docker-compose.yaml $OSM_STACK_NAME" |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 765 | popd |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 766 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 767 | echo "Finished deployment of lightweight build" |
| 768 | } |
| 769 | |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 770 | function deploy_elk() { |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 771 | echo "Pulling docker images for ELK" |
| 772 | sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image" |
| 773 | sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image" |
| 774 | sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image" |
| 775 | echo "Finished pulling elk docker images" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 776 | mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk" |
| 777 | cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 778 | remove_stack osm_elk |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 779 | echo "Deploying ELK stack" |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 780 | sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_elk/docker-compose.yml osm_elk" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 781 | echo "Waiting for ELK stack to be up and running" |
| 782 | time=0 |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 783 | step=5 |
| 784 | timelength=40 |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 785 | elk_is_up=1 |
| 786 | while [ $time -le $timelength ]; do |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 787 | 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 |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 788 | elk_is_up=0 |
| 789 | break |
| 790 | fi |
| 791 | sleep $step |
| 792 | time=$((time+step)) |
| 793 | done |
| 794 | if [ $elk_is_up -eq 0 ]; then |
| 795 | echo "ELK is up and running. Trying to create index pattern..." |
| 796 | #Create index pattern |
| 797 | curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 798 | "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \ |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 799 | -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 800 | #Make it the default index |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 801 | curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 802 | "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \ |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 803 | -d"{\"value\":\"logstash-*\"}" 2>/dev/null |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 804 | else |
| 805 | echo "Cannot connect to Kibana to create index pattern." |
| 806 | echo "Once Kibana is running, you can use the following instructions to create index pattern:" |
| 807 | echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 808 | "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \ |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 809 | -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"' |
| 810 | echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \ |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 811 | "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \ |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 812 | -d"{\"value\":\"logstash-*\"}"' |
| 813 | fi |
| 814 | echo "Finished deployment of ELK stack" |
| 815 | return 0 |
| 816 | } |
| 817 | |
| 818 | function deploy_perfmon() { |
| garciadeblas | e2aebfe | 2018-07-06 14:11:20 +0200 | [diff] [blame] | 819 | echo "Pulling docker images for PM (Grafana and Prometheus)" |
| 820 | sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image" |
| 821 | sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image" |
| 822 | echo "Finished pulling PM docker images" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 823 | echo "Generating osm/kafka-exporter docker image" |
| garciadeblas | c119fb3 | 2018-05-25 09:13:30 +0200 | [diff] [blame] | 824 | 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" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 825 | echo "Finished generation of osm/kafka-exporter docker image" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 826 | mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics |
| 827 | cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics |
| 828 | cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics |
| garciadeblas | 5b857d3 | 2018-05-24 18:37:58 +0200 | [diff] [blame] | 829 | remove_stack osm_metrics |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 830 | echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)" |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 831 | sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_metrics/docker-compose.yml osm_metrics" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 832 | echo "Finished deployment of PM stack" |
| 833 | return 0 |
| 834 | } |
| 835 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 836 | function install_lightweight() { |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 837 | [ -z "$OSM_DOCKER_WORK_DIR" ] && OSM_DOCKER_WORK_DIR="$HOME/.osm/stack/$OSM_STACK_NAME" |
| 838 | [ ! -d "$OSM_DOCKER_WORK_DIR" ] && mkdir -p $OSM_DOCKER_WORK_DIR |
| 839 | |
| garciadeblas | d13a8aa | 2018-05-18 15:24:51 +0200 | [diff] [blame] | 840 | [ "$USER" == "root" ] && FATAL "You are running the installer as root. The installer is prepared to be executed as a normal user with sudo privileges." |
| garciadeblas | 0ebde16 | 2018-05-30 18:36:29 +0200 | [diff] [blame] | 841 | [ -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 |
| garciadeblas | fae5e97 | 2018-06-12 18:27:11 +0200 | [diff] [blame] | 842 | track proceed |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 843 | echo "Installing lightweight build of OSM" |
| 844 | LWTEMPDIR="$(mktemp -d -q --tmpdir "installosmlight.XXXXXX")" |
| 845 | trap 'rm -rf "${LWTEMPDIR}"' EXIT |
| 846 | DEFAULT_IF=`route -n |awk '$1~/^0.0.0.0/ {print $8}'` |
| garciadeblas | 8cd6077 | 2018-06-02 08:38:17 +0200 | [diff] [blame] | 847 | [ -z "$DEFAULT_IF" ] && FATAL "Not possible to determine the interface with the default route 0.0.0.0" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 848 | DEFAULT_IP=`ip -o -4 a |grep ${DEFAULT_IF}|awk '{split($4,a,"/"); print a[1]}'` |
| garciadeblas | 8cd6077 | 2018-06-02 08:38:17 +0200 | [diff] [blame] | 849 | [ -z "$DEFAULT_IP" ] && FATAL "Not possible to determine the IP address of the interface with the default route" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 850 | DEFAULT_MTU=$(ip addr show ${DEFAULT_IF} | perl -ne 'if (/mtu\s(\d+)/) {print $1;}') |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 851 | |
| 852 | # if no host is passed in, we need to install lxd/juju, unless explicilty asked not to |
| 853 | if [ -z "$OSMLCM_VCA_HOST" ] && [ -z "$INSTALL_NOLXD" ]; then |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 854 | need_packages_lw="lxd" |
| 855 | echo -e "Checking required packages: $need_packages_lw" |
| 856 | dpkg -l $need_packages_lw &>/dev/null \ |
| 857 | || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ |
| 858 | || sudo apt-get update \ |
| 859 | || FATAL "failed to run apt-get update" |
| 860 | dpkg -l $need_packages_lw &>/dev/null \ |
| 861 | || ! echo -e "Installing $need_packages_lw requires root privileges." \ |
| 862 | || sudo apt-get install -y $need_packages_lw \ |
| 863 | || FATAL "failed to install $need_packages_lw" |
| 864 | fi |
| garciadeblas | fae5e97 | 2018-06-12 18:27:11 +0200 | [diff] [blame] | 865 | track prereqok |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 866 | [ -z "$INSTALL_NOJUJU" ] && install_juju |
| 867 | |
| 868 | if [ -z "$OSMLCM_VCA_HOST" ]; then |
| 869 | juju_createcontroller |
| 870 | OSMLCM_VCA_HOST=`sg lxd -c "juju show-controller $OSM_STACK_NAME"|grep api-endpoints|awk -F\' '{print $2}'|awk -F\: '{print $1}'` |
| 871 | [ -z "$OSMLCM_VCA_HOST" ] && FATAL "Cannot obtain juju controller IP address" |
| 872 | fi |
| 873 | if [ -z "$OSMLCM_VCA_SECRET" ]; then |
| 874 | OSMLCM_VCA_SECRET=$(parse_juju_password $OSM_STACK_NAME) |
| 875 | [ -z "$OSMLCM_VCA_SECRET" ] && FATAL "Cannot obtain juju secret" |
| 876 | fi |
| 877 | |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 878 | track juju |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 879 | [ -n "$INSTALL_NODOCKER" ] || install_docker_ce |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 880 | track docker_ce |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 881 | #install_docker_compose |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 882 | [ -z "$DOCKER_NOBUILD" ] && generate_docker_images |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 883 | track docker_build |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 884 | generate_docker_env_files |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 885 | generate_config_log_folders |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 886 | |
| 887 | [ -n "$INSTALL_NODOCKER" ] || init_docker_swarm |
| 888 | # remove old stack |
| 889 | remove_stack $OSM_STACK_NAME |
| 890 | create_docker_network |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 891 | deploy_lightweight |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 892 | generate_osmclient_script |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 893 | track docker_deploy |
| 894 | [ -n "$INSTALL_VIMEMU" ] && install_vimemu && track vimemu |
| 895 | [ -n "$INSTALL_ELK" ] && deploy_elk && track elk |
| 896 | [ -n "$INSTALL_PERFMON" ] && deploy_perfmon && track perfmon |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 897 | [ -z "$INSTALL_NOHOSTCLIENT" ] && install_osmclient |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 898 | track osmclient |
| 899 | wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null |
| 900 | track end |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 901 | return 0 |
| 902 | } |
| 903 | |
| 904 | function install_vimemu() { |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 905 | echo "\nInstalling vim-emu" |
| 906 | EMUTEMPDIR="$(mktemp -d -q --tmpdir "installosmvimemu.XXXXXX")" |
| 907 | trap 'rm -rf "${EMUTEMPDIR}"' EXIT |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 908 | # clone vim-emu repository (attention: branch is currently master only) |
| 909 | echo "Cloning vim-emu repository ..." |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 910 | git clone https://osm.etsi.org/gerrit/osm/vim-emu.git $EMUTEMPDIR |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 911 | # build vim-emu docker |
| 912 | echo "Building vim-emu Docker container..." |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 913 | |
| 914 | sg docker -c "docker build -t vim-emu-img -f $EMUTEMPDIR/Dockerfile --no-cache $EMUTEMPDIR/" || FATAL "cannot build vim-emu-img docker image" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 915 | # start vim-emu container as daemon |
| 916 | echo "Starting vim-emu Docker container 'vim-emu' ..." |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 917 | if [ -n "$INSTALL_LIGHTWEIGHT" ]; then |
| 918 | # in lightweight mode, the emulator needs to be attached to netOSM |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 919 | sg docker -c "docker run --name vim-emu -t -d --restart always --privileged --pid='host' --network=net${OSM_STACK_NAME} -v /var/run/docker.sock:/var/run/docker.sock vim-emu-img python examples/osm_default_daemon_topology_2_pop.py" |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 920 | else |
| 921 | # classic build mode |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 922 | sg docker -c "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" |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 923 | fi |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 924 | echo "Waiting for 'vim-emu' container to start ..." |
| 925 | sleep 5 |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 926 | export VIMEMU_HOSTNAME=$(sg docker -c "docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' vim-emu") |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 927 | echo "vim-emu running at ${VIMEMU_HOSTNAME} ..." |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 928 | # print vim-emu connection info |
| 929 | echo -e "\nYou might be interested in adding the following vim-emu env variables to your .bashrc file:" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 930 | echo " export VIMEMU_HOSTNAME=${VIMEMU_HOSTNAME}" |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 931 | echo -e "To add the emulated VIM to OSM you should do:" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 932 | echo " osm vim-create --name emu-vim1 --user username --password password --auth_url http://${VIMEMU_HOSTNAME}:6001/v2.0 --tenant tenantName --account_type openstack" |
| 933 | } |
| 934 | |
| 935 | function dump_vars(){ |
| 936 | echo "DEVELOP=$DEVELOP" |
| 937 | echo "INSTALL_FROM_SOURCE=$INSTALL_FROM_SOURCE" |
| 938 | echo "UNINSTALL=$UNINSTALL" |
| 939 | echo "NAT=$NAT" |
| 940 | echo "UPDATE=$UPDATE" |
| 941 | echo "RECONFIGURE=$RECONFIGURE" |
| 942 | echo "TEST_INSTALLER=$TEST_INSTALLER" |
| 943 | echo "INSTALL_VIMEMU=$INSTALL_VIMEMU" |
| 944 | echo "INSTALL_LXD=$INSTALL_LXD" |
| 945 | echo "INSTALL_FROM_LXDIMAGES=$INSTALL_FROM_LXDIMAGES" |
| 946 | echo "LXD_REPOSITORY_BASE=$LXD_REPOSITORY_BASE" |
| 947 | echo "LXD_REPOSITORY_PATH=$LXD_REPOSITORY_PATH" |
| 948 | echo "INSTALL_LIGHTWEIGHT=$INSTALL_LIGHTWEIGHT" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 949 | echo "INSTALL_ONLY=$INSTALL_ONLY" |
| 950 | echo "INSTALL_ELK=$INSTALL_ELK" |
| 951 | echo "INSTALL_PERFMON=$INSTALL_PERFMON" |
| garciadeblas | 0e596bc | 2018-05-28 16:04:42 +0200 | [diff] [blame] | 952 | echo "TO_REBUILD=$TO_REBUILD" |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 953 | echo "INSTALL_NOLXD=$INSTALL_NOLXD" |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 954 | echo "INSTALL_NODOCKER=$INSTALL_NODOCKER" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 955 | echo "RELEASE=$RELEASE" |
| 956 | echo "REPOSITORY=$REPOSITORY" |
| 957 | echo "REPOSITORY_BASE=$REPOSITORY_BASE" |
| 958 | echo "REPOSITORY_KEY=$REPOSITORY_KEY" |
| 959 | echo "NOCONFIGURE=$NOCONFIGURE" |
| 960 | echo "SHOWOPTS=$SHOWOPTS" |
| 961 | echo "Install from specific refspec (-b): $COMMIT_ID" |
| 962 | } |
| 963 | |
| 964 | function track(){ |
| 965 | ctime=`date +%s` |
| 966 | duration=$((ctime - SESSION_ID)) |
| 967 | url="http://www.woopra.com/track/ce?project=osm.etsi.org&cookie=${SESSION_ID}" |
| 968 | #url="${url}&ce_campaign_name=${CAMPAIGN_NAME}" |
| 969 | event_name="bin" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 970 | [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_SOURCE" ] && event_name="binsrc" |
| 971 | [ -z "$INSTALL_LIGHTWEIGHT" ] && [ -n "$INSTALL_FROM_LXDIMAGES" ] && event_name="lxd" |
| 972 | [ -n "$INSTALL_LIGHTWEIGHT" ] && event_name="lw" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 973 | event_name="${event_name}_$1" |
| 974 | url="${url}&event=${event_name}&ce_duration=${duration}" |
| 975 | wget -q -O /dev/null $url |
| 976 | } |
| 977 | |
| 978 | UNINSTALL="" |
| 979 | DEVELOP="" |
| 980 | NAT="" |
| 981 | UPDATE="" |
| 982 | RECONFIGURE="" |
| 983 | TEST_INSTALLER="" |
| 984 | INSTALL_LXD="" |
| 985 | SHOWOPTS="" |
| 986 | COMMIT_ID="" |
| 987 | ASSUME_YES="" |
| 988 | INSTALL_FROM_SOURCE="" |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 989 | RELEASE="ReleaseFOUR" |
| 990 | REPOSITORY="stable" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 991 | INSTALL_VIMEMU="" |
| 992 | INSTALL_FROM_LXDIMAGES="" |
| 993 | LXD_REPOSITORY_BASE="https://osm-download.etsi.org/repository/osm/lxd" |
| 994 | LXD_REPOSITORY_PATH="" |
| 995 | INSTALL_LIGHTWEIGHT="y" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 996 | INSTALL_ONLY="" |
| 997 | INSTALL_ELK="" |
| 998 | INSTALL_PERFMON="" |
| garciadeblas | 0e596bc | 2018-05-28 16:04:42 +0200 | [diff] [blame] | 999 | TO_REBUILD="" |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 1000 | INSTALL_NOLXD="" |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 1001 | INSTALL_NODOCKER="" |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 1002 | INSTALL_NOJUJU="" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1003 | NOCONFIGURE="" |
| 1004 | RELEASE_DAILY="" |
| 1005 | SESSION_ID=`date +%s` |
| 1006 | OSM_DEVOPS= |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 1007 | OSMLCM_VCA_HOST= |
| 1008 | OSMLCM_VCA_SECRET= |
| 1009 | OSM_STACK_NAME=osm |
| 1010 | NO_HOST_PORTS="" |
| 1011 | DOCKER_NOBUILD="" |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1012 | REPOSITORY_KEY="OSM%20ETSI%20Release%20Key.gpg" |
| 1013 | REPOSITORY_BASE="http://osm-download.etsi.org/repository/osm/debian" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1014 | |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 1015 | while getopts ":hy-:b:r:k:u:R:l:p:D:o:m:H:S:s:" o; do |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1016 | case "${o}" in |
| 1017 | h) |
| 1018 | usage && exit 0 |
| 1019 | ;; |
| 1020 | b) |
| 1021 | COMMIT_ID=${OPTARG} |
| 1022 | ;; |
| 1023 | r) |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1024 | REPOSITORY="${OPTARG}" |
| 1025 | REPO_ARGS+=(-r "$REPOSITORY") |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1026 | ;; |
| 1027 | R) |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1028 | RELEASE="${OPTARG}" |
| 1029 | REPO_ARGS+=(-R "$RELEASE") |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1030 | ;; |
| 1031 | k) |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1032 | REPOSITORY_KEY="${OPTARG}" |
| 1033 | REPO_ARGS+=(-k "$REPOSITORY_KEY") |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1034 | ;; |
| 1035 | u) |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1036 | REPOSITORY_BASE="${OPTARG}" |
| 1037 | REPO_ARGS+=(-u "$REPOSITORY_BASE") |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1038 | ;; |
| 1039 | l) |
| 1040 | LXD_REPOSITORY_BASE="${OPTARG}" |
| 1041 | ;; |
| 1042 | p) |
| 1043 | LXD_REPOSITORY_PATH="${OPTARG}" |
| 1044 | ;; |
| 1045 | D) |
| 1046 | OSM_DEVOPS="${OPTARG}" |
| 1047 | ;; |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 1048 | s) |
| 1049 | OSM_STACK_NAME="${OPTARG}" |
| 1050 | ;; |
| 1051 | H) |
| 1052 | OSMLCM_VCA_HOST="${OPTARG}" |
| 1053 | ;; |
| 1054 | S) |
| 1055 | OSMLCM_VCA_SECRET="${OPTARG}" |
| 1056 | ;; |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 1057 | o) |
| 1058 | INSTALL_ONLY="y" |
| 1059 | [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue |
| 1060 | [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue |
| 1061 | [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue |
| 1062 | ;; |
| garciadeblas | 0e596bc | 2018-05-28 16:04:42 +0200 | [diff] [blame] | 1063 | m) |
| 1064 | [ "${OPTARG}" == "RO" ] && TO_REBUILD="$TO_REBUILD RO" && continue |
| 1065 | [ "${OPTARG}" == "LCM" ] && TO_REBUILD="$TO_REBUILD LCM" && continue |
| 1066 | [ "${OPTARG}" == "NBI" ] && TO_REBUILD="$TO_REBUILD NBI" && continue |
| 1067 | [ "${OPTARG}" == "LW-UI" ] && TO_REBUILD="$TO_REBUILD LW-UI" && continue |
| 1068 | [ "${OPTARG}" == "MON" ] && TO_REBUILD="$TO_REBUILD MON" && continue |
| 1069 | [ "${OPTARG}" == "KAFKA" ] && TO_REBUILD="$TO_REBUILD KAFKA" && continue |
| 1070 | [ "${OPTARG}" == "MONGO" ] && TO_REBUILD="$TO_REBUILD MONGO" && continue |
| 1071 | [ "${OPTARG}" == "NONE" ] && TO_REBUILD="$TO_REBUILD NONE" && continue |
| 1072 | ;; |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1073 | -) |
| 1074 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| 1075 | [ "${OPTARG}" == "source" ] && INSTALL_FROM_SOURCE="y" && continue |
| 1076 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| 1077 | [ "${OPTARG}" == "uninstall" ] && UNINSTALL="y" && continue |
| 1078 | [ "${OPTARG}" == "nat" ] && NAT="y" && continue |
| 1079 | [ "${OPTARG}" == "update" ] && UPDATE="y" && continue |
| 1080 | [ "${OPTARG}" == "reconfigure" ] && RECONFIGURE="y" && continue |
| 1081 | [ "${OPTARG}" == "test" ] && TEST_INSTALLER="y" && continue |
| 1082 | [ "${OPTARG}" == "lxdinstall" ] && INSTALL_LXD="y" && continue |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 1083 | [ "${OPTARG}" == "nolxd" ] && INSTALL_NOLXD="y" && continue |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 1084 | [ "${OPTARG}" == "nodocker" ] && INSTALL_NODOCKER="y" && continue |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1085 | [ "${OPTARG}" == "lxdimages" ] && INSTALL_FROM_LXDIMAGES="y" && continue |
| 1086 | [ "${OPTARG}" == "lightweight" ] && INSTALL_LIGHTWEIGHT="y" && continue |
| garciadeblas | e990f66 | 2018-05-18 11:43:39 +0200 | [diff] [blame] | 1087 | [ "${OPTARG}" == "soui" ] && INSTALL_LIGHTWEIGHT="" && RELEASE="-R ReleaseTHREE" && REPOSITORY="-r stable" && continue |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1088 | [ "${OPTARG}" == "vimemu" ] && INSTALL_VIMEMU="y" && continue |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 1089 | [ "${OPTARG}" == "elk_stack" ] && INSTALL_ELK="y" && continue |
| 1090 | [ "${OPTARG}" == "pm_stack" ] && INSTALL_PERFMON="y" && continue |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1091 | [ "${OPTARG}" == "noconfigure" ] && NOCONFIGURE="y" && continue |
| 1092 | [ "${OPTARG}" == "showopts" ] && SHOWOPTS="y" && continue |
| 1093 | [ "${OPTARG}" == "daily" ] && RELEASE_DAILY="y" && continue |
| Mike Marchetti | 67411aa | 2018-09-13 11:38:38 -0400 | [diff] [blame] | 1094 | [ "${OPTARG}" == "nohostports" ] && NO_HOST_PORTS="y" && continue |
| 1095 | [ "${OPTARG}" == "nojuju" ] && INSTALL_NOJUJU="y" && continue |
| 1096 | [ "${OPTARG}" == "nodockerbuild" ] && DOCKER_NOBUILD="y" && continue |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1097 | [ "${OPTARG}" == "nohostclient" ] && INSTALL_NOHOSTCLIENT="y" && continue |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1098 | echo -e "Invalid option: '--$OPTARG'\n" >&2 |
| 1099 | usage && exit 1 |
| 1100 | ;; |
| 1101 | \?) |
| 1102 | echo -e "Invalid option: '-$OPTARG'\n" >&2 |
| 1103 | usage && exit 1 |
| 1104 | ;; |
| 1105 | y) |
| 1106 | ASSUME_YES="y" |
| 1107 | ;; |
| 1108 | *) |
| 1109 | usage && exit 1 |
| 1110 | ;; |
| 1111 | esac |
| 1112 | done |
| 1113 | |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 1114 | [ -n "$INSTALL_FROM_LXDIMAGES" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --lxd can only be used with --soui" |
| garciadeblas | e990f66 | 2018-05-18 11:43:39 +0200 | [diff] [blame] | 1115 | [ -n "$NAT" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --nat can only be used with --soui" |
| 1116 | [ -n "$NOCONFIGURE" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --noconfigure can only be used with --soui" |
| garciadeblas | fb56627 | 2018-05-25 10:33:36 +0200 | [diff] [blame] | 1117 | [ -n "$RELEASE_DAILY" ] && [ -n "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible options: --daily can only be used with --soui" |
| garciadeblas | d41f548 | 2018-05-25 10:25:06 +0200 | [diff] [blame] | 1118 | [ -n "$INSTALL_NOLXD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nolxd cannot be used with --soui" |
| garciadeblas | a3e2661 | 2018-05-30 17:58:55 +0200 | [diff] [blame] | 1119 | [ -n "$INSTALL_NODOCKER" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: --nodocker cannot be used with --soui" |
| garciadeblas | 0e596bc | 2018-05-28 16:04:42 +0200 | [diff] [blame] | 1120 | [ -n "$TO_REBUILD" ] && [ -z "$INSTALL_LIGHTWEIGHT" ] && FATAL "Incompatible option: -m cannot be used with --soui" |
| 1121 | [ -n "$TO_REBUILD" ] && [ "$TO_REBUILD" != " NONE" ] && echo $TO_REBUILD | grep -q NONE && FATAL "Incompatible option: -m NONE cannot be used with other -m options" |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 1122 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1123 | if [ -n "$SHOWOPTS" ]; then |
| 1124 | dump_vars |
| 1125 | exit 0 |
| 1126 | fi |
| 1127 | |
| 1128 | [ -n "$RELEASE_DAILY" ] && echo -e "\nInstalling from daily build repo" && RELEASE="-R ReleaseTHREE-daily" && REPOSITORY="-r testing" && COMMIT_ID="master" |
| 1129 | |
| 1130 | # if develop, we force master |
| 1131 | [ -z "$COMMIT_ID" ] && [ -n "$DEVELOP" ] && COMMIT_ID="master" |
| 1132 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1133 | need_packages="git jq wget curl tar" |
| 1134 | echo -e "Checking required packages: $need_packages" |
| 1135 | dpkg -l $need_packages &>/dev/null \ |
| 1136 | || ! echo -e "One or several required packages are not installed. Updating apt cache requires root privileges." \ |
| 1137 | || sudo apt-get update \ |
| 1138 | || FATAL "failed to run apt-get update" |
| 1139 | dpkg -l $need_packages &>/dev/null \ |
| 1140 | || ! echo -e "Installing $need_packages requires root privileges." \ |
| 1141 | || sudo apt-get install -y $need_packages \ |
| 1142 | || FATAL "failed to install $need_packages" |
| 1143 | |
| 1144 | if [ -z "$OSM_DEVOPS" ]; then |
| Michael Marchetti | ee37414 | 2018-08-02 22:47:16 +0200 | [diff] [blame] | 1145 | if [ -n "$TEST_INSTALLER" ]; then |
| 1146 | echo -e "\nUsing local devops repo for OSM installation" |
| 1147 | OSM_DEVOPS="$(dirname $(realpath $(dirname $0)))" |
| 1148 | else |
| 1149 | echo -e "\nCreating temporary dir for OSM installation" |
| 1150 | OSM_DEVOPS="$(mktemp -d -q --tmpdir "installosm.XXXXXX")" |
| 1151 | trap 'rm -rf "$OSM_DEVOPS"' EXIT |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1152 | |
| Michael Marchetti | ee37414 | 2018-08-02 22:47:16 +0200 | [diff] [blame] | 1153 | git clone https://osm.etsi.org/gerrit/osm/devops.git $OSM_DEVOPS |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1154 | |
| Michael Marchetti | ee37414 | 2018-08-02 22:47:16 +0200 | [diff] [blame] | 1155 | if [ -z "$COMMIT_ID" ]; then |
| 1156 | echo -e "\nGuessing the current stable release" |
| 1157 | LATEST_STABLE_DEVOPS=`git -C $OSM_DEVOPS tag -l v[0-9].* | sort -V | tail -n1` |
| 1158 | [ -z "$LATEST_STABLE_DEVOPS" ] && echo "Could not find the current latest stable release" && exit 0 |
| 1159 | |
| 1160 | echo "Latest tag in devops repo: $LATEST_STABLE_DEVOPS" |
| 1161 | COMMIT_ID="tags/$LATEST_STABLE_DEVOPS" |
| 1162 | else |
| 1163 | echo -e "\nDEVOPS Using commit $COMMIT_ID" |
| 1164 | fi |
| 1165 | git -C $OSM_DEVOPS checkout $COMMIT_ID |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1166 | fi |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1167 | fi |
| 1168 | |
| 1169 | OSM_JENKINS="$OSM_DEVOPS/jenkins" |
| 1170 | . $OSM_JENKINS/common/all_funcs |
| 1171 | |
| 1172 | [ -n "$INSTALL_LIGHTWEIGHT" ] && [ -n "$UNINSTALL" ] && uninstall_lightweight && echo -e "\nDONE" && exit 0 |
| 1173 | [ -n "$UNINSTALL" ] && uninstall && echo -e "\nDONE" && exit 0 |
| 1174 | [ -n "$NAT" ] && nat && echo -e "\nDONE" && exit 0 |
| 1175 | [ -n "$UPDATE" ] && update && echo -e "\nDONE" && exit 0 |
| 1176 | [ -n "$RECONFIGURE" ] && configure && echo -e "\nDONE" && exit 0 |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 1177 | [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_ELK" ] && deploy_elk |
| 1178 | [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_PERFMON" ] && deploy_perfmon |
| 1179 | [ -n "$INSTALL_ONLY" ] && [ -n "$INSTALL_VIMEMU" ] && install_vimemu |
| 1180 | [ -n "$INSTALL_ONLY" ] && echo -e "\nDONE" && exit 0 |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1181 | |
| 1182 | #Installation starts here |
| garciadeblas | 6c66abf | 2018-05-16 14:46:19 +0200 | [diff] [blame] | 1183 | wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README.txt &> /dev/null |
| 1184 | track start |
| 1185 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1186 | [ -n "$INSTALL_LIGHTWEIGHT" ] && install_lightweight && echo -e "\nDONE" && exit 0 |
| 1187 | echo -e "\nInstalling OSM from refspec: $COMMIT_ID" |
| 1188 | if [ -n "$INSTALL_FROM_SOURCE" ] && [ -z "$ASSUME_YES" ]; then |
| 1189 | ! ask_user "The installation will take about 75-90 minutes. Continue (Y/n)? " y && echo "Cancelled!" && exit 1 |
| 1190 | fi |
| 1191 | |
| 1192 | echo -e "Checking required packages: lxd" |
| 1193 | lxd --version &>/dev/null || FATAL "lxd not present, exiting." |
| 1194 | [ -n "$INSTALL_LXD" ] && echo -e "\nInstalling and configuring lxd" && install_lxd |
| 1195 | |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1196 | # use local devops for containers |
| 1197 | export OSM_USE_LOCAL_DEVOPS=true |
| 1198 | if [ -n "$INSTALL_FROM_SOURCE" ]; then #install from source |
| 1199 | echo -e "\nCreating the containers and building from source ..." |
| 1200 | $OSM_DEVOPS/jenkins/host/start_build RO --notest checkout $COMMIT_ID || FATAL "RO container build failed (refspec: '$COMMIT_ID')" |
| 1201 | ro_is_up && track RO |
| 1202 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA container build failed" |
| 1203 | vca_is_up && track VCA |
| 1204 | $OSM_DEVOPS/jenkins/host/start_build MON || FATAL "MON install failed" |
| 1205 | mon_is_up && track MON |
| 1206 | $OSM_DEVOPS/jenkins/host/start_build SO checkout $COMMIT_ID || FATAL "SO container build failed (refspec: '$COMMIT_ID')" |
| 1207 | $OSM_DEVOPS/jenkins/host/start_build UI checkout $COMMIT_ID || FATAL "UI container build failed (refspec: '$COMMIT_ID')" |
| 1208 | #so_is_up && track SOUI |
| 1209 | track SOUI |
| 1210 | elif [ -n "$INSTALL_FROM_LXDIMAGES" ]; then #install from LXD images stored in OSM repo |
| 1211 | echo -e "\nInstalling from lxd images ..." |
| 1212 | install_from_lxdimages |
| 1213 | else #install from binaries |
| 1214 | echo -e "\nCreating the containers and installing from binaries ..." |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1215 | $OSM_DEVOPS/jenkins/host/install RO ${REPO_ARGS[@]} || FATAL "RO install failed" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1216 | ro_is_up && track RO |
| 1217 | $OSM_DEVOPS/jenkins/host/start_build VCA || FATAL "VCA install failed" |
| 1218 | vca_is_up && track VCA |
| 1219 | $OSM_DEVOPS/jenkins/host/install MON || FATAL "MON build failed" |
| 1220 | mon_is_up && track MON |
| Mike Marchetti | 972947c | 2018-09-15 12:28:29 -0400 | [diff] [blame^] | 1221 | $OSM_DEVOPS/jenkins/host/install SO ${REPO_ARGS[@]} || FATAL "SO install failed" |
| 1222 | $OSM_DEVOPS/jenkins/host/install UI ${REPO_ARGS[@]} || FATAL "UI install failed" |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1223 | #so_is_up && track SOUI |
| 1224 | track SOUI |
| 1225 | fi |
| 1226 | |
| 1227 | #Install iptables-persistent and configure NAT rules |
| 1228 | [ -z "$NOCONFIGURE" ] && nat |
| 1229 | |
| 1230 | #Configure components |
| 1231 | [ -z "$NOCONFIGURE" ] && configure |
| 1232 | |
| 1233 | #Install osmclient |
| 1234 | [ -z "$NOCONFIGURE" ] && install_osmclient |
| 1235 | |
| 1236 | #Install vim-emu (optional) |
| peusterm | 76353e4 | 2018-05-08 13:56:05 +0200 | [diff] [blame] | 1237 | [ -n "$INSTALL_VIMEMU" ] && install_docker_ce && install_vimemu |
| garciadeblas | d8bc5c3 | 2018-05-09 17:37:56 +0200 | [diff] [blame] | 1238 | |
| 1239 | wget -q -O- https://osm-download.etsi.org/ftp/osm-4.0-four/README2.txt &> /dev/null |
| 1240 | track end |
| 1241 | echo -e "\nDONE" |
| 1242 | |