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