summaryrefslogtreecommitdiff
path: root/openstack/usr/share/openstack/openstack-glance-setup
blob: 8a40de0258c39f73c6f5e249c984a9fc96f82672 (plain)
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
#!/bin/sh
#
# Copyright (C) 2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

set -e

# Create required system users and groups
getent group glance >/dev/null || groupadd -r --gid 164 glance
getent passwd glance >/dev/null || \
	useradd --uid 164 -r -g glance -d /var/lib/glance -s /sbin/nologin \
	-c "OpenStack Glance Daemons" glance

# Create required keystone tenants, users and roles
export OS_SERVICE_TOKEN=##KEYSTONE_TEMPORARY_ADMIN_TOKEN##
export OS_SERVICE_ENDPOINT='http://localhost:35357/v2.0'

keystone user-create --name ##GLANCE_SERVICE_USER## --pass ##GLANCE_SERVICE_PASSWORD##
keystone user-role-add --tenant service --user ##GLANCE_SERVICE_USER## --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 ##GLANCE_PUBLIC_URL## \
	                  --internalurl ##GLANCE_INTERNAL_URL## \
	                  --adminurl ##GLANCE_ADMIN_URL##

# Setup the glance database
if [ ! -e /var/lib/glance/glance.sqlite ]; then
    chown -R glance:glance /var/lib/glance
    chown -R glance:glance /var/log/glance
    sudo -u glance glance-manage db_sync
fi

# Remove the one-shot setup service
rm /etc/systemd/system/multi-user.target.wants/openstack-glance-setup.service

# Start glance services
systemctl start openstack-glance-api
systemctl start openstack-glance-registry

# Create the links to run glance services when system start next times.
ln -s "/etc/systemd/system/openstack-glance-api.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-glance-api.service"

ln -s "/etc/systemd/system/openstack-glance-registry.service" \
    "/etc/systemd/system/multi-user.target.wants/openstack-glance-registry.service"

exit 0