blob: 632c7ab767df38930e0fe49fc2229e3232ae471c [file] [log] [blame]
Sean Dagueb562e6a2012-11-19 16:00:01 -05001# lib/horizon
2# Functions to control the configuration and operation of the horizon service
Sean Dagueb562e6a2012-11-19 16:00:01 -05003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``apache`` file
8# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
Sean Dagueb562e6a2012-11-19 16:00:01 -05009
10# ``stack.sh`` calls the entry points in this order:
11#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010012# - install_horizon
13# - configure_horizon
14# - init_horizon
15# - start_horizon
16# - stop_horizon
17# - cleanup_horizon
Sean Dagueb562e6a2012-11-19 16:00:01 -050018
19# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
Sean Dagueb562e6a2012-11-19 16:00:01 -050027# Set up default directories
28HORIZON_DIR=$DEST/horizon
29
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090030# local_settings.py is used to customize Dashboard settings.
31# The example file in Horizon repo is used by default.
32HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
33
Dean Troyer4237f592014-01-29 16:22:11 -060034# Tell Tempest this project is present
35TEMPEST_SERVICES+=,horizon
36
Dean Troyercc6b4432013-04-08 15:38:03 -050037
38# Functions
39# ---------
40
Eugene Nikanorovb663b332013-03-07 16:10:10 +040041# utility method of setting python option
Ian Wienandaee18c72014-02-21 15:35:08 +110042function _horizon_config_set {
Eugene Nikanorovb663b332013-03-07 16:10:10 +040043 local file=$1
44 local section=$2
45 local option=$3
46 local value=$4
47
Rob Crittendenc31fa402014-03-17 00:07:52 -040048 if [ -z "$section" ]; then
49 sed -e "/^$option/d" -i $local_settings
50 echo -e "\n$option=$value" >> $file
51 elif grep -q "^$section" $file; then
Eugene Nikanorovb663b332013-03-07 16:10:10 +040052 line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
53 if [ -n "$line" ]; then
54 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
55 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070056 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040057 fi
58 else
59 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
60 fi
61}
Sean Dagueb562e6a2012-11-19 16:00:01 -050062
Ian Wienandad43b392013-04-11 11:13:09 +100063
Dean Troyer1a6d4492013-06-03 16:47:36 -050064
Sean Dagueb562e6a2012-11-19 16:00:01 -050065# Entry Points
66# ------------
67
68# cleanup_horizon() - Remove residual data files, anything left over from previous
69# runs that a clean run would need to clean up
Ian Wienandaee18c72014-02-21 15:35:08 +110070function cleanup_horizon {
Dean Troyer1a6d4492013-06-03 16:47:36 -050071 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
72 # If ``/usr/bin/node`` points into ``$DEST``
73 # we installed it via ``install_nodejs``
74 if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
75 sudo rm /usr/bin/node
76 fi
77 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -050078}
79
80# configure_horizon() - Set config files, create data dirs, etc
Ian Wienandaee18c72014-02-21 15:35:08 +110081function configure_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050082 setup_develop $HORIZON_DIR
83}
84
85# init_horizon() - Initialize databases, etc.
Ian Wienandaee18c72014-02-21 15:35:08 +110086function init_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -050087 # ``local_settings.py`` is used to override horizon default settings.
88 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090089 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050090
Edgar Maganac973f122013-07-29 16:39:56 -070091 if is_service_enabled neutron; then
92 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP
93 fi
Eugene Nikanorovb663b332013-03-07 16:10:10 +040094 # enable loadbalancer dashboard in case service is enabled
95 if is_service_enabled q-lbaas; then
Nobuto MURATA73a39bf2013-07-11 16:26:02 +090096 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True
Eugene Nikanorovb663b332013-03-07 16:10:10 +040097 fi
98
Ravi Chunduru95c93e22013-07-16 04:18:47 -070099 # enable firewall dashboard in case service is enabled
100 if is_service_enabled q-fwaas; then
101 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_firewall True
102 fi
103
Akihiro MOTOKIeaa9e1e2013-09-10 05:22:37 +0900104 # enable VPN dashboard in case service is enabled
105 if is_service_enabled q-vpn; then
106 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_vpn True
107 fi
108
Rob Crittendenc31fa402014-03-17 00:07:52 -0400109 _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\"
110 _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_PROTOCOL}://%s:${KEYSTONE_SERVICE_PORT}/v2.0\" % OPENSTACK_HOST"
111
112 if [ -f $SSL_BUNDLE_FILE ]; then
113 _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\"
114 fi
115
Sean Dagueb562e6a2012-11-19 16:00:01 -0500116 # Create an empty directory that apache uses as docroot
117 sudo mkdir -p $HORIZON_DIR/.blackhole
118
Chris Buccella610af8c2013-11-05 12:56:34 +0000119 # Apache 2.4 uses mod_authz_host for access control now (instead of "Allow")
Sunil Thaha627d9c72013-04-10 14:11:44 +1000120 HORIZON_REQUIRE=''
Chris Buccella610af8c2013-11-05 12:56:34 +0000121 if check_apache_version "2.4" ; then
122 HORIZON_REQUIRE='Require all granted'
123 fi
124
Gabriel Assis Bezerraa688bc62014-05-27 20:58:22 +0000125 local horizon_conf=$(apache_site_config_for horizon)
JordanP1e4587e2013-05-08 22:19:59 +0200126
Sean Dagueb562e6a2012-11-19 16:00:01 -0500127 # Configure apache to run horizon
128 sudo sh -c "sed -e \"
129 s,%USER%,$APACHE_USER,g;
130 s,%GROUP%,$APACHE_GROUP,g;
131 s,%HORIZON_DIR%,$HORIZON_DIR,g;
132 s,%APACHE_NAME%,$APACHE_NAME,g;
133 s,%DEST%,$DEST,g;
Sunil Thaha627d9c72013-04-10 14:11:44 +1000134 s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800135 \" $FILES/apache-horizon.template >$horizon_conf"
Attila Fazekasafda4ef2014-06-03 16:53:03 +0200136
137 if is_ubuntu; then
138 disable_apache_site 000-default
139 sudo touch $horizon_conf
140 elif is_fedora; then
141 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
142 elif is_suse; then
143 : # nothing to do
144 else
145 exit_distro_not_supported "horizon apache configuration"
146 fi
147 enable_apache_site horizon
148
149 # Remove old log files that could mess with how devstack detects whether Horizon
150 # has been successfully started (see start_horizon() and functions::screen_it())
151 sudo rm -f /var/log/$APACHE_NAME/horizon_*
152
Sean Dagueb562e6a2012-11-19 16:00:01 -0500153}
154
155# install_horizon() - Collect source and prepare
Ian Wienandaee18c72014-02-21 15:35:08 +1100156function install_horizon {
Sean Dagueb562e6a2012-11-19 16:00:01 -0500157 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800158 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500159
Sean Dagueb562e6a2012-11-19 16:00:01 -0500160 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
161}
162
163# start_horizon() - Start running processes, including screen
Ian Wienandaee18c72014-02-21 15:35:08 +1100164function start_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800165 restart_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500166 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
167}
168
169# stop_horizon() - Stop running processes (non-screen)
Ian Wienandaee18c72014-02-21 15:35:08 +1100170function stop_horizon {
zhang-hared98a5d02013-06-21 18:18:02 +0800171 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500172}
173
Dean Troyer1a6d4492013-06-03 16:47:36 -0500174
Sean Dagueb562e6a2012-11-19 16:00:01 -0500175# Restore xtrace
176$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400177
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100178# Tell emacs to use shell-script-mode
179## Local variables:
180## mode: shell-script
181## End: