| 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 | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 34 |  | 
 | 35 | # Functions | 
 | 36 | # --------- | 
 | 37 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 38 | # utility method of setting python option | 
 | 39 | function _horizon_config_set() { | 
 | 40 |     local file=$1 | 
 | 41 |     local section=$2 | 
 | 42 |     local option=$3 | 
 | 43 |     local value=$4 | 
 | 44 |  | 
 | 45 |     if grep -q "^$section" $file; then | 
 | 46 |         line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) | 
 | 47 |         if [ -n "$line" ]; then | 
 | 48 |             sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file | 
 | 49 |         else | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 50 |             sed -i -e "/^$section/a\    '$option': $value," $file | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 51 |         fi | 
 | 52 |     else | 
 | 53 |         echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file | 
 | 54 |     fi | 
 | 55 | } | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 56 |  | 
| Ian Wienand | ad43b39 | 2013-04-11 11:13:09 +1000 | [diff] [blame] | 57 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 58 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 59 | # Entry Points | 
 | 60 | # ------------ | 
 | 61 |  | 
 | 62 | # cleanup_horizon() - Remove residual data files, anything left over from previous | 
 | 63 | # runs that a clean run would need to clean up | 
 | 64 | function cleanup_horizon() { | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 65 |     if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then | 
 | 66 |         # If ``/usr/bin/node`` points into ``$DEST`` | 
 | 67 |         # we installed it via ``install_nodejs`` | 
 | 68 |         if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then | 
 | 69 |             sudo rm /usr/bin/node | 
 | 70 |         fi | 
 | 71 |     fi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 72 | } | 
 | 73 |  | 
 | 74 | # configure_horizon() - Set config files, create data dirs, etc | 
 | 75 | function configure_horizon() { | 
 | 76 |     setup_develop $HORIZON_DIR | 
 | 77 | } | 
 | 78 |  | 
 | 79 | # init_horizon() - Initialize databases, etc. | 
 | 80 | function init_horizon() { | 
 | 81 |     # Remove stale session database. | 
 | 82 |     rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3 | 
 | 83 |  | 
 | 84 |     # ``local_settings.py`` is used to override horizon default settings. | 
 | 85 |     local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 86 |     cp $HORIZON_SETTINGS $local_settings | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 87 |  | 
| Edgar Magana | c973f12 | 2013-07-29 16:39:56 -0700 | [diff] [blame] | 88 |     if is_service_enabled neutron; then | 
 | 89 |         _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP | 
 | 90 |     fi | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 91 |     # enable loadbalancer dashboard in case service is enabled | 
 | 92 |     if is_service_enabled q-lbaas; then | 
| Nobuto MURATA | 73a39bf | 2013-07-11 16:26:02 +0900 | [diff] [blame] | 93 |         _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 94 |     fi | 
 | 95 |  | 
| Ravi Chunduru | 95c93e2 | 2013-07-16 04:18:47 -0700 | [diff] [blame] | 96 |     # enable firewall dashboard in case service is enabled | 
 | 97 |     if is_service_enabled q-fwaas; then | 
 | 98 |         _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_firewall True | 
 | 99 |     fi | 
 | 100 |  | 
| Akihiro MOTOKI | eaa9e1e | 2013-09-10 05:22:37 +0900 | [diff] [blame] | 101 |     # enable VPN dashboard in case service is enabled | 
 | 102 |     if is_service_enabled q-vpn; then | 
 | 103 |         _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_vpn True | 
 | 104 |     fi | 
 | 105 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 106 |     # Initialize the horizon database (it stores sessions and notices shown to | 
 | 107 |     # users).  The user system is external (keystone). | 
 | 108 |     cd $HORIZON_DIR | 
 | 109 |     python manage.py syncdb --noinput | 
 | 110 |     cd $TOP_DIR | 
 | 111 |  | 
 | 112 |     # Create an empty directory that apache uses as docroot | 
 | 113 |     sudo mkdir -p $HORIZON_DIR/.blackhole | 
 | 114 |  | 
| Chris Buccella | 610af8c | 2013-11-05 12:56:34 +0000 | [diff] [blame^] | 115 |     # 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] | 116 |     HORIZON_REQUIRE='' | 
| Chris Buccella | 610af8c | 2013-11-05 12:56:34 +0000 | [diff] [blame^] | 117 |     if check_apache_version "2.4" ; then | 
 | 118 |         HORIZON_REQUIRE='Require all granted' | 
 | 119 |     fi | 
 | 120 |  | 
| Attila Fazekas | 248a8cc | 2013-08-06 08:00:06 +0200 | [diff] [blame] | 121 |     local horizon_conf=/etc/$APACHE_NAME/$APACHE_CONF_DIR/horizon.conf | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 122 |     if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 123 |         # Clean up the old config name | 
 | 124 |         sudo rm -f /etc/apache2/sites-enabled/000-default | 
 | 125 |         # Be a good citizen and use the distro tools here | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 126 |         sudo touch $horizon_conf | 
| Attila Fazekas | 248a8cc | 2013-08-06 08:00:06 +0200 | [diff] [blame] | 127 |         sudo a2ensite horizon.conf | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 128 |     elif is_fedora; then | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 129 |         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] | 130 |     elif is_suse; then | 
 | 131 |         : # nothing to do | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 132 |     else | 
