-
Notifications
You must be signed in to change notification settings - Fork 6
/
setup-controller.sh
executable file
·4995 lines (4449 loc) · 189 KB
/
setup-controller.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
##
## Setup the OpenStack controller node.
##
set -x
DIRNAME=`dirname $0`
# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
echo "This script must be run as root" 1>&2
exit 1
fi
# Grab our libs
. "$DIRNAME/setup-lib.sh"
if [ "$HOSTNAME" != "$CONTROLLER" ]; then
exit 0;
fi
logtstart "controller"
if [ -f $SETTINGS ]; then
. $SETTINGS
fi
#
# openstack CLI commands seem flakey sometimes on Kilo and Liberty.
# Don't know if it's WSGI, mysql dropping connections, an NTP
# thing... but until it gets solved more permanently, have to retry :(.
#
__openstack() {
__err=1
__debug=
__times=0
while [ $__times -lt 16 -a ! $__err -eq 0 ]; do
openstack $__debug "$@"
__err=$?
if [ $__err -eq 0 ]; then
break
fi
__debug=" --debug "
__times=`expr $__times + 1`
if [ $__times -gt 1 ]; then
echo "ERROR: openstack command failed: sleeping and trying again!"
sleep 8
fi
done
}
#
# We're going to spin off our image downloader/configurator to better
# parallelize. So make sure it has the packages it needs.
#
maybe_install_packages qemu-utils wget lockfile-progs rpm
if [ "$ARCH" = "aarch64" ]; then
# need growpart
maybe_install_packages cloud-guest-utils
fi
maybe_install_packages pssh
PSSH='/usr/bin/parallel-ssh -t 0 -O StrictHostKeyChecking=no '
PSCP='/usr/bin/parallel-scp -t 0 -O StrictHostKeyChecking=no '
# Make sure our repos are setup.
#apt-get install ubuntu-cloud-keyring
#echo "deb http://ubuntu-cloud.archive.canonical.com/ubuntu" \
# "trusty-updates/juno main" > /etc/apt/sources.list.d/cloudarchive-juno.list
#sudo add-apt-repository ppa:ubuntu-cloud-archive/juno-staging
#
# Setup mail to users
#
maybe_install_packages dma
maybe_install_packages mailutils
echo "$PFQDN" > /etc/mailname
sleep 2
echo "Your OpenStack instance is setting up on `hostname` ." \
| mail -s "OpenStack Instance Setting Up" ${SWAPPER_EMAIL} &
#
# Fire off the image downloader/configurator in the background.
#
$DIRNAME/setup-images.sh >> $OURDIR/setup-images.log 2>&1 &
#
# If we're >= Kilo, we might need the openstack CLI command.
#
if [ $OSVERSION -ge $OSKILO ]; then
maybe_install_packages ${PYPKGPREFIX}-openstackclient
fi
#
# This is a nasty bug in oslo_service; see
# https://review.openstack.org/#/c/256267/
#
if [ $OSVERSION -ge $OSKILO -a $OSVERSION -lt $OSNEWTON ]; then
maybe_install_packages ${PYPKGPREFIX}-oslo.service
patch -d / -p0 < $DIRNAME/etc/oslo_service-liberty-sig-MAINLOOP.patch
fi
#
# Install the database
#
if [ -z "${DB_ROOT_PASS}" ]; then
logtstart "database"
maybe_install_packages mariadb-server $DBDPACKAGE
service_stop mysql
# Change the root password; secure the users/dbs.
mysqld_safe --skip-grant-tables --skip-networking &
sleep 8
DB_ROOT_PASS=`$PSWDGEN`
# This does what mysql_secure_installation does on Ubuntu
echo "use mysql; update user set password=PASSWORD(\"${DB_ROOT_PASS}\") where User='root'; delete from user where User=''; delete from user where User='root' and Host not in ('localhost', '127.0.0.1', '::1'); drop database test; delete from db where Db='test' or Db='test\\_%'; flush privileges;" | mysql -u root
# Shutdown our unprotected server
mysqladmin --password=${DB_ROOT_PASS} shutdown
# Put it on the management network and set recommended settings
echo "[mysqld]" >> /etc/mysql/my.cnf
echo "bind-address = $MGMTIP" >> /etc/mysql/my.cnf
echo "default-storage-engine = innodb" >> /etc/mysql/my.cnf
echo "innodb_file_per_table" >> /etc/mysql/my.cnf
echo "collation-server = utf8_general_ci" >> /etc/mysql/my.cnf
echo "init-connect = 'SET NAMES utf8'" >> /etc/mysql/my.cnf
echo "character-set-server = utf8" >> /etc/mysql/my.cnf
echo "max_connections = 4096" >> /etc/mysql/my.cnf
# Restart it!
service_restart mysql
service_enable mysql
# Save the passwd
echo "DB_ROOT_PASS=\"${DB_ROOT_PASS}\"" >> $SETTINGS
if [ -z "${MGMTLAN}" -a $OSVERSION -ge $OSLIBERTY ]; then
# Make sure mysqld won't start until after the openvpn
# mgmt net is up.
cat <<EOF >/etc/init.d/legacy-openvpn-net-waiter
#!/bin/bash
#
### BEGIN INIT INFO
# Provides: legacy-openvpn-net-waiter
# Required-Start: \$network openvpn
# Required-Stop:
# Should-Start: \$network openvpn
# X-Start-Before: mysql
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Waits for an IP address to appear on the mgmt net device.
# Description: Waits for an IP address to appear on the mgmt net device.
### END INIT INFO
#
. /lib/lsb/init-functions
case "\${1:-''}" in
'start')
while [ 1 -eq 1 ]; do
ip addr show | grep -q "$MGMTIP"
if [ \$? -eq 0 ]; then
log_daemon_msg "Found net device with ip addr $MGMTIP; allowing services to start" "openvpn"
break
else
sleep 1
fi
done
;;
'stop')
exit 0
;;
'restart')
exit 0
;;
*)
exit 1
;;
esac
exit 0
EOF
chmod 755 /etc/init.d/legacy-openvpn-net-waiter
#sed -i -e 's/^# Required-Start:\(.*\)$/# Required-Start:\1 mgmt-net-waiter/' /etc/init.d/mysql
#sed -i -e 's/^# Should-Start:\(.*\)$/# Should-Start:\1 mgmt-net-waiter/' /etc/init.d/mysql
update-rc.d legacy-openvpn-net-waiter defaults
update-rc.d legacy-openvpn-net-waiter enable
#update-rc.d mysql enable
fi
logtend "database"
fi
#
# Install a message broker
#
if [ -z "${RABBIT_PASS}" ]; then
logtstart "rabbit"
maybe_install_packages rabbitmq-server
service_restart rabbitmq-server
service_enable rabbitmq-server
rabbitmqctl start_app
while [ ! $? -eq 0 ]; do
sleep 1
rabbitmqctl start_app
done
if [ $OSVERSION -lt $OSNEWTON ]; then
cat <<EOF > /etc/rabbitmq/rabbitmq.config
[
{rabbit,
[
{loopback_users, []}
]}
]
.
EOF
fi
if [ ${OSCODENAME} = "juno" ]; then
RABBIT_USER="guest"
else
RABBIT_USER="openstack"
rabbitmqctl add_vhost /
fi
RABBIT_PASS=`$PSWDGEN`
RABBIT_URL="rabbit://${RABBIT_USER}:${RABBIT_PASS}@${CONTROLLER}"
rabbitmqctl change_password $RABBIT_USER $RABBIT_PASS
if [ ! $? -eq 0 ]; then
rabbitmqctl add_user ${RABBIT_USER} ${RABBIT_PASS}
rabbitmqctl set_permissions ${RABBIT_USER} ".*" ".*" ".*"
fi
# Save the passwd
echo "RABBIT_USER=\"${RABBIT_USER}\"" >> $SETTINGS
echo "RABBIT_PASS=\"${RABBIT_PASS}\"" >> $SETTINGS
echo "RABBIT_URL=\"${RABBIT_URL}\"" >> $SETTINGS
rabbitmqctl stop_app
service_restart rabbitmq-server
rabbitmqctl start_app
while [ ! $? -eq 0 ]; do
sleep 1
rabbitmqctl start_app
done
if [ -z "${MGMTLAN}" -a $OSVERSION -ge $OSLIBERTY ]; then
# Make sure rabbitmq won't start until after the openvpn
# mgmt net is up.
cat <<EOF >/etc/systemd/system/openvpn-net-waiter.service
[Unit]
Description=OpenVPN Device Waiter
After=network.target network-online.target local-fs.target
Wants=network.target
Before=rabbitmq-server.service
Requires=rabbitmq-server.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/init.d/legacy-openvpn-net-waiter start
StandardOutput=journal+console
StandardError=journal+console
[Install]
WantedBy=multi-user.target
EOF
systemctl enable openvpn-net-waiter.service
fi
logtend "rabbit"
fi
#
# If Keystone API Version v3, we have to supply a --domain sometimes.
#
DOMARG=""
#if [ $OSVERSION -gt $OSKILO ]; then
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
DOMARG="--domain default"
fi
#
# Always install memcache now.
#
if [ -z "${MEMCACHE_DONE}" ]; then
logtstart "memcache"
maybe_install_packages memcached ${PYPKGPREFIX}-memcache
# Ensure memcached also listens on private controller network
cat <<EOF >> /etc/memcached.conf
-l ${MGMTIP}
EOF
if [ ${HAVE_SYSTEMD} -eq 1 ]; then
mkdir /etc/systemd/system/memcached.service.d
systemctl list-units | grep -q networking\.service
if [ $? -eq 0 ]; then
cat <<EOF >/etc/systemd/system/memcached.service.d/local-ifup.conf
[Unit]
Requires=networking.service
After=networking.service
EOF
else
systemctl list-units | grep -q network-online\.target
if [ $? -eq 0 ]; then
cat <<EOF >/etc/systemd/system/memcached.service.d/local-ifup.conf
[Unit]
Requires=network-online.target
After=network-online.target
EOF
fi
fi
fi
service_restart memcached
service_enable memcached
echo "MEMCACHE_DONE=1" >> $SETTINGS
logtend "memcache"
fi
if [ $OSVERSION -ge $OSROCKY -a -z "${ETCD_DONE}" ]; then
logtstart "etcd"
if [ $ARCH = "aarch64" ]; then
#
# We need to set a particular env var for unsupported
# architectures, BEFORE we install. Otherwise apt-get will
# return error.
#
mkdir -p /etc/systemd/system/etcd.service.d
cat <<EOF >/etc/systemd/system/etcd.service.d/local.conf
[Service]
Environment=ETCD_UNSUPPORTED_ARCH=arm64
EOF
fi
maybe_install_packages etcd etcd-server etcd-client
if [ $OSVERSION -le $OSQUEENS ]; then
mkdir -p /etc/etcd
cat <<EOF >> /etc/etcd/etcd.conf.yaml
name: ${CONTROLLER}
data-dir: /var/lib/etcd
initial-cluster-state: 'new'
initial-cluster-token: 'etcd-cluster-01'
initial-cluster: ${CONTROLLER}=http:/:2380
initial-advertise-peer-urls: http://${MGMTIP}:2380
advertise-client-urls: http://${MGMTIP}:2379
listen-peer-urls: http://0.0.0.0:2380
listen-client-urls: http://${MGMTIP}:2379
EOF
chown -R etcd:etcd /etc/etcd
chmod 750 /etc/etcd
else
cat <<EOF >/etc/default/etcd
ETCD_NAME="$CONTROLLER"
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER="${CONTROLLER}=http://${MGMTIP}:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${MGMTIP}:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://${MGMTIP}:2379"
ETCD_LISTEN_PEER_URLS="http://${MGMTIP}:2380"
ETCD_LISTEN_CLIENT_URLS="http://${MGMTIP}:2379"
EOF
fi
service_enable etcd
service_restart etcd
echo "ETCD_DONE=1" >> $SETTINGS
logtend "etcd"
fi
#
# Install the Identity Service
#
if [ -z "${KEYSTONE_DBPASS}" ]; then
logtstart "keystone"
KEYSTONE_DBPASS=`$PSWDGEN`
echo "create database keystone" | mysql -u root --password="$DB_ROOT_PASS"
echo "grant all privileges on keystone.* to 'keystone'@'localhost' identified by '$KEYSTONE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
echo "grant all privileges on keystone.* to 'keystone'@'%' identified by '$KEYSTONE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
maybe_install_packages keystone ${PYPKGPREFIX}-keystoneclient
if [ $OSVERSION -ge $OSKILO -o $KEYSTONEUSEWSGI -eq 1 ]; then
maybe_install_packages apache2
if [ $ISPYTHON3 -eq 1 ]; then
maybe_install_packages libapache2-mod-wsgi-py3
else
maybe_install_packages libapache2-mod-wsgi
fi
a2enmod wsgi
fi
ADMIN_TOKEN=`$PSWDGEN`
crudini --set /etc/keystone/keystone.conf DEFAULT admin_token "$ADMIN_TOKEN"
crudini --set /etc/keystone/keystone.conf database connection \
"${DBDSTRING}://keystone:${KEYSTONE_DBPASS}@$CONTROLLER/keystone"
crudini --set /etc/keystone/keystone.conf token expiration ${TOKENTIMEOUT}
if [ $OSVERSION -le $OSJUNO ]; then
crudini --set /etc/keystone/keystone.conf token provider \
'keystone.token.providers.uuid.Provider'
crudini --set /etc/keystone/keystone.conf token driver \
'keystone.token.persistence.backends.sql.Token'
elif [ $OSVERSION -le $OSKILO ]; then
crudini --set /etc/keystone/keystone.conf token provider \
'keystone.token.providers.uuid.Provider'
crudini --set /etc/keystone/keystone.conf revoke driver \
'keystone.contrib.revoke.backends.sql.Revoke'
if [ $KEYSTONEUSEMEMCACHE -eq 1 ]; then
crudini --set /etc/keystone/keystone.conf token driver \
'keystone.token.persistence.backends.memcache.Token'
crudini --set /etc/keystone/keystone.conf memcache servers \
'127.0.0.1:11211'
else
crudini --set /etc/keystone/keystone.conf token driver \
'keystone.token.persistence.backends.sql.Token'
fi
else
if [ $OSVERSION -le $OSMITAKA ]; then
crudini --set /etc/keystone/keystone.conf token provider 'uuid'
crudini --set /etc/keystone/keystone.conf revoke driver 'sql'
else
crudini --set /etc/keystone/keystone.conf token provider fernet
fi
if [ $KEYSTONEUSEMEMCACHE -eq 1 ]; then
if [ $OSVERSION -lt $OSQUEENS ]; then
crudini --set /etc/keystone/keystone.conf token driver 'memcache'
fi
if [ $OSVERSION -lt $OSSTEIN ]; then
crudini --set /etc/keystone/keystone.conf cache \
backend dogpile.cache.memcached
crudini --set /etc/keystone/keystone.conf cache \
backend_argument url:127.0.0.1:11211
fi
crudini --set /etc/keystone/keystone.conf cache \
enable true
crudini --set /etc/keystone/keystone.conf cache \
enabled true
crudini --set /etc/keystone/keystone.conf cache \
memcache_servers 127.0.0.1:11211
crudini --set /etc/keystone/keystone.conf cache \
memcached_servers 127.0.0.1:11211
crudini --set /etc/keystone/keystone.conf memcache servers \
'127.0.0.1:11211'
else
crudini --set /etc/keystone/keystone.conf token driver 'sql'
fi
fi
crudini --set /etc/keystone/keystone.conf DEFAULT verbose ${VERBOSE_LOGGING}
crudini --set /etc/keystone/keystone.conf DEFAULT debug ${DEBUG_LOGGING}
su -s /bin/sh -c "/usr/bin/keystone-manage db_sync" keystone
if [ $OSVERSION -ge $OSNEWTON ]; then
keystone-manage fernet_setup --keystone-user keystone \
--keystone-group keystone
keystone-manage credential_setup --keystone-user keystone \
--keystone-group keystone
fi
if [ $OSVERSION -eq $OSKILO -a $KEYSTONEUSEWSGI -eq 1 ]; then
cat <<EOF >/etc/apache2/sites-available/wsgi-keystone.conf
Listen 5000
Listen 35357
<VirtualHost *:5000>
WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-public
WSGIScriptAlias / /var/www/cgi-bin/keystone/main
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
<IfVersion >= 2.4>
ErrorLogFormat "%{cu}t %M"
</IfVersion>
LogLevel info
ErrorLog /var/log/apache2/keystone-error.log
CustomLog /var/log/apache2/keystone-access.log combined
</VirtualHost>
<VirtualHost *:35357>
WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-admin
WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
<IfVersion >= 2.4>
ErrorLogFormat "%{cu}t %M"
</IfVersion>
LogLevel info
ErrorLog /var/log/apache2/keystone-error.log
CustomLog /var/log/apache2/keystone-access.log combined
</VirtualHost>
EOF
ln -s /etc/apache2/sites-available/wsgi-keystone.conf \
/etc/apache2/sites-enabled
mkdir -p /var/www/cgi-bin/keystone
wget -O /var/www/cgi-bin/keystone/admin "http://git.openstack.org/cgit/openstack/keystone/plain/httpd/keystone.py?h=stable/${OSCODENAME}"
if [ ! $? -eq 0 ]; then
# Try the EOL version...
wget -O /var/www/cgi-bin/keystone/admin "http://git.openstack.org/cgit/openstack/keystone/plain/httpd/keystone.py?h=${OSCODENAME}-eol"
fi
cp -p /var/www/cgi-bin/keystone/admin /var/www/cgi-bin/keystone/main
chown -R keystone:keystone /var/www/cgi-bin/keystone
chmod 755 /var/www/cgi-bin/keystone/*
elif [ $OSVERSION -ge $OSLIBERTY -a $KEYSTONEUSEWSGI -eq 1 \
-a $OSVERSION -lt $OSNEWTON ]; then
cat <<EOF >/etc/apache2/sites-available/wsgi-keystone.conf
Listen 5000
Listen 35357
<VirtualHost *:5000>
WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-public
WSGIScriptAlias / /usr/bin/keystone-wsgi-public
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
<IfVersion >= 2.4>
ErrorLogFormat "%{cu}t %M"
</IfVersion>
ErrorLog /var/log/apache2/keystone.log
CustomLog /var/log/apache2/keystone_access.log combined
<Directory /usr/bin>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
</Directory>
</VirtualHost>
<VirtualHost *:35357>
WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
WSGIProcessGroup keystone-admin
WSGIScriptAlias / /usr/bin/keystone-wsgi-admin
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
<IfVersion >= 2.4>
ErrorLogFormat "%{cu}t %M"
</IfVersion>
ErrorLog /var/log/apache2/keystone.log
CustomLog /var/log/apache2/keystone_access.log combined
<Directory /usr/bin>
<IfVersion >= 2.4>
Require all granted
</IfVersion>
<IfVersion < 2.4>
Order allow,deny
Allow from all
</IfVersion>
</Directory>
</VirtualHost>
EOF
ln -s /etc/apache2/sites-available/wsgi-keystone.conf \
/etc/apache2/sites-enabled
else
# Make sure various symlinks for keystone/wsgi are in place.
if [ ! -e /etc/apache2/sites-enabled/keystone.conf -a \
-e /etc/apache2/sites-available/keystone.conf ]; then
ln -s /etc/apache2/sites-available/keystone.conf \
/etc/apache2/sites-enabled/
fi
if [ ! -e /etc/apache2/mods-enabled/wsgi.conf -a \
-e /etc/apache2/mods-available/wsgi.conf ]; then
ln -s /etc/apache2/mods-available/wsgi.conf \
/etc/apache2/mods-enabled/
fi
if [ ! -e /etc/apache2/mods-enabled/wsgi.load -a \
-e /etc/apache2/mods-available/wsgi.load ]; then
ln -s /etc/apache2/mods-available/wsgi.load \
/etc/apache2/mods-enabled/
fi
a2ensite keystone
fi
if [ $OSVERSION -le $OSJUNO -o $KEYSTONEUSEWSGI -eq 0 ]; then
service_restart keystone
service_enable keystone
else
service_stop keystone
service_disable keystone
service_restart apache2
service_enable apache2
fi
rm -f /var/lib/keystone/keystone.db
sleep 8
# optional of course
(crontab -l -u keystone 2>&1 | grep -q token_flush) || \
echo '@hourly /usr/bin/keystone-manage token_flush >/var/log/keystone/keystone-tokenflush.log 2>&1' \
>> /var/spool/cron/crontabs/keystone
# Create admin token
if [ $OSVERSION -lt $OSKILO ]; then
export OS_SERVICE_TOKEN=$ADMIN_TOKEN
export OS_SERVICE_ENDPOINT=http://$CONTROLLER:${KADMINPORT}/$KAPISTR
else
export OS_TOKEN=$ADMIN_TOKEN
export OS_URL=http://$CONTROLLER:${KADMINPORT}/$KAPISTR
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
export OS_IDENTITY_API_VERSION=3
else
export OS_IDENTITY_API_VERSION=2.0
fi
fi
if [ $OSVERSION -lt $OSKILO ]; then
# Create the service tenant:
keystone tenant-create --name service --description "Service Tenant"
# Create the service entity for the Identity service:
keystone service-create --name keystone --type identity \
--description "OpenStack Identity Service"
# Create the API endpoint for the Identity service:
keystone endpoint-create \
--service-id `keystone service-list | awk '/ identity / {print $2}'` \
--publicurl http://$CONTROLLER:5000/v2.0 \
--internalurl http://$CONTROLLER:5000/v2.0 \
--adminurl http://$CONTROLLER:${KADMINPORT}/v2.0 \
--region $REGION
else
__openstack service create \
--name keystone --description "OpenStack Identity" identity
if [ $KEYSTONEAPIVERSION -lt 3 ]; then
__openstack endpoint create \
--publicurl http://${CONTROLLER}:5000/${KAPISTR} \
--internalurl http://${CONTROLLER}:5000/${KAPISTR} \
--adminurl http://${CONTROLLER}:${KADMINPORT}/${KAPISTR} \
--region $REGION identity
else
__openstack endpoint create --region $REGION \
identity public http://${CONTROLLER}:5000/${KAPISTR}
__openstack endpoint create --region $REGION \
identity internal http://${CONTROLLER}:5000/${KAPISTR}
__openstack endpoint create --region $REGION \
identity admin http://${CONTROLLER}:${KADMINPORT}/${KAPISTR}
fi
fi
if [ "x${ADMIN_PASS}" = "x" ]; then
# Create the admin user -- temporarily use the random one for
# ${ADMIN_API}; we change it right away below manually via sql
APSWD="${ADMIN_API_PASS}"
else
APSWD="${ADMIN_PASS}"
fi
if [ $OSVERSION -eq $OSJUNO ]; then
# Create the admin tenant
keystone tenant-create --name admin --description "Admin Tenant"
keystone user-create --name admin --pass "${APSWD}" \
--email "${SWAPPER_EMAIL}"
# Create the admin role
keystone role-create --name admin
# Add the admin tenant and user to the admin role:
keystone user-role-add --tenant admin --user admin --role admin
# Create the _member_ role:
keystone role-create --name _member_
# Add the admin tenant and user to the _member_ role:
keystone user-role-add --tenant admin --user admin --role _member_
# Create the adminapi user
keystone user-create --name ${ADMIN_API} --pass ${ADMIN_API_PASS} \
--email "${SWAPPER_EMAIL}"
keystone user-role-add --tenant admin --user ${ADMIN_API} --role admin
keystone user-role-add --tenant admin --user ${ADMIN_API} --role _member_
else
if [ $OSVERSION -ge $OSMITAKA ]; then
openstack domain create --description "Default Domain" default
fi
__openstack project create $DOMARG --description "Admin Project" admin
__openstack user create $DOMARG --password "${APSWD}" \
--email "${SWAPPER_EMAIL}" admin
__openstack role create admin
__openstack role add --project admin --user admin admin
__openstack role create user
__openstack role add --project admin --user admin user
__openstack project create $DOMARG --description "Service Project" service
# Create the adminapi user
__openstack user create $DOMARG --password ${ADMIN_API_PASS} \
--email "${SWAPPER_EMAIL}" ${ADMIN_API}
__openstack role add --project admin --user ${ADMIN_API} admin
__openstack role add --project admin --user ${ADMIN_API} user
fi
if [ "x${ADMIN_PASS}" = "x" ]; then
#
# Update the admin user with the passwd hash from our config
#
echo "update user set password='${ADMIN_PASS_HASH}' where name='admin'" \
| mysql -u root --password=${DB_ROOT_PASS} keystone
fi
if [ $OSVERSION -lt $OSKILO ]; then
unset OS_SERVICE_TOKEN OS_SERVICE_ENDPOINT
else
unset OS_TOKEN OS_URL
unset OS_IDENTITY_API_VERSION
fi
crudini --del /etc/keystone/keystone.conf DEFAULT admin_token
# Save the passwd
echo "ADMIN_API=\"${ADMIN_API}\"" >> $SETTINGS
echo "ADMIN_API_PASS=\"${ADMIN_API_PASS}\"" >> $SETTINGS
echo "KEYSTONE_DBPASS=\"${KEYSTONE_DBPASS}\"" >> $SETTINGS
logtend "keystone"
fi
#
# Create the admin-openrc.{sh,py} files.
#
echo "export OS_TENANT_NAME=admin" > $OURDIR/admin-openrc-oldcli.sh
echo "export OS_USERNAME=${ADMIN_API}" >> $OURDIR/admin-openrc-oldcli.sh
echo "export OS_PASSWORD=${ADMIN_API_PASS}" >> $OURDIR/admin-openrc-oldcli.sh
echo "export OS_AUTH_URL=http://$CONTROLLER:${KADMINPORT}/v2.0" >> $OURDIR/admin-openrc-oldcli.sh
echo "OS_TENANT_NAME=\"admin\"" > $OURDIR/admin-openrc-oldcli.py
echo "OS_USERNAME=\"${ADMIN_API}\"" >> $OURDIR/admin-openrc-oldcli.py
echo "OS_PASSWORD=\"${ADMIN_API_PASS}\"" >> $OURDIR/admin-openrc-oldcli.py
echo "OS_AUTH_URL=\"http://$CONTROLLER:${KADMINPORT}/v2.0\"" >> $OURDIR/admin-openrc-oldcli.py
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
echo "OS_IDENTITY_API_VERSION=3" >> $OURDIR/admin-openrc-oldcli.py
else
echo "OS_IDENTITY_API_VERSION=2.0" >> $OURDIR/admin-openrc-oldcli.py
fi
#
# These trigger a bug with the openstack client -- it doesn't choose v2.0
# if they're set.
#
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
if [ $OSVERSION -lt $OSMITAKA ]; then
echo "export OS_PROJECT_DOMAIN_ID=default" > $OURDIR/admin-openrc-newcli.sh
echo "export OS_USER_DOMAIN_ID=default" >> $OURDIR/admin-openrc-newcli.sh
else
echo "export OS_PROJECT_DOMAIN_NAME=default" > $OURDIR/admin-openrc-newcli.sh
echo "export OS_USER_DOMAIN_NAME=default" >> $OURDIR/admin-openrc-newcli.sh
fi
fi
echo "export OS_PROJECT_NAME=admin" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_TENANT_NAME=admin" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_USERNAME=${ADMIN_API}" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_PASSWORD=${ADMIN_API_PASS}" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_AUTH_URL=http://$CONTROLLER:${KADMINPORT}/${KAPISTR}" >> $OURDIR/admin-openrc-newcli.sh
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
echo "export OS_IDENTITY_API_VERSION=3" >> $OURDIR/admin-openrc-newcli.sh
else
echo "export OS_IDENTITY_API_VERSION=2.0" >> $OURDIR/admin-openrc-newcli.sh
fi
if [ $OSVERSION -ge $OSNEWTON ]; then
echo "export OS_IMAGE_API_VERSION=2" >> $OURDIR/admin-openrc-newcli.sh
fi
if [ $OSVERSION -ge $OSQUEENS ]; then
echo "export OS_AUTH_TYPE=password" >> $OURDIR/admin-openrc-newcli.sh
fi
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
if [ $OSVERSION -lt $OSMITAKA ]; then
echo "OS_PROJECT_DOMAIN_ID=\"default\"" > $OURDIR/admin-openrc-newcli.py
echo "OS_USER_DOMAIN_ID=\"default\"" >> $OURDIR/admin-openrc-newcli.py
else
echo "OS_PROJECT_DOMAIN_NAME=\"default\"" > $OURDIR/admin-openrc-newcli.py
echo "OS_USER_DOMAIN_NAME=\"default\"" >> $OURDIR/admin-openrc-newcli.py
fi
fi
echo "OS_PROJECT_NAME=\"admin\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_TENANT_NAME=\"admin\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_USERNAME=\"${ADMIN_API}\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_PASSWORD=\"${ADMIN_API_PASS}\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_AUTH_URL=\"http://$CONTROLLER:${KADMINPORT}/${KAPISTR}\"" >> $OURDIR/admin-openrc-newcli.py
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
echo "OS_IDENTITY_API_VERSION=3" >> $OURDIR/admin-openrc-newcli.py
else
echo "OS_IDENTITY_API_VERSION=2.0" >> $OURDIR/admin-openrc-newcli.py
fi
if [ $OSVERSION -ge $OSNEWTON ]; then
echo "OS_IMAGE_API_VERSION=2" >> $OURDIR/admin-openrc-newcli.py
fi
if [ $OSVERSION -ge $OSQUEENS ]; then
echo "OS_AUTH_TYPE='password'" >> $OURDIR/admin-openrc-newcli.py
fi
#
# From here on out, we need to be the adminapi user.
#
if [ $OSVERSION -eq $OSJUNO ]; then
export OS_TENANT_NAME=admin
export OS_USERNAME=${ADMIN_API}
export OS_PASSWORD=${ADMIN_API_PASS}
export OS_AUTH_URL=http://$CONTROLLER:${KADMINPORT}/${KAPISTR}
ln -sf $OURDIR/admin-openrc-oldcli.sh $OURDIR/admin-openrc.sh
ln -sf $OURDIR/admin-openrc-oldcli.py $OURDIR/admin-openrc.py
else
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
if [ $OSVERSION -lt $OSMITAKA ]; then
export OS_PROJECT_DOMAIN_ID=default
export OS_USER_DOMAIN_ID=default
else
export OS_PROJECT_DOMAIN_NAME=default
export OS_USER_DOMAIN_NAME=default
fi
fi
export OS_PROJECT_NAME=admin
export OS_TENANT_NAME=admin
export OS_USERNAME=${ADMIN_API}
export OS_PASSWORD=${ADMIN_API_PASS}
export OS_AUTH_URL=http://${CONTROLLER}:${KADMINPORT}/${KAPISTR}
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
export OS_IDENTITY_API_VERSION=3
else
export OS_IDENTITY_API_VERSION=2.0
fi
ln -sf $OURDIR/admin-openrc-newcli.sh $OURDIR/admin-openrc.sh
ln -sf $OURDIR/admin-openrc-newcli.py $OURDIR/admin-openrc.py
fi
#
# Install the Image service
#
if [ -z "${GLANCE_DBPASS}" ]; then
logtstart "glance"
GLANCE_DBPASS=`$PSWDGEN`
GLANCE_PASS=`$PSWDGEN`
echo "create database glance" | mysql -u root --password="$DB_ROOT_PASS"
echo "grant all privileges on glance.* to 'glance'@'localhost' identified by '$GLANCE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
echo "grant all privileges on glance.* to 'glance'@'%' identified by '$GLANCE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
if [ $OSVERSION -lt $OSKILO ]; then
keystone user-create --name glance --pass $GLANCE_PASS
keystone user-role-add --user glance --tenant service --role admin
keystone service-create --name glance --type image \
--description "OpenStack Image Service"
keystone endpoint-create \
--service-id `keystone service-list | awk '/ image / {print $2}'` \
--publicurl http://$CONTROLLER:9292 \
--internalurl http://$CONTROLLER:9292 \
--adminurl http://$CONTROLLER:9292 \
--region $REGION
else
__openstack user create $DOMARG --password $GLANCE_PASS glance
__openstack role add --user glance --project service admin
__openstack service create --name glance \
--description "OpenStack Image Service" image
if [ $KEYSTONEAPIVERSION -lt 3 ]; then
__openstack endpoint create \
--publicurl http://$CONTROLLER:9292 \
--internalurl http://$CONTROLLER:9292 \
--adminurl http://$CONTROLLER:9292 \
--region $REGION image
else
__openstack endpoint create --region $REGION \
image public http://$CONTROLLER:9292
__openstack endpoint create --region $REGION \
image internal http://$CONTROLLER:9292
__openstack endpoint create --region $REGION \
image admin http://$CONTROLLER:9292
fi
fi
maybe_install_packages glance ${PYPKGPREFIX}-glanceclient
crudini --set /etc/glance/glance-api.conf database connection \
"${DBDSTRING}://glance:${GLANCE_DBPASS}@$CONTROLLER/glance"
crudini --set /etc/glance/glance-api.conf DEFAULT auth_strategy keystone
crudini --set /etc/glance/glance-api.conf DEFAULT verbose ${VERBOSE_LOGGING}
crudini --set /etc/glance/glance-api.conf DEFAULT debug ${DEBUG_LOGGING}
crudini --set /etc/glance/glance-api.conf paste_deploy flavor keystone
if [ $OSVERSION -eq $OSJUNO ]; then
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
auth_uri http://${CONTROLLER}:5000/${KAPISTR}
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
identity_uri http://${CONTROLLER}:${KADMINPORT}
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
admin_tenant_name service
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
admin_user glance
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
admin_password "${GLANCE_PASS}"
else
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
${AUTH_URI_KEY} http://${CONTROLLER}:5000
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
auth_url http://${CONTROLLER}:${KADMINPORT}
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
${AUTH_TYPE_PARAM} password
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
${PROJECT_DOMAIN_PARAM} default
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
${USER_DOMAIN_PARAM} default
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
project_name service
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
username glance
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
password "${GLANCE_PASS}"
crudini --set /etc/glance/glance-api.conf glance_store default_store file
crudini --set /etc/glance/glance-api.conf glance_store \
filesystem_store_datadir /var/lib/glance/images/
#crudini --set /etc/glance/glance-api.conf DEFAULT notification_driver noop
if [ $OSVERSION -ge $OSNEWTON ]; then
crudini --set /etc/glance/glance-api.conf glance_store stores file,http
fi
fi
if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
crudini --set /etc/glance/glance-api.conf keystone_authtoken \
memcached_servers ${CONTROLLER}:11211
fi
if [ $OSVERSION -lt $OSSTEIN ]; then
crudini --set /etc/glance/glance-registry.conf database \
connection "${DBDSTRING}://glance:${GLANCE_DBPASS}@$CONTROLLER/glance"
crudini --set /etc/glance/glance-registry.conf DEFAULT auth_strategy keystone
crudini --set /etc/glance/glance-registry.conf DEFAULT verbose ${VERBOSE_LOGGING}
crudini --set /etc/glance/glance-registry.conf DEFAULT debug ${DEBUG_LOGGING}
crudini --set /etc/glance/glance-registry.conf paste_deploy flavor keystone
if [ $OSVERSION -eq $OSJUNO ]; then
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
auth_uri http://${CONTROLLER}:5000/${KAPISTR}
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
identity_uri http://${CONTROLLER}:${KADMINPORT}
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
admin_tenant_name service
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
admin_user glance
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
admin_password "${GLANCE_PASS}"
else
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
${AUTH_URI_KEY} http://${CONTROLLER}:5000
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
auth_url http://${CONTROLLER}:${KADMINPORT}
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
${AUTH_TYPE_PARAM} password
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
${PROJECT_DOMAIN_PARAM} default
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
${USER_DOMAIN_PARAM} default
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
project_name service
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
username glance
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
password "${GLANCE_PASS}"
#crudini --set /etc/glance/glance-registry.conf DEFAULT notification_driver noop
fi
if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
memcached_servers ${CONTROLLER}:11211
fi
fi
su -s /bin/sh -c "/usr/bin/glance-manage db_sync" glance
#
# Possibly create a larger image storage space.
#
if [ -n "$GLANCE_LV_SIZE" -a ! $GLANCE_LV_SIZE = 0 ]; then
if [ $OSVERSION -lt $OSSTEIN ]; then
service_stop glance-registry
fi
service_stop glance-api
$DIRNAME/setup-extra-space.sh
. $LOCALSETTINGS
mkdir -p ${STORAGEDIR}/glance
chown glance:glance ${STORAGEDIR}/glance
chmod 770 ${STORAGEDIR}/glance
if [ $LVM = 1 ]; then
lvcreate -L ${GLANCE_LV_SIZE}G -n glance $VGNAME
if [ -f /sbin/mkfs.ext4 ]; then