| Sean Dague | e263c82 | 2014-12-05 14:25:28 -0500 | [diff] [blame] | 1 | #!/bin/bash | 
|  | 2 | # | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 3 | # lib/horizon | 
|  | 4 | # Functions to control the configuration and operation of the horizon service | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 5 |  | 
|  | 6 | # Dependencies: | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 7 | # | 
|  | 8 | # - ``functions`` file | 
|  | 9 | # - ``apache`` file | 
|  | 10 | # - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 11 |  | 
|  | 12 | # ``stack.sh`` calls the entry points in this order: | 
|  | 13 | # | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 14 | # - install_horizon | 
|  | 15 | # - configure_horizon | 
|  | 16 | # - init_horizon | 
|  | 17 | # - start_horizon | 
|  | 18 | # - stop_horizon | 
|  | 19 | # - cleanup_horizon | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 20 |  | 
|  | 21 | # Save trace setting | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 22 | _XTRACE_HORIZON=$(set +o | grep xtrace) | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 23 | set +o xtrace | 
|  | 24 |  | 
|  | 25 |  | 
|  | 26 | # Defaults | 
|  | 27 | # -------- | 
|  | 28 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 29 | HORIZON_DIR=$DEST/horizon | 
|  | 30 |  | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 31 | # local_settings.py is used to customize Dashboard settings. | 
|  | 32 | # The example file in Horizon repo is used by default. | 
|  | 33 | HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example} | 
|  | 34 |  | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 35 | # Functions | 
|  | 36 | # --------- | 
|  | 37 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 38 | # utility method of setting python option | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 39 | function _horizon_config_set { | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 40 | local file=$1 | 
|  | 41 | local section=$2 | 
|  | 42 | local option=$3 | 
|  | 43 | local value=$4 | 
|  | 44 |  | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 45 | if [ -z "$section" ]; then | 
| Akihiro Motoki | deb3ff5 | 2019-07-24 17:08:44 +0900 | [diff] [blame] | 46 | sed -e "/^$option/d" -i $file | 
|  | 47 | echo "$option = $value" >> $file | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 48 | elif grep -q "^$section" $file; then | 
| Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 49 | local line | 
|  | 50 | line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 51 | if [ -n "$line" ]; then | 
|  | 52 | sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file | 
|  | 53 | else | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 54 | sed -i -e "/^$section/a\    '$option': $value," $file | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 55 | fi | 
|  | 56 | else | 
|  | 57 | echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file | 
|  | 58 | fi | 
|  | 59 | } | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 60 |  | 
| Ian Wienand | ad43b39 | 2013-04-11 11:13:09 +1000 | [diff] [blame] | 61 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 62 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 63 | # 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 Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 68 | function cleanup_horizon { | 
| Rob Crittenden | 5631ca5 | 2016-08-02 13:19:14 -0400 | [diff] [blame] | 69 | disable_apache_site horizon | 
|  | 70 | sudo rm -f $(apache_site_config_for horizon) | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
|  | 73 | # configure_horizon() - Set config files, create data dirs, etc | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 74 | function configure_horizon { | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 75 | setup_develop $HORIZON_DIR | 
| Akihiro Motoki | 6518c0b | 2014-10-15 17:26:59 +0900 | [diff] [blame] | 76 |  | 
|  | 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 Srinivas | 51ecf0a | 2017-01-05 16:11:17 -0500 | [diff] [blame] | 81 | (cd $HORIZON_DIR; $PYTHON manage.py compilemessages) | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 82 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 83 | # ``local_settings.py`` is used to override horizon default settings. | 
| Dean Troyer | 1bbfcc7 | 2014-07-25 12:50:14 -0500 | [diff] [blame] | 84 | local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 85 | cp $HORIZON_SETTINGS $local_settings | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 86 |  | 
| Akihiro Motoki | deb3ff5 | 2019-07-24 17:08:44 +0900 | [diff] [blame] | 87 | # Ensure local_setting.py file ends with EOL (newline) | 
|  | 88 | echo >> $local_settings | 
|  | 89 |  | 
| David Lyle | 7b105c5 | 2015-07-27 17:14:32 -0600 | [diff] [blame] | 90 | _horizon_config_set $local_settings "" WEBROOT \"$HORIZON_APACHE_ROOT/\" | 
| David Lyle | 7b105c5 | 2015-07-27 17:14:32 -0600 | [diff] [blame] | 91 |  | 
| David Lyle | 45ce982 | 2014-09-11 17:50:08 -0600 | [diff] [blame] | 92 | _horizon_config_set $local_settings "" COMPRESS_OFFLINE True | 
| Lance Bragstad | a7d0c6f | 2018-06-18 15:06:48 +0000 | [diff] [blame] | 93 | _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_DEFAULT_ROLE \"member\" | 
| David Lyle | 45ce982 | 2014-09-11 17:50:08 -0600 | [diff] [blame] | 94 |  | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 95 | _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\" | 
| Samuel de Medeiros Queiroz | 3fd71d6 | 2015-05-03 14:54:45 -0300 | [diff] [blame] | 96 |  | 
| Brant Knudson | e86b91b | 2016-05-03 15:21:47 -0500 | [diff] [blame] | 97 | _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_URI}/v3\"" | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 98 |  | 
| Tomasz Trębski | 868a663 | 2016-11-14 09:10:57 +0100 | [diff] [blame] | 99 | # 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 Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 104 | if [ -f $SSL_BUNDLE_FILE ]; then | 
|  | 105 | _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\" | 
|  | 106 | fi | 
|  | 107 |  | 
| Leticia Wanderley | cc36397 | 2017-06-26 23:52:52 -0300 | [diff] [blame] | 108 | if is_service_enabled ldap; then | 
|  | 109 | _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT "True" | 
|  | 110 | fi | 
|  | 111 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 112 | # Create an empty directory that apache uses as docroot | 
|  | 113 | sudo mkdir -p $HORIZON_DIR/.blackhole | 
|  | 114 |  | 
| Ian Wienand | ada886d | 2015-10-07 14:06:26 +1100 | [diff] [blame] | 115 | local horizon_conf | 
|  | 116 | horizon_conf=$(apache_site_config_for horizon) | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 117 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 118 | # Configure apache to run horizon | 
| Akihiro Motoki | 43f62c0 | 2015-12-15 16:44:41 +0900 | [diff] [blame] | 119 | # Set up the django horizon application to serve via apache/wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 120 | sudo sh -c "sed -e \" | 
|  | 121 | s,%USER%,$APACHE_USER,g; | 
|  | 122 | s,%GROUP%,$APACHE_GROUP,g; | 
|  | 123 | s,%HORIZON_DIR%,$HORIZON_DIR,g; | 
|  | 124 | s,%APACHE_NAME%,$APACHE_NAME,g; | 
|  | 125 | s,%DEST%,$DEST,g; | 
| David Lyle | 7b105c5 | 2015-07-27 17:14:32 -0600 | [diff] [blame] | 126 | s,%WEBROOT%,$HORIZON_APACHE_ROOT,g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 127 | \" $FILES/apache-horizon.template >$horizon_conf" | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 128 |  | 
|  | 129 | if is_ubuntu; then | 
|  | 130 | disable_apache_site 000-default | 
|  | 131 | sudo touch $horizon_conf | 
| Dan Kolb | 5c4691a | 2016-11-16 13:47:49 -0600 | [diff] [blame] | 132 | elif is_fedora || is_suse; then | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 133 | : # nothing to do | 
|  | 134 | else | 
|  | 135 | exit_distro_not_supported "horizon apache configuration" | 
|  | 136 | fi | 
|  | 137 | enable_apache_site horizon | 
| Akihiro Motoki | 43f62c0 | 2015-12-15 16:44:41 +0900 | [diff] [blame] | 138 | } | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 139 |  | 
| Akihiro Motoki | 43f62c0 | 2015-12-15 16:44:41 +0900 | [diff] [blame] | 140 | # init_horizon() - Initialize databases, etc. | 
|  | 141 | function init_horizon { | 
| Dean Troyer | dc97cb7 | 2015-03-28 08:20:50 -0500 | [diff] [blame] | 142 | # Remove old log files that could mess with how DevStack detects whether Horizon | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 143 | # has been successfully started (see start_horizon() and functions::screen_it()) | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 144 | # and run_process | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 145 | sudo rm -f /var/log/$APACHE_NAME/horizon_* | 
|  | 146 |  | 
| Mikhail S Medvedev | 088e660 | 2014-11-18 12:11:26 -0600 | [diff] [blame] | 147 | # Setup alias for django-admin which could be different depending on distro | 
|  | 148 | local django_admin | 
|  | 149 | if type -p django-admin > /dev/null; then | 
|  | 150 | django_admin=django-admin | 
|  | 151 | else | 
|  | 152 | django_admin=django-admin.py | 
|  | 153 | fi | 
|  | 154 |  | 
| Akihiro Motoki | 43f62c0 | 2015-12-15 16:44:41 +0900 | [diff] [blame] | 155 | # These need to be run after horizon plugins are configured. | 
| Mikhail S Medvedev | 088e660 | 2014-11-18 12:11:26 -0600 | [diff] [blame] | 156 | DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin collectstatic --noinput | 
|  | 157 | DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin compress --force | 
| David Lyle | 45ce982 | 2014-09-11 17:50:08 -0600 | [diff] [blame] | 158 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 159 | } | 
|  | 160 |  | 
|  | 161 | # install_horizon() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 162 | function install_horizon { | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 163 | # Apache installation, because we mark it NOPRIME | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 164 | install_apache_wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 165 |  | 
| Sean Dague | 5375329 | 2014-12-04 19:38:15 -0500 | [diff] [blame] | 166 | git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
| Sean Dague | 0eebeb4 | 2017-08-30 14:16:58 -0400 | [diff] [blame] | 169 | # start_horizon() - Start running processes | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 170 | function start_horizon { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 171 | restart_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 172 | } | 
|  | 173 |  | 
| Sean Dague | 0eebeb4 | 2017-08-30 14:16:58 -0400 | [diff] [blame] | 174 | # stop_horizon() - Stop running processes | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 175 | function stop_horizon { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 176 | stop_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 177 | } | 
|  | 178 |  | 
|  | 179 | # Restore xtrace | 
| Ian Wienand | 523f488 | 2015-10-13 11:03:03 +1100 | [diff] [blame] | 180 | $_XTRACE_HORIZON | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 181 |  | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 182 | # Tell emacs to use shell-script-mode | 
|  | 183 | ## Local variables: | 
|  | 184 | ## mode: shell-script | 
|  | 185 | ## End: |