blob: 6f753f546f0bd37a591a2b7348b68c9d59a686e6 [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
Ian Wienand523f4882015-10-13 11:03:03 +110022_XTRACE_HORIZON=$(set +o | grep xtrace)
Sean Dagueb562e6a2012-11-19 16:00:01 -050023set +o xtrace
24
25
26# Defaults
27# --------
28
Sean Dagueb562e6a2012-11-19 16:00:01 -050029HORIZON_DIR=$DEST/horizon
30
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090031# local_settings.py is used to customize Dashboard settings.
32# The example file in Horizon repo is used by default.
33HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
34
Dean Troyercc6b4432013-04-08 15:38:03 -050035# Functions
36# ---------
37
Eugene Nikanorovb663b332013-03-07 16:10:10 +040038# utility method of setting python option
Ian Wienandaee18c72014-02-21 15:35:08 +110039function _horizon_config_set {
Eugene Nikanorovb663b332013-03-07 16:10:10 +040040 local file=$1
41 local section=$2
42 local option=$3
43 local value=$4
44
Rob Crittendenc31fa402014-03-17 00:07:52 -040045 if [ -z "$section" ]; then
Akihiro Motokideb3ff52019-07-24 17:08:44 +090046 sed -e "/^$option/d" -i $file
47 echo "$option = $value" >> $file
Rob Crittendenc31fa402014-03-17 00:07:52 -040048 elif grep -q "^$section" $file; then
Ian Wienandada886d2015-10-07 14:06:26 +110049 local line
50 line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
Eugene Nikanorovb663b332013-03-07 16:10:10 +040051 if [ -n "$line" ]; then
52 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
53 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070054 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040055 fi
56 else
57 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
58 fi
59}
Sean Dagueb562e6a2012-11-19 16:00:01 -050060
Ian Wienandad43b392013-04-11 11:13:09 +100061
Dean Troyer1a6d4492013-06-03 16:47:36 -050062
Sean Dagueb562e6a2012-11-19 16:00:01 -050063# Entry Points
64# ------------
65
66# cleanup_horizon() - Remove residual data files, anything left over from previous
67# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110068function cleanup_horizon {
Rob Crittenden5631ca52016-08-02 13:19:14 -040069 disable_apache_site horizon
70 sudo rm -f $(apache_site_config_for horizon)
Sean Dagueb562e6a2012-11-19 16:00:01 -050071}
72
73# configure_horizon() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110074function configure_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050075 setup_develop $HORIZON_DIR
Akihiro Motoki6518c0b2014-10-15 17:26:59 +090076
77 # Compile message catalogs.
78 # Horizon is installed as develop mode, so we can compile here.
79 # Message catalog compilation is handled by Django admin script,
80 # so compiling them after the installation avoids Django installation twice.
Davanum Srinivas51ecf0a2017-01-05 16:11:17 -050081 (cd $HORIZON_DIR; $PYTHON manage.py compilemessages)
Sean Dagueb562e6a2012-11-19 16:00:01 -050082
Sean Dagueb562e6a2012-11-19 16:00:01 -050083 # ``local_settings.py`` is used to override horizon default settings.
Dean Troyer1bbfcc72014-07-25 12:50:14 -050084 local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090085 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050086
Akihiro Motokideb3ff52019-07-24 17:08:44 +090087 # Ensure local_setting.py file ends with EOL (newline)
88 echo >> $local_settings
89
David Lyle7b105c52015-07-27 17:14:32 -060090 _horizon_config_set $local_settings "" WEBROOT \"$HORIZON_APACHE_ROOT/\"
David Lyle7b105c52015-07-27 17:14:32 -060091
David Lyle45ce9822014-09-11 17:50:08 -060092 _horizon_config_set $local_settings "" COMPRESS_OFFLINE True
Lance Bragstada7d0c6f2018-06-18 15:06:48 +000093 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_DEFAULT_ROLE \"member\"
David Lyle45ce9822014-09-11 17:50:08 -060094
Rob Crittendenc31fa402014-03-17 00:07:52 -040095 _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\"
Samuel de Medeiros Queiroz3fd71d62015-05-03 14:54:45 -030096
Brant Knudsone86b91b2016-05-03 15:21:47 -050097 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_URI}/v3\""
Rob Crittendenc31fa402014-03-17 00:07:52 -040098
Tomasz Trębski868a6632016-11-14 09:10:57 +010099 # note(trebskit): if HOST_IP points at non-localhost ip address, horizon cannot be accessed
100 # from outside the virtual machine. This fixes is meant primarily for local development
101 # purpose
102 _horizon_config_set $local_settings "" ALLOWED_HOSTS [\"*\"]
103
Rob Crittendenc31fa402014-03-17 00:07:52 -0400104 if [ -f $SSL_BUNDLE_FILE ]; then
105 _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\"
106 fi
107
Leticia Wanderleycc363972017-06-26 23:52:52 -0300108 if is_service_enabled ldap; then
109 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT "True"
110 fi
111
Sean Dagueb562e6a2012-11-19 16:00:01 -0500112 # Create an empty directory that apache uses as docroot
113 sudo mkdir -p $HORIZON_DIR/.blackhole
114
Ian Wienandada886d2015-10-07 14:06:26 +1100115 local horizon_conf
116 horizon_conf=$(apache_site_config_for horizon)
JordanP1e4587e2013-05-08 22:19:59 +0200117
Clark Boylana40f9cb2018-04-04 14:02:30 -0700118 local wsgi_venv_config=""
119 if [[ "$GLOBAL_VENV" == "True" ]] ; then
120 wsgi_venv_config="WSGIPythonHome $DEVSTACK_VENV"
121 fi
122
Sean Dagueb562e6a2012-11-19 16:00:01 -0500123 # Configure apache to run horizon
Akihiro Motoki43f62c02015-12-15 16:44:41 +0900124 # Set up the django horizon application to serve via apache/wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500125 sudo sh -c "sed -e \"
126 s,%USER%,$APACHE_USER,g;
127 s,%GROUP%,$APACHE_GROUP,g;
128 s,%HORIZON_DIR%,$HORIZON_DIR,g;
129 s,%APACHE_NAME%,$APACHE_NAME,g;
130 s,%DEST%,$DEST,g;
David Lyle7b105c52015-07-27 17:14:32 -0600131 s,%WEBROOT%,$HORIZON_APACHE_ROOT,g;
Clark Boylana40f9cb2018-04-04 14:02:30 -0700132 s,%WSGIPYTHONHOME%,$wsgi_venv_config,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800133 \" $FILES/apache-horizon.template >$horizon_conf"
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200134
135 if is_ubuntu; then
136 disable_apache_site 000-default
137 sudo touch $horizon_conf
Martin Kopecec07b342023-01-24 17:38:45 +0100138 elif is_fedora; then
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200139 : # nothing to do
140 else
141 exit_distro_not_supported "horizon apache configuration"
142 fi
143 enable_apache_site horizon
Akihiro Motoki43f62c02015-12-15 16:44:41 +0900144}
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200145
Akihiro Motoki43f62c02015-12-15 16:44:41 +0900146# init_horizon() - Initialize databases, etc.
147function init_horizon {
Dean Troyerdc97cb72015-03-28 08:20:50 -0500148 # Remove old log files that could mess with how DevStack detects whether Horizon
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200149 # has been successfully started (see start_horizon() and functions::screen_it())
Chris Dent2f27a0e2014-09-09 13:46:02 +0100150 # and run_process
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200151 sudo rm -f /var/log/$APACHE_NAME/horizon_*
152
Mikhail S Medvedev088e6602014-11-18 12:11:26 -0600153 # Setup alias for django-admin which could be different depending on distro
154 local django_admin
155 if type -p django-admin > /dev/null; then
156 django_admin=django-admin
157 else
158 django_admin=django-admin.py
159 fi
160
Akihiro Motoki43f62c02015-12-15 16:44:41 +0900161 # These need to be run after horizon plugins are configured.
Mikhail S Medvedev088e6602014-11-18 12:11:26 -0600162 DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin collectstatic --noinput
163 DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin compress --force
David Lyle45ce9822014-09-11 17:50:08 -0600164
Sean Dagueb562e6a2012-11-19 16:00:01 -0500165}
166
167# install_horizon() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100168function install_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -0500169 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800170 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500171
Takashi Kajinamid2acd602023-10-16 15:02:08 +0900172 # Install the memcache library so that horizon can use memcached as its
173 # cache backend
174 pip_install_gr pymemcache
175
Sean Dague53753292014-12-04 19:38:15 -0500176 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH
Sean Dagueb562e6a2012-11-19 16:00:01 -0500177}
178
Sean Dague0eebeb42017-08-30 14:16:58 -0400179# start_horizon() - Start running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100180function start_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800181 restart_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500182}
183
Sean Dague0eebeb42017-08-30 14:16:58 -0400184# stop_horizon() - Stop running processes
Ian Wienandaee18c72014-02-21 15:35:08 +1100185function stop_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800186 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500187}
188
189# Restore xtrace
Ian Wienand523f4882015-10-13 11:03:03 +1100190$_XTRACE_HORIZON
Sean Dague584d90e2013-03-29 14:34:53 -0400191
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100192# Tell emacs to use shell-script-mode
193## Local variables:
194## mode: shell-script
195## End: