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