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 |
| 29 | |
Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 30 | # local_settings.py is used to customize Dashboard settings. |
| 31 | # The example file in Horizon repo is used by default. |
| 32 | HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example} |
| 33 | |
Dean Troyer | 4237f59 | 2014-01-29 16:22:11 -0600 | [diff] [blame] | 34 | # Tell Tempest this project is present |
| 35 | TEMPEST_SERVICES+=,horizon |
| 36 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 37 | |
| 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 |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 52 | 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 Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 56 | sed -i -e "/^$section/a\ '$option': $value," $file |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 57 | fi |
| 58 | else |
| 59 | echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file |
| 60 | fi |
| 61 | } |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 62 | |
Ian Wienand | ad43b39 | 2013-04-11 11:13:09 +1000 | [diff] [blame] | 63 | |
Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 64 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 65 | # 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 Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 70 | function cleanup_horizon { |
Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 71 | 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 Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | # configure_horizon() - Set config files, create data dirs, etc |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 81 | function configure_horizon { |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 82 | setup_develop $HORIZON_DIR |
| 83 | } |
| 84 | |
| 85 | # init_horizon() - Initialize databases, etc. |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 86 | function init_horizon { |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 87 | # ``local_settings.py`` is used to override horizon default settings. |
| 88 | local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py |
Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 89 | cp $HORIZON_SETTINGS $local_settings |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 90 | |
Edgar Magana | c973f12 | 2013-07-29 16:39:56 -0700 | [diff] [blame] | 91 | if is_service_enabled neutron; then |
| 92 | _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP |
| 93 | fi |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 94 | # enable loadbalancer dashboard in case service is enabled |
| 95 | if is_service_enabled q-lbaas; then |
Nobuto MURATA | 73a39bf | 2013-07-11 16:26:02 +0900 | [diff] [blame] | 96 | _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True |
Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 97 | fi |
| 98 | |
Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 99 | # 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 MOTOKI | eaa9e1e | 2013-09-10 05:22:37 +0900 | [diff] [blame] | 104 | # 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 Crittenden | c31fa40 | 2014-03-17 00:07:52 -0400 | [diff] [blame] | 109 | _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\" |
Haiwei Xu | 98a1817 | 2014-06-04 19:15:11 +0900 | [diff] [blame^] | 110 | _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] | 111 | |
| 112 | if [ -f $SSL_BUNDLE_FILE ]; then |
| 113 | _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\" |
| 114 | fi |
| 115 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 116 | # Create an empty directory that apache uses as docroot |
| 117 | sudo mkdir -p $HORIZON_DIR/.blackhole |
| 118 | |
Chris Buccella | 610af8c | 2013-11-05 12:56:34 +0000 | [diff] [blame] | 119 | # 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] | 120 | HORIZON_REQUIRE='' |
Chris Buccella | 610af8c | 2013-11-05 12:56:34 +0000 | [diff] [blame] | 121 | if check_apache_version "2.4" ; then |
| 122 | HORIZON_REQUIRE='Require all granted' |
| 123 | fi |
| 124 | |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 125 | local horizon_conf=$(apache_site_config_for horizon) |
Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 126 | if is_ubuntu; then |
Christian Berendt | cbd97ca | 2014-03-27 12:48:43 +0000 | [diff] [blame] | 127 | disable_apache_site 000-default |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 128 | sudo touch $horizon_conf |
Gabriel Assis Bezerra | a688bc6 | 2014-05-27 20:58:22 +0000 | [diff] [blame] | 129 | enable_apache_site horizon |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 130 | elif is_fedora; then |
Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 131 | sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf |
Adam Spiers | 3ac8612 | 2013-10-01 01:08:20 +0100 | [diff] [blame] | 132 | elif is_suse; then |
| 133 | : # nothing to do |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 134 | else |
Adam Spiers | 15aa0fc | 2013-10-01 01:10:16 +0100 | [diff] [blame] | 135 | exit_distro_not_supported "horizon apache configuration" |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 136 | fi |
| 137 | |
JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 138 | # Remove old log files that could mess with how devstack detects whether Horizon |
| 139 | # has been successfully started (see start_horizon() and functions::screen_it()) |
| 140 | sudo rm -f /var/log/$APACHE_NAME/horizon_* |
| 141 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 142 | # Configure apache to run horizon |
| 143 | sudo sh -c "sed -e \" |
| 144 | s,%USER%,$APACHE_USER,g; |
| 145 | s,%GROUP%,$APACHE_GROUP,g; |
| 146 | s,%HORIZON_DIR%,$HORIZON_DIR,g; |
| 147 | s,%APACHE_NAME%,$APACHE_NAME,g; |
| 148 | s,%DEST%,$DEST,g; |
Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 149 | s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g; |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 150 | \" $FILES/apache-horizon.template >$horizon_conf" |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | # install_horizon() - Collect source and prepare |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 154 | function install_horizon { |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 155 | # Apache installation, because we mark it NOPRIME |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 156 | install_apache_wsgi |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 157 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 158 | git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG |
| 159 | } |
| 160 | |
| 161 | # start_horizon() - Start running processes, including screen |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 162 | function start_horizon { |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 163 | restart_apache_server |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 164 | screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log" |
| 165 | } |
| 166 | |
| 167 | # stop_horizon() - Stop running processes (non-screen) |
Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 168 | function stop_horizon { |
zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 169 | stop_apache_server |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 170 | } |
| 171 | |
Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 172 | |
Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 173 | # Restore xtrace |
| 174 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 175 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 176 | # Tell emacs to use shell-script-mode |
| 177 | ## Local variables: |
| 178 | ## mode: shell-script |
| 179 | ## End: |