blob: 122d5166731769ed58678d375e5c5040e36a7ebd [file] [log] [blame]
Sean Daguee263c822014-12-05 14:25:28 -05001#!/bin/bash
2#
Sean Dagueb562e6a2012-11-19 16:00:01 -05003# lib/horizon
4# Functions to control the configuration and operation of the horizon service
Sean Dagueb562e6a2012-11-19 16:00:01 -05005
6# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01007#
8# - ``functions`` file
9# - ``apache`` file
10# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
Sean Dagueb562e6a2012-11-19 16:00:01 -050011
12# ``stack.sh`` calls the entry points in this order:
13#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010014# - install_horizon
15# - configure_horizon
16# - init_horizon
17# - start_horizon
18# - stop_horizon
19# - cleanup_horizon
Sean Dagueb562e6a2012-11-19 16:00:01 -050020
21# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
24
25
26# Defaults
27# --------
28
Sean Dagueb562e6a2012-11-19 16:00:01 -050029# Set up default directories
Sean Dague3c8973a2014-11-14 09:31:02 -050030GITDIR["django_openstack_auth"]=$DEST/django_openstack_auth
31
Sean Dagueb562e6a2012-11-19 16:00:01 -050032HORIZON_DIR=$DEST/horizon
33
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090034# local_settings.py is used to customize Dashboard settings.
35# The example file in Horizon repo is used by default.
36HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
37
Dean Troyer4237f592014-01-29 16:22:11 -060038# Tell Tempest this project is present
39TEMPEST_SERVICES+=,horizon
40
Dean Troyercc6b4432013-04-08 15:38:03 -050041
42# Functions
43# ---------
44
Eugene Nikanorovb663b332013-03-07 16:10:10 +040045# utility method of setting python option
Ian Wienandaee18c72014-02-21 15:35:08 +110046function _horizon_config_set {
Eugene Nikanorovb663b332013-03-07 16:10:10 +040047 local file=$1
48 local section=$2
49 local option=$3
50 local value=$4
51
Rob Crittendenc31fa402014-03-17 00:07:52 -040052 if [ -z "$section" ]; then
53 sed -e "/^$option/d" -i $local_settings
54 echo -e "\n$option=$value" >> $file
55 elif grep -q "^$section" $file; then
Dean Troyer1bbfcc72014-07-25 12:50:14 -050056 local line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
Eugene Nikanorovb663b332013-03-07 16:10:10 +040057 if [ -n "$line" ]; then
58 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
59 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070060 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040061 fi
62 else
63 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
64 fi
65}
Sean Dagueb562e6a2012-11-19 16:00:01 -050066
Ian Wienandad43b392013-04-11 11:13:09 +100067
Dean Troyer1a6d4492013-06-03 16:47:36 -050068
Sean Dagueb562e6a2012-11-19 16:00:01 -050069# Entry Points
70# ------------
71
72# cleanup_horizon() - Remove residual data files, anything left over from previous
73# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110074function cleanup_horizon {
Dean Troyer444a8d52014-06-06 16:36:52 -050075 local horizon_conf=$(apache_site_config_for horizon)
76 sudo rm -f $horizon_conf
Sean Dagueb562e6a2012-11-19 16:00:01 -050077}
78
79# configure_horizon() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110080function configure_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050081 setup_develop $HORIZON_DIR
Akihiro Motoki6518c0b2014-10-15 17:26:59 +090082
83 # Compile message catalogs.
84 # Horizon is installed as develop mode, so we can compile here.
85 # Message catalog compilation is handled by Django admin script,
86 # so compiling them after the installation avoids Django installation twice.
Sean Dague3c8973a2014-11-14 09:31:02 -050087 (cd $HORIZON_DIR; ./run_tests.sh -N --compilemessages)
Sean Dagueb562e6a2012-11-19 16:00:01 -050088}
89
90# init_horizon() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +110091function init_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050092 # ``local_settings.py`` is used to override horizon default settings.
Dean Troyer1bbfcc72014-07-25 12:50:14 -050093 local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090094 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050095
David Lyle45ce9822014-09-11 17:50:08 -060096 _horizon_config_set $local_settings "" COMPRESS_OFFLINE True
97
Rob Crittendenc31fa402014-03-17 00:07:52 -040098 _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\"
Haiwei Xu98a18172014-06-04 19:15:11 +090099 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_PROTOCOL}://${KEYSTONE_SERVICE_HOST}:${KEYSTONE_SERVICE_PORT}/v2.0\""
Rob Crittendenc31fa402014-03-17 00:07:52 -0400100
101 if [ -f $SSL_BUNDLE_FILE ]; then
102 _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\"
103 fi
104
Sean Dagueb562e6a2012-11-19 16:00:01 -0500105 # Create an empty directory that apache uses as docroot
106 sudo mkdir -p $HORIZON_DIR/.blackhole
107
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000108 local horizon_conf=$(apache_site_config_for horizon)
JordanP1e4587e2013-05-08 22:19:59 +0200109
Sean Dagueb562e6a2012-11-19 16:00:01 -0500110 # Configure apache to run horizon
111 sudo sh -c "sed -e \"
112 s,%USER%,$APACHE_USER,g;
113 s,%GROUP%,$APACHE_GROUP,g;
114 s,%HORIZON_DIR%,$HORIZON_DIR,g;
115 s,%APACHE_NAME%,$APACHE_NAME,g;
116 s,%DEST%,$DEST,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800117 \" $FILES/apache-horizon.template >$horizon_conf"
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200118
119 if is_ubuntu; then
120 disable_apache_site 000-default
121 sudo touch $horizon_conf
122 elif is_fedora; then
123 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
124 elif is_suse; then
125 : # nothing to do
126 else
127 exit_distro_not_supported "horizon apache configuration"
128 fi
129 enable_apache_site horizon
130
131 # Remove old log files that could mess with how devstack detects whether Horizon
132 # has been successfully started (see start_horizon() and functions::screen_it())
Chris Dent2f27a0e2014-09-09 13:46:02 +0100133 # and run_process
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200134 sudo rm -f /var/log/$APACHE_NAME/horizon_*
135
Mikhail S Medvedev088e6602014-11-18 12:11:26 -0600136 # Setup alias for django-admin which could be different depending on distro
137 local django_admin
138 if type -p django-admin > /dev/null; then
139 django_admin=django-admin
140 else
141 django_admin=django-admin.py
142 fi
143
144 DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin collectstatic --noinput
145 DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin compress --force
David Lyle45ce9822014-09-11 17:50:08 -0600146
Sean Dagueb562e6a2012-11-19 16:00:01 -0500147}
148
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800149# install_django_openstack_auth() - Collect source and prepare
150function install_django_openstack_auth {
Sean Dague3c8973a2014-11-14 09:31:02 -0500151 if use_library_from_git "django_openstack_auth"; then
152 local dir=${GITDIR["django_openstack_auth"]}
153 git_clone_by_name "django_openstack_auth"
154 # Compile message catalogs before installation
155 _prepare_message_catalog_compilation
156 (cd $dir; python setup.py compile_catalog)
157 setup_dev_lib "django_openstack_auth"
158 fi
159 # if we aren't using this library from git, then we just let it
160 # get dragged in by the horizon setup.
Zhenguo Niue385d1e2014-03-12 16:58:12 +0800161}
162
Sean Dagueb562e6a2012-11-19 16:00:01 -0500163# install_horizon() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100164function install_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -0500165 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800166 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500167
Sean Dague53753292014-12-04 19:38:15 -0500168 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH
Sean Dagueb562e6a2012-11-19 16:00:01 -0500169}
170
171# start_horizon() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100172function start_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800173 restart_apache_server
Chris Dent2f27a0e2014-09-09 13:46:02 +0100174 tail_log horizon /var/log/$APACHE_NAME/horizon_error.log
Sean Dagueb562e6a2012-11-19 16:00:01 -0500175}
176
177# stop_horizon() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100178function stop_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800179 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500180}
181
Akihiro Motoki6518c0b2014-10-15 17:26:59 +0900182# NOTE: It can be moved to common functions, but it is only used by compilation
183# of django_openstack_auth catalogs at the moment.
184function _prepare_message_catalog_compilation {
185 local babel_package=$(grep ^Babel $REQUIREMENTS_DIR/global-requirements.txt)
186 pip_install "$babel_package"
187}
188
Dean Troyer1a6d4492013-06-03 16:47:36 -0500189
Sean Dagueb562e6a2012-11-19 16:00:01 -0500190# Restore xtrace
191$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400192
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100193# Tell emacs to use shell-script-mode
194## Local variables:
195## mode: shell-script
196## End: