| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 1 | # lib/horizon | 
 | 2 | # Functions to control the configuration and operation of the horizon service | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 3 |  | 
 | 4 | # Dependencies: | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 5 | # | 
 | 6 | # - ``functions`` file | 
 | 7 | # - ``apache`` file | 
 | 8 | # - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 9 |  | 
 | 10 | # ``stack.sh`` calls the entry points in this order: | 
 | 11 | # | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 12 | # - install_horizon | 
 | 13 | # - configure_horizon | 
 | 14 | # - init_horizon | 
 | 15 | # - start_horizon | 
 | 16 | # - stop_horizon | 
 | 17 | # - cleanup_horizon | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 18 |  | 
 | 19 | # Save trace setting | 
 | 20 | XTRACE=$(set +o | grep xtrace) | 
 | 21 | set +o xtrace | 
 | 22 |  | 
 | 23 |  | 
 | 24 | # Defaults | 
 | 25 | # -------- | 
 | 26 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 27 | # Set up default directories | 
| Sean Dague | 3c8973a | 2014-11-14 09:31:02 -0500 | [diff] [blame] | 28 | GITDIR["django_openstack_auth"]=$DEST/django_openstack_auth | 
 | 29 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 30 | HORIZON_DIR=$DEST/horizon | 
 | 31 |  | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 32 | # local_settings.py is used to customize Dashboard settings. | 
 | 33 | # The example file in Horizon repo is used by default. | 
 | 34 | HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example} | 
 | 35 |  | 
| Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 36 | # Tell Tempest this project is present | 
 | 37 | TEMPEST_SERVICES+=,horizon | 
 | 38 |  | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 39 |  | 
 | 40 | # Functions | 
 | 41 | # --------- | 
 | 42 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 43 | # utility method of setting python option | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 44 | function _horizon_config_set { | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 45 |     local file=$1 | 
 | 46 |     local section=$2 | 
 | 47 |     local option=$3 | 
 | 48 |     local value=$4 | 
 | 49 |  | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 50 |     if [ -z "$section" ]; then | 
 | 51 |         sed -e "/^$option/d" -i $local_settings | 
 | 52 |         echo -e "\n$option=$value" >> $file | 
 | 53 |     elif grep -q "^$section" $file; then | 
| Dean Troyer | 1bbfcc7 | 2014-07-25 12:50:14 -0500 | [diff] [blame] | 54 |         local line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 55 |         if [ -n "$line" ]; then | 
 | 56 |             sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file | 
 | 57 |         else | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 58 |             sed -i -e "/^$section/a\    '$option': $value," $file | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 59 |         fi | 
 | 60 |     else | 
 | 61 |         echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file | 
 | 62 |     fi | 
 | 63 | } | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 64 |  | 
| Ian Wienand | ad43b39 | 2013-04-11 11:13:09 +1000 | [diff] [blame] | 65 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 66 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 67 | # Entry Points | 
 | 68 | # ------------ | 
 | 69 |  | 
 | 70 | # cleanup_horizon() - Remove residual data files, anything left over from previous | 
 | 71 | # runs that a clean run would need to clean up | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 72 | function cleanup_horizon { | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 73 |     if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then | 
 | 74 |         # If ``/usr/bin/node`` points into ``$DEST`` | 
 | 75 |         # we installed it via ``install_nodejs`` | 
 | 76 |         if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then | 
 | 77 |             sudo rm /usr/bin/node | 
 | 78 |         fi | 
 | 79 |     fi | 
| Dean Troyer | 444a8d5 | 2014-06-06 16:36:52 -0500 | [diff] [blame] | 80 |  | 
 | 81 |     local horizon_conf=$(apache_site_config_for horizon) | 
 | 82 |     sudo rm -f $horizon_conf | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 83 | } | 
 | 84 |  | 
 | 85 | # configure_horizon() - Set config files, create data dirs, etc | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 86 | function configure_horizon { | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 87 |     setup_develop $HORIZON_DIR | 
| Akihiro Motoki | 6518c0b | 2014-10-15 17:26:59 +0900 | [diff] [blame] | 88 |  | 
 | 89 |     # Compile message catalogs. | 
 | 90 |     # Horizon is installed as develop mode, so we can compile here. | 
 | 91 |     # Message catalog compilation is handled by Django admin script, | 
 | 92 |     # so compiling them after the installation avoids Django installation twice. | 
| Sean Dague | 3c8973a | 2014-11-14 09:31:02 -0500 | [diff] [blame] | 93 |     (cd $HORIZON_DIR; ./run_tests.sh -N --compilemessages) | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 94 | } | 
 | 95 |  | 
 | 96 | # init_horizon() - Initialize databases, etc. | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 97 | function init_horizon { | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 98 |     # ``local_settings.py`` is used to override horizon default settings. | 
| Dean Troyer | 1bbfcc7 | 2014-07-25 12:50:14 -0500 | [diff] [blame] | 99 |     local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 100 |     cp $HORIZON_SETTINGS $local_settings | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 101 |  | 
| David Lyle | 45ce982 | 2014-09-11 17:50:08 -0600 | [diff] [blame] | 102 |     _horizon_config_set $local_settings "" COMPRESS_OFFLINE True | 
 | 103 |  | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 104 |     _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\" | 