| Adam Spiers | 15aa0fc | 2013-10-01 01:10:16 +0100 | [diff] [blame] | 133 |         exit_distro_not_supported "horizon apache configuration" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 134 |     fi | 
 | 135 |  | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 136 |     # Remove old log files that could mess with how devstack detects whether Horizon | 
 | 137 |     # has been successfully started (see start_horizon() and functions::screen_it()) | 
 | 138 |     sudo rm -f /var/log/$APACHE_NAME/horizon_* | 
 | 139 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 140 |     # Configure apache to run horizon | 
 | 141 |     sudo sh -c "sed -e \" | 
 | 142 |         s,%USER%,$APACHE_USER,g; | 
 | 143 |         s,%GROUP%,$APACHE_GROUP,g; | 
 | 144 |         s,%HORIZON_DIR%,$HORIZON_DIR,g; | 
 | 145 |         s,%APACHE_NAME%,$APACHE_NAME,g; | 
 | 146 |         s,%DEST%,$DEST,g; | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 147 |         s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g; | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 148 |     \" $FILES/apache-horizon.template >$horizon_conf" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 149 | } | 
 | 150 |  | 
 | 151 | # install_horizon() - Collect source and prepare | 
 | 152 | function install_horizon() { | 
 | 153 |     # Apache installation, because we mark it NOPRIME | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 154 |     install_apache_wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 155 |  | 
 | 156 |     # NOTE(sdague) quantal changed the name of the node binary | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 157 |     if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 158 |         if [[ ! -e "/usr/bin/node" ]]; then | 
 | 159 |             install_package nodejs-legacy | 
 | 160 |         fi | 
| Ian Wienand | 2bda6cf | 2013-05-23 09:25:10 +1000 | [diff] [blame] | 161 |     elif is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -ge "18" ]]; then | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 162 |         install_package nodejs | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 163 |     fi | 
 | 164 |  | 
 | 165 |     git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG | 
 | 166 | } | 
 | 167 |  | 
 | 168 | # start_horizon() - Start running processes, including screen | 
 | 169 | function start_horizon() { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 170 |     restart_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 171 |     screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log" | 
 | 172 | } | 
 | 173 |  | 
 | 174 | # stop_horizon() - Stop running processes (non-screen) | 
 | 175 | function stop_horizon() { | 
| zhang-hare | d98a5d0 | 2013-06-21 18:18:02 +0800 | [diff] [blame] | 176 |     stop_apache_server | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 177 | } | 
 | 178 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 179 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 180 | # Restore xtrace | 
 | 181 | $XTRACE | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 182 |  | 
| Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 183 | # Tell emacs to use shell-script-mode | 
 | 184 | ## Local variables: | 
 | 185 | ## mode: shell-script | 
 | 186 | ## End: |