Updates docs for SR1 with final revision
[genesis.git] / fuel / build / f_isoroot / f_bootstrap / bootstrap_admin_node.sh
1 #!/bin/bash
2 FUEL_RELEASE=$(grep release: /etc/fuel/version.yaml | cut -d: -f2 | tr -d '" ')
3
4 function countdown() {
5   local i
6   sleep 1
7   for ((i=$1-1; i>=1; i--)); do
8     printf '\b\b%02d' "$i"
9     sleep 1
10   done
11 }
12
13 function fail() {
14   echo "ERROR: Fuel node deployment FAILED! Check /var/log/puppet/bootstrap_admin_node.log for details" 1>&2
15   exit 1
16 }
17 # LANG variable is a workaround for puppet-3.4.2 bug. See LP#1312758 for details
18 export LANG=en_US.UTF8
19 showmenu="no"
20 if [ -f /root/.showfuelmenu ]; then
21   . /root/.showfuelmenu
22 fi
23
24 echo -n "Applying default Fuel settings..."
25 fuelmenu --save-only --iface=eth0
26 echo "Done!"
27
28 ### OPNFV addition BEGIN
29 shopt -s nullglob
30 for script in /opt/opnfv/bootstrap/pre.d/*.sh
31 do
32   echo "Pre script: $script" >> /root/pre.log 2>&1
33   $script >> /root/pre.log 2>&1
34 done
35 shopt -u nullglob
36 ### OPNFV addition END
37
38 if [[ "$showmenu" == "yes" || "$showmenu" == "YES" ]]; then
39   fuelmenu
40   else
41   #Give user 15 seconds to enter fuelmenu or else continue
42   echo
43   echo -n "Press a key to enter Fuel Setup (or press ESC to skip)... 15"
44   countdown 15 & pid=$!
45   if ! read -s -n 1 -t 15 key; then
46     echo -e "\nSkipping Fuel Setup..."
47   else
48     { kill "$pid"; wait $!; } 2>/dev/null
49     case "$key" in
50       $'\e')  echo "Skipping Fuel Setup.."
51               ;;
52       *)      echo -e "\nEntering Fuel Setup..."
53               fuelmenu
54               ;;
55     esac
56   fi
57 fi
58
59
60 #Reread /etc/sysconfig/network to inform puppet of changes
61 . /etc/sysconfig/network
62 hostname "$HOSTNAME"
63
64 service docker start
65
66 if [ -f /root/.build_images ]; then
67   #Fail on all errors
68   set -e
69   trap fail EXIT
70
71   echo "Loading Fuel base image for Docker..."
72   docker load -i /var/www/nailgun/docker/images/fuel-images.tar
73
74   echo "Building Fuel Docker images..."
75   WORKDIR=$(mktemp -d /tmp/docker-buildXXX)
76   SOURCE=/var/www/nailgun/docker
77   REPO_CONT_ID=$(docker -D run -d -p 80 -v /var/www/nailgun:/var/www/nailgun fuel/centos sh -c 'mkdir /var/www/html/os;ln -sf /var/www/nailgun/centos/x86_64 /var/www/html/os/x86_64;/usr/sbin/apachectl -DFOREGROUND')
78   RANDOM_PORT=$(docker port $REPO_CONT_ID 80 | cut -d':' -f2)
79
80   for imagesource in /var/www/nailgun/docker/sources/*; do
81     if ! [ -f "$imagesource/Dockerfile" ]; then
82       echo "Skipping ${imagesource}..."
83       continue
84     fi
85     image=$(basename "$imagesource")
86     cp -R "$imagesource" $WORKDIR/$image
87     mkdir -p $WORKDIR/$image/etc
88     cp -R /etc/puppet /etc/fuel $WORKDIR/$image/etc
89     sed -e "s/_PORT_/${RANDOM_PORT}/" -i $WORKDIR/$image/Dockerfile
90     sed -e 's/production:.*/production: "docker-build"/' -i $WORKDIR/$image/etc/fuel/version.yaml
91     docker build -t fuel/${image}_${FUEL_RELEASE} $WORKDIR/$image
92   done
93   docker rm -f $REPO_CONT_ID
94   rm -rf "$WORKDIR"
95
96   #Remove trap for normal deployment
97   trap - EXIT
98   set +e
99 else
100   echo "Loading docker images. (This may take a while)"
101   docker load -i /var/www/nailgun/docker/images/fuel-images.tar
102 fi
103
104 # apply puppet
105 puppet apply --detailed-exitcodes -d -v /etc/puppet/modules/nailgun/examples/host-only.pp
106 if [ $? -ge 4 ];then
107   fail
108 fi
109 rmdir /var/log/remote && ln -s /var/log/docker-logs/remote /var/log/remote
110
111 dockerctl check || fail
112 bash /etc/rc.local
113
114 ### OPNFV addition BEGIN
115 shopt -s nullglob
116 for script in /opt/opnfv/bootstrap/post.d/*.sh
117 do
118   echo "Post script: $script" >> /root/post.log 2>&1
119   $script >> /root/post.log 2>&1
120 done
121 shopt -u nullglob
122 ### OPNFV addition END
123
124 # Enable updates repository
125 cat > /etc/yum.repos.d/mos${FUEL_RELEASE}-updates.repo << EOF
126 [mos${FUEL_RELEASE}-updates]
127 name=mos${FUEL_RELEASE}-updates
128 baseurl=http://mirror.fuel-infra.org/mos/centos-6/mos${FUEL_RELEASE}/updates/
129 gpgcheck=0
130 skip_if_unavailable=1
131 EOF
132
133 # Enable security repository
134 cat > /etc/yum.repos.d/mos${FUEL_RELEASE}-security.repo << EOF
135 [mos${FUEL_RELEASE}-security]
136 name=mos${FUEL_RELEASE}-security
137 baseurl=http://mirror.fuel-infra.org/mos/centos-6/mos${FUEL_RELEASE}/security/
138 gpgcheck=0
139 skip_if_unavailable=1
140 EOF
141
142 #Check if repo is accessible
143 echo "Checking for access to updates repository..."
144 repourl=$(grep baseurl /etc/yum.repos.d/*updates* 2>/dev/null | cut -d'=' -f2- | head -1)
145 if urlaccesscheck check "$repourl" ; then
146   UPDATE_ISSUES=0
147 else
148   UPDATE_ISSUES=1
149 fi
150
151 if [ $UPDATE_ISSUES -eq 1 ]; then
152   warning="WARNING: There are issues connecting to Fuel update repository.\
153 \nPlease fix your connection and update this node with \`yum update\`\
154 \nThen run \`dockerctl destroy all; bootstrap_admin_node.sh;\`\
155 \nto repeat bootstrap on Fuel Master with the latest updates.\
156 \nFor more information, check out Fuel documentation at:\
157 \nhttp://docs.mirantis.com/fuel"
158 else
159   warning="WARNING: There may be updates available for Fuel.\
160 \nYou should update this node with \`yum update\`. If there are available\
161 \n updates, run \`dockerctl destroy all; bootstrap_admin_node.sh;\`\
162 \nto repeat bootstrap on Fuel Master with the latest updates.\
163 \nFor more information, check out Fuel documentation at:\
164 \nhttp://docs.mirantis.com/fuel"
165 fi
166 echo
167 echo "*************************************************"
168 echo -e "$warning"
169 echo "*************************************************"
170 echo "Sending notification to Fuel UI..."
171 fuel notify --topic warning --send "$warning"
172 echo "Fuel node deployment complete!"