3 ##############################################################################
4 # Copyright (c) 2019 Nokia Corporation and others.
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
13 docker -v >/dev/null || {
14 echo "Fenix needs docker to be installed..."
15 ver=`grep "UBUNTU_CODENAME" /etc/os-release | cut -d '=' -f 2`
16 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
17 add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $ver stable"
18 apt install apt-transport-https ca-certificates curl software-properties-common
20 apt-cache policy docker-ce
21 apt-get install -y docker-ce docker-ce-cli containerd.io
22 dpkg -r --force-depends golang-docker-credential-helpers
25 docker ps | grep fenix -q && {
26 REMOTE=`git ls-remote https://opendev.org/x/fenix HEAD | awk '{ print $1}'`
27 LOCAL=`docker exec -t fenix git rev-parse @`
28 if [[ "$LOCAL" =~ "$REMOTE" ]]; then
29 # Difference in above string ending marks, so cannot compare equal
30 echo "Fenix start: Already running latest $LOCAL equals $REMOTE"
33 echo "Fenix container needs to be recreated $LOCAL not $REMOTE"
34 # Remove previous container
35 for img in `docker image list | grep "^fenix" | awk '{print $1}'`; do
36 for dock in `docker ps --all -f "ancestor=$img" | grep "$img" | awk '{print $1}'`; do
37 docker stop $dock; docker rm $dock;
42 } || echo "Fenix container needs to be created..."
44 cp /root/keystonercv3 .
46 transport=`grep -m1 "^transport" /etc/nova/nova.conf`
49 echo "[DEFAULT]" > fenix.conf
50 echo "port = 12347" >> fenix.conf
51 echo $transport >> fenix.conf
53 echo "[database]" >> fenix.conf
54 MYSQLIP=`grep -m1 "^connection" /etc/nova/nova.conf | sed -e "s/.*@//;s/\/.*//"`
55 echo "connection = mysql+pymysql://fenix:fenix@$MYSQLIP/fenix" >> fenix.conf
57 echo "[service_user]" >> fenix.conf
58 echo "os_auth_url = $OS_AUTH_URL" >> fenix.conf
59 echo "os_username = $OS_USERNAME" >> fenix.conf
60 echo "os_password = $OS_PASSWORD" >> fenix.conf
61 echo "os_user_domain_name = $OS_USER_DOMAIN_NAME" >> fenix.conf
62 echo "os_project_name = $OS_PROJECT_NAME" >> fenix.conf
63 echo "os_project_domain_name = $OS_PROJECT_DOMAIN_NAME" >> fenix.conf
65 echo "[DEFAULT]" > fenix-api.conf
66 echo "port = 12347" >> fenix-api.conf
67 echo $transport >> fenix-api.conf
69 echo "[keystone_authtoken]" >> fenix-api.conf
70 echo "auth_url = $OS_AUTH_URL" >> fenix-api.conf
71 echo "auth_type = password" >> fenix-api.conf
72 echo "project_domain_name = $OS_PROJECT_DOMAIN_NAME" >> fenix-api.conf
73 echo "project_name = $OS_PROJECT_NAME" >> fenix-api.conf
74 echo "user_domain_name = $OS_PROJECT_DOMAIN_NAME" >> fenix-api.conf
75 echo "password = $OS_PASSWORD" >> fenix-api.conf
76 echo "username = $OS_USERNAME" >> fenix-api.conf
77 echo "cafile = /opt/stack/data/ca-bundle.pem" >> fenix-api.conf
79 openstack service list | grep -q maintenance || {
80 openstack service create --name fenix --enable maintenance
81 openstack endpoint create --region $OS_REGION_NAME --enable fenix public http://localhost:12347/v1
85 # MYSQLPW=`cat /var/lib/config-data/mysql/etc/puppet/hieradata/service_configs.json | grep mysql | grep root_password | awk -F": " '{print $2}' | awk -F"\"" '{print $2}'`
89 [ `mysql -uroot -p$MYSQLPW -e "SELECT host, user FROM mysql.user;" | grep fenix | wc -l` -eq 0 ] && {
90 mysql -uroot -p$MYSQLPW -hlocalhost -e "CREATE USER 'fenix'@'localhost' IDENTIFIED BY 'fenix';"
91 mysql -uroot -p$MYSQLPW -hlocalhost -e "GRANT ALL PRIVILEGES ON fenix.* TO 'fenix'@'' identified by 'fenix';FLUSH PRIVILEGES;"
93 mysql -ufenix -pfenix -hlocalhost -e "DROP DATABASE IF EXISTS fenix;"
94 mysql -ufenix -pfenix -hlocalhost -e "CREATE DATABASE fenix CHARACTER SET utf8;"
96 # Build Fenix container and run it
98 docker build --build-arg OPENSTACK=master --build-arg BRANCH=master --network host $PWD -t fenix | tail -1
99 docker run --network host -d --name fenix -p 12347:12347 -ti fenix
100 if [ $? -eq 0 ]; then
101 echo "Fenix start: OK"
103 echo "Fenix start: FAILED"
105 # To debug check log from fenix container
106 # docker exec -ti fenix tail -f /var/log/fenix-engine.log