| Haiwei Xu | 98a1817 | 2014-06-04 19:15:11 +0900 | [diff] [blame] | 105 |     _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_PROTOCOL}://${KEYSTONE_SERVICE_HOST}:${KEYSTONE_SERVICE_PORT}/v2.0\"" | 
| Brant Knudson | 3951a94 | 2014-08-24 18:54:51 -0500 | [diff] [blame] | 106 |     if [[ -n "$KEYSTONE_TOKEN_HASH_ALGORITHM" ]]; then | 
 | 107 |         _horizon_config_set $local_settings "" OPENSTACK_TOKEN_HASH_ALGORITHM \""$KEYSTONE_TOKEN_HASH_ALGORITHM"\" | 
 | 108 |     fi | 
| Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 109 |  | 
 | 110 |     if [ -f $SSL_BUNDLE_FILE ]; then | 
 | 111 |         _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\" | 
 | 112 |     fi | 
 | 113 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 114 |     # Create an empty directory that apache uses as docroot | 
 | 115 |     sudo mkdir -p $HORIZON_DIR/.blackhole | 
 | 116 |  | 
| Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 117 |     local horizon_conf=$(apache_site_config_for horizon) | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 118 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 119 |     # Configure apache to run horizon | 
 | 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; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 126 |     \" $FILES/apache-horizon.template >$horizon_conf" | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 127 |  | 
 | 128 |     if is_ubuntu; then | 
 | 129 |         disable_apache_site 000-default | 
 | 130 |         sudo touch $horizon_conf | 
 | 131 |     elif is_fedora; then | 
 | 132 |         sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf | 
 | 133 |     elif is_suse; then | 
 | 134 |         : # nothing to do | 
 | 135 |     else | 
 | 136 |         exit_distro_not_supported "horizon apache configuration" | 
 | 137 |     fi | 
 | 138 |     enable_apache_site horizon | 
 | 139 |  | 
 | 140 |     # Remove old log files that could mess with how devstack detects whether Horizon | 
 | 141 |     # has been successfully started (see start_horizon() and functions::screen_it()) | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 142 |     # and run_process | 
| Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 143 |     sudo rm -f /var/log/$APACHE_NAME/horizon_* | 
 | 144 |  | 
| Mikhail S Medvedev | 088e660 | 2014-11-18 12:11:26 -0600 | [diff] [blame] | 145 |     # Setup alias for django-admin which could be different depending on distro | 
 | 146 |     local django_admin | 
 | 147 |     if type -p django-admin > /dev/null; then | 
 | 148 |         django_admin=django-admin | 
 | 149 |     else | 
 | 150 |         django_admin=django-admin.py | 
 | 151 |     fi | 
 | 152 |  | 
 | 153 |     DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin collectstatic --noinput | 
 | 154 |     DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin compress --force | 
| David Lyle | 45ce982 | 2014-09-11 17:50:08 -0600 | [diff] [blame] | 155 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 156 | } | 
 | 157 |  | 
| Zhenguo Niu | e385d1e | 2014-03-12 16:58:12 +0800 | [diff] [blame] | 158 | # install_django_openstack_auth() - Collect source and prepare | 
 | 159 | function install_django_openstack_auth { | 
| Sean Dague | 3c8973a | 2014-11-14 09:31:02 -0500 | [diff] [blame] | 160 |     if use_library_from_git "django_openstack_auth"; then | 
 | 161 |         local dir=${GITDIR["django_openstack_auth"]} | 
 | 162 |         git_clone_by_name "django_openstack_auth" | 
 | 163 |         # Compile message catalogs before installation | 
 | 164 |         _prepare_message_catalog_compilation | 
 | 165 |         (cd $dir; python setup.py compile_catalog) | 
 | 166 |         setup_dev_lib "django_openstack_auth" | 
 | 167 |     fi | 
 | 168 |     # if we aren't using this library from git, then we just let it | 
 | 169 |     # get dragged in by the horizon setup. | 
| Zhenguo Niu | e385d1e | 2014-03-12 16:58:12 +0800 | [diff] [blame] | 170 | } | 
 | 171 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 172 | # install_horizon() - Collect source and prepare | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 173 | function install_horizon { | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 174 |     # Apache installation, because we mark it NOPRIME | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 175 |     install_apache_wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 176 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 177 |     git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG | 
 | 178 | } | 
 | 179 |  | 
 | 180 | # start_horizon() - Start running processes, including screen | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 181 | function start_horizon { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 182 |     restart_apache_server | 
| Chris Dent | 2f27a0e | 2014-09-09 13:46:02 +0100 | [diff] [blame] | 183 |     tail_log horizon /var/log/$APACHE_NAME/horizon_error.log | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 184 | } | 
 | 185 |  | 
 | 186 | # stop_horizon() - Stop running processes (non-screen) | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 187 | function stop_horizon { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 188 |     stop_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 189 | } | 
 | 190 |  | 
| Akihiro Motoki | 6518c0b | 2014-10-15 17:26:59 +0900 | [diff] [blame] | 191 | # NOTE: It can be moved to common functions, but it is only used by compilation | 
 | 192 | # of django_openstack_auth catalogs at the moment. | 
 | 193 | function _prepare_message_catalog_compilation { | 
 | 194 |     local babel_package=$(grep ^Babel $REQUIREMENTS_DIR/global-requirements.txt) | 
 | 195 |     pip_install "$babel_package" | 
 | 196 | } | 
 | 197 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 198 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 199 | # Restore xtrace | 
 | 200 | $XTRACE | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 201 |  | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 202 | # Tell emacs to use shell-script-mode | 
 | 203 | ## Local variables: | 
 | 204 | ## mode: shell-script | 
 | 205 | ## End: |