| 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 | 
|  | 3 | # <do not include this template file in ``stack.sh``!> | 
|  | 4 |  | 
|  | 5 | # Dependencies: | 
|  | 6 | # ``functions`` file | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 7 | # ``apache`` file | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 8 | # ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined | 
|  | 9 | # <list other global vars that are assumed to be defined> | 
|  | 10 |  | 
|  | 11 | # ``stack.sh`` calls the entry points in this order: | 
|  | 12 | # | 
|  | 13 | # install_horizon | 
|  | 14 | # configure_horizon | 
|  | 15 | # init_horizon | 
|  | 16 | # start_horizon | 
|  | 17 | # stop_horizon | 
|  | 18 | # cleanup_horizon | 
|  | 19 |  | 
|  | 20 | # Save trace setting | 
|  | 21 | XTRACE=$(set +o | grep xtrace) | 
|  | 22 | set +o xtrace | 
|  | 23 |  | 
|  | 24 |  | 
|  | 25 | # Defaults | 
|  | 26 | # -------- | 
|  | 27 |  | 
|  | 28 | # <define global variables here that belong to this project> | 
|  | 29 |  | 
|  | 30 | # Set up default directories | 
|  | 31 | HORIZON_DIR=$DEST/horizon | 
|  | 32 |  | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 33 | # local_settings.py is used to customize Dashboard settings. | 
|  | 34 | # The example file in Horizon repo is used by default. | 
|  | 35 | HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example} | 
|  | 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 | 
|  | 42 | function _horizon_config_set() { | 
|  | 43 | local file=$1 | 
|  | 44 | local section=$2 | 
|  | 45 | local option=$3 | 
|  | 46 | local value=$4 | 
|  | 47 |  | 
|  | 48 | if grep -q "^$section" $file; then | 
|  | 49 | line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) | 
|  | 50 | if [ -n "$line" ]; then | 
|  | 51 | sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file | 
|  | 52 | else | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 53 | sed -i -e "/^$section/a\    '$option': $value," $file | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 54 | fi | 
|  | 55 | else | 
|  | 56 | echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file | 
|  | 57 | fi | 
|  | 58 | } | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 59 |  | 
| Ian Wienand | ad43b39 | 2013-04-11 11:13:09 +1000 | [diff] [blame] | 60 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 61 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 62 | # Entry Points | 
|  | 63 | # ------------ | 
|  | 64 |  | 
|  | 65 | # cleanup_horizon() - Remove residual data files, anything left over from previous | 
|  | 66 | # runs that a clean run would need to clean up | 
|  | 67 | function cleanup_horizon() { | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 68 | if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then | 
|  | 69 | # If ``/usr/bin/node`` points into ``$DEST`` | 
|  | 70 | # we installed it via ``install_nodejs`` | 
|  | 71 | if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then | 
|  | 72 | sudo rm /usr/bin/node | 
|  | 73 | fi | 
|  | 74 | fi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 75 | } | 
|  | 76 |  | 
|  | 77 | # configure_horizon() - Set config files, create data dirs, etc | 
|  | 78 | function configure_horizon() { | 
|  | 79 | setup_develop $HORIZON_DIR | 
|  | 80 | } | 
|  | 81 |  | 
|  | 82 | # init_horizon() - Initialize databases, etc. | 
|  | 83 | function init_horizon() { | 
|  | 84 | # Remove stale session database. | 
|  | 85 | rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3 | 
|  | 86 |  | 
|  | 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 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 109 | # Initialize the horizon database (it stores sessions and notices shown to | 
|  | 110 | # users).  The user system is external (keystone). | 
|  | 111 | cd $HORIZON_DIR | 
|  | 112 | python manage.py syncdb --noinput | 
|  | 113 | cd $TOP_DIR | 
|  | 114 |  | 
|  | 115 | # Create an empty directory that apache uses as docroot | 
|  | 116 | sudo mkdir -p $HORIZON_DIR/.blackhole | 
|  | 117 |  | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 118 | HORIZON_REQUIRE='' | 
| Attila Fazekas | 248a8cc | 2013-08-06 08:00:06 +0200 | [diff] [blame] | 119 | local horizon_conf=/etc/$APACHE_NAME/$APACHE_CONF_DIR/horizon.conf | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 120 | if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 121 | # Clean up the old config name | 
|  | 122 | sudo rm -f /etc/apache2/sites-enabled/000-default | 
|  | 123 | # Be a good citizen and use the distro tools here | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 124 | sudo touch $horizon_conf | 
| Attila Fazekas | 248a8cc | 2013-08-06 08:00:06 +0200 | [diff] [blame] | 125 | sudo a2ensite horizon.conf | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 126 | elif is_fedora; then | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 127 | if [[ "$os_RELEASE" -ge "18" ]]; then | 
|  | 128 | # fedora 18 has Require all denied  in its httpd.conf | 
|  | 129 | # and requires explicit Require all granted | 
|  | 130 | HORIZON_REQUIRE='Require all granted' | 
|  | 131 | fi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 132 | 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] | 133 | elif is_suse; then | 
|  | 134 | : # nothing to do | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 135 | else | 
| Adam Spiers | 15aa0fc | 2013-10-01 01:10:16 +0100 | [diff] [blame] | 136 | exit_distro_not_supported "horizon apache configuration" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 137 | fi | 
|  | 138 |  | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 139 | # Remove old log files that could mess with how devstack detects whether Horizon | 
|  | 140 | # has been successfully started (see start_horizon() and functions::screen_it()) | 
|  | 141 | sudo rm -f /var/log/$APACHE_NAME/horizon_* | 
|  | 142 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 143 | # Configure apache to run horizon | 
|  | 144 | sudo sh -c "sed -e \" | 
|  | 145 | s,%USER%,$APACHE_USER,g; | 
|  | 146 | s,%GROUP%,$APACHE_GROUP,g; | 
|  | 147 | s,%HORIZON_DIR%,$HORIZON_DIR,g; | 
|  | 148 | s,%APACHE_NAME%,$APACHE_NAME,g; | 
|  | 149 | s,%DEST%,$DEST,g; | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 150 | s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 151 | \" $FILES/apache-horizon.template >$horizon_conf" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 152 | } | 
|  | 153 |  | 
|  | 154 | # install_horizon() - Collect source and prepare | 
|  | 155 | function install_horizon() { | 
|  | 156 | # Apache installation, because we mark it NOPRIME | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 157 | install_apache_wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 158 |  | 
|  | 159 | # NOTE(sdague) quantal changed the name of the node binary | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 160 | if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 161 | if [[ ! -e "/usr/bin/node" ]]; then | 
|  | 162 | install_package nodejs-legacy | 
|  | 163 | fi | 
| Ian Wienand | 2bda6cf | 2013-05-23 09:25:10 +1000 | [diff] [blame] | 164 | elif is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -ge "18" ]]; then | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 165 | install_package nodejs | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 166 | fi | 
|  | 167 |  | 
|  | 168 | git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG | 
|  | 169 | } | 
|  | 170 |  | 
|  | 171 | # start_horizon() - Start running processes, including screen | 
|  | 172 | function start_horizon() { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 173 | restart_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 174 | screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log" | 
|  | 175 | } | 
|  | 176 |  | 
|  | 177 | # stop_horizon() - Stop running processes (non-screen) | 
|  | 178 | function stop_horizon() { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 179 | stop_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 180 | } | 
|  | 181 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 182 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 183 | # Restore xtrace | 
|  | 184 | $XTRACE | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 185 |  | 
|  | 186 | # Local variables: | 
|  | 187 | # mode: shell-script | 
|  | 188 | # End: |