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 |
| 28 | HORIZON_DIR=$DEST/horizon |
Zhenguo Niu | e385d1e | 2014-03-12 16:58:12 +0800 | [diff] [blame] | 29 | HORIZONAUTH_DIR=$DEST/django_openstack_auth |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 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 | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 35 | # Tell Tempest this project is present |
| 36 | TEMPEST_SERVICES+=,horizon |
| 37 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 38 | |
| 39 | # Functions |
| 40 | # --------- |
| 41 | |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 42 | # utility method of setting python option |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 43 | function _horizon_config_set { |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 44 | local file=$1 |
| 45 | local section=$2 |
| 46 | local option=$3 |
| 47 | local value=$4 |
| 48 | |
Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 49 | if [ -z "$section" ]; then |
| 50 | sed -e "/^$option/d" -i $local_settings |
| 51 | echo -e "\n$option=$value" >> $file |
| 52 | elif grep -q "^$section" $file; then |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 53 | line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) |
| 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 { |
Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 72 | if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then |
| 73 | # If ``/usr/bin/node`` points into ``$DEST`` |
| 74 | # we installed it via ``install_nodejs`` |
| 75 | if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then |
| 76 | sudo rm /usr/bin/node |
| 77 | fi |
| 78 | fi |
Dean Troyer | 444a8d5 | 2014-06-06 16:36:52 -0500 | [diff] [blame] | 79 | |
| 80 | local horizon_conf=$(apache_site_config_for horizon) |
| 81 | sudo rm -f $horizon_conf |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | # configure_horizon() - Set config files, create data dirs, etc |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 85 | function configure_horizon { |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 86 | setup_develop $HORIZON_DIR |
| 87 | } |
| 88 | |
| 89 | # init_horizon() - Initialize databases, etc. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 90 | function init_horizon { |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 91 | # ``local_settings.py`` is used to override horizon default settings. |
| 92 | local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py |
Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 93 | cp $HORIZON_SETTINGS $local_settings |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 94 | |
Edgar Magana | c973f12 | 2013-07-29 16:39:56 -0700 | [diff] [blame] | 95 | if is_service_enabled neutron; then |
| 96 | _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP |
| 97 | fi |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 98 | # enable loadbalancer dashboard in case service is enabled |
| 99 | if is_service_enabled q-lbaas; then |
Nobuto MURATA | 73a39bf | 2013-07-11 16:26:02 +0900 | [diff] [blame] | 100 | _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 101 | fi |
| 102 | |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 103 | # enable firewall dashboard in case service is enabled |
| 104 | if is_service_enabled q-fwaas; then |
| 105 | _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_firewall True |
| 106 | fi |
| 107 | |
Akihiro MOTOKI | eaa9e1e | 2013-09-10 05:22:37 +0900 | [diff] [blame] | 108 | # enable VPN dashboard in case service is enabled |
| 109 | if is_service_enabled q-vpn; then |
| 110 | _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_vpn True |
| 111 | fi |
| 112 | |
Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 113 | _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\" |
Haiwei Xu | 98a1817 | 2014-06-04 19:15:11 +0900 | [diff] [blame] | 114 | _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_PROTOCOL}://${KEYSTONE_SERVICE_HOST}:${KEYSTONE_SERVICE_PORT}/v2.0\"" |
Rob Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 115 | |
| 116 | if [ -f $SSL_BUNDLE_FILE ]; then |
| 117 | _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\" |
| 118 | fi |
| 119 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 120 | # Create an empty directory that apache uses as docroot |
| 121 | sudo mkdir -p $HORIZON_DIR/.blackhole |
| 122 | |
Chris Buccella | 610af8c | 2013-11-05 12:56:34 +0000 | [diff] [blame] | 123 | # Apache 2.4 uses mod_authz_host for access control now (instead of "Allow") |
Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 124 | HORIZON_REQUIRE='' |
Chris Buccella | 610af8c | 2013-11-05 12:56:34 +0000 | [diff] [blame] | 125 | if check_apache_version "2.4" ; then |
| 126 | HORIZON_REQUIRE='Require all granted' |
| 127 | fi |
| 128 | |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 129 | local horizon_conf=$(apache_site_config_for horizon) |
JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 130 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 131 | # Configure apache to run horizon |
| 132 | sudo sh -c "sed -e \" |
| 133 | s,%USER%,$APACHE_USER,g; |
| 134 | s,%GROUP%,$APACHE_GROUP,g; |
| 135 | s,%HORIZON_DIR%,$HORIZON_DIR,g; |
| 136 | s,%APACHE_NAME%,$APACHE_NAME,g; |
| 137 | s,%DEST%,$DEST,g; |
Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 138 | s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g; |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 139 | \" $FILES/apache-horizon.template >$horizon_conf" |
Attila Fazekas | afda4ef | 2014-06-03 16:53:03 +0200 | [diff] [blame] | 140 | |
| 141 | if is_ubuntu; then |
| 142 | disable_apache_site 000-default |
| 143 | sudo touch $horizon_conf |
| 144 | elif is_fedora; then |
| 145 | sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf |
| 146 | elif is_suse; then |
| 147 | : # nothing to do |
| 148 | else |
| 149 | exit_distro_not_supported "horizon apache configuration" |
| 150 | fi |
| 151 | enable_apache_site horizon |
| 152 | |
| 153 | # Remove old log files that could mess with how devstack detects whether Horizon |
| 154 | # has been successfully started (see start_horizon() and functions::screen_it()) |
| 155 | sudo rm -f /var/log/$APACHE_NAME/horizon_* |
| 156 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 157 | } |
| 158 | |
Zhenguo Niu | e385d1e | 2014-03-12 16:58:12 +0800 | [diff] [blame] | 159 | # install_django_openstack_auth() - Collect source and prepare |
| 160 | function install_django_openstack_auth { |
| 161 | git_clone $HORIZONAUTH_REPO $HORIZONAUTH_DIR $HORIZONAUTH_BRANCH |
Sean Dague | e837714 | 2014-06-23 08:21:07 -0400 | [diff] [blame] | 162 | setup_install $HORIZONAUTH_DIR |
Zhenguo Niu | e385d1e | 2014-03-12 16:58:12 +0800 | [diff] [blame] | 163 | } |
| 164 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 165 | # install_horizon() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 166 | function install_horizon { |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 167 | # Apache installation, because we mark it NOPRIME |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 168 | install_apache_wsgi |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 169 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 170 | git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG |
| 171 | } |
| 172 | |
| 173 | # start_horizon() - Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 174 | function start_horizon { |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 175 | restart_apache_server |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 176 | screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log" |
| 177 | } |
| 178 | |
| 179 | # stop_horizon() - Stop running processes (non-screen) |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 180 | function stop_horizon { |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 181 | stop_apache_server |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 182 | } |
| 183 | |
Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 184 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 185 | # Restore xtrace |
| 186 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 187 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 188 | # Tell emacs to use shell-script-mode |
| 189 | ## Local variables: |
| 190 | ## mode: shell-script |
| 191 | ## End: |