| 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 | 
|  | 7 | # ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined | 
|  | 8 | # <list other global vars that are assumed to be defined> | 
|  | 9 |  | 
|  | 10 | # ``stack.sh`` calls the entry points in this order: | 
|  | 11 | # | 
|  | 12 | # install_horizon | 
|  | 13 | # configure_horizon | 
|  | 14 | # init_horizon | 
|  | 15 | # start_horizon | 
|  | 16 | # stop_horizon | 
|  | 17 | # cleanup_horizon | 
|  | 18 |  | 
|  | 19 | # Save trace setting | 
|  | 20 | XTRACE=$(set +o | grep xtrace) | 
|  | 21 | set +o xtrace | 
|  | 22 |  | 
|  | 23 |  | 
|  | 24 | # Defaults | 
|  | 25 | # -------- | 
|  | 26 |  | 
|  | 27 | # <define global variables here that belong to this project> | 
|  | 28 |  | 
|  | 29 | # Set up default directories | 
|  | 30 | HORIZON_DIR=$DEST/horizon | 
|  | 31 |  | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 32 | # local_settings.py is used to customize Dashboard settings. | 
|  | 33 | # The example file in Horizon repo is used by default. | 
|  | 34 | HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example} | 
|  | 35 |  | 
| Martin Vidner | 2ed63f4 | 2012-12-04 10:33:49 +0100 | [diff] [blame] | 36 | # Allow overriding the default Apache user and group, default to | 
|  | 37 | # current user and his default group. | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 38 | APACHE_USER=${APACHE_USER:-$USER} | 
| Martin Vidner | 2ed63f4 | 2012-12-04 10:33:49 +0100 | [diff] [blame] | 39 | APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)} | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 40 |  | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 41 | # Set up service name and configuration path | 
|  | 42 | if is_ubuntu; then | 
|  | 43 | APACHE_NAME=apache2 | 
|  | 44 | APACHE_CONF=sites-available/horizon | 
|  | 45 | elif is_fedora; then | 
|  | 46 | APACHE_NAME=httpd | 
|  | 47 | APACHE_CONF=conf.d/horizon.conf | 
|  | 48 | elif is_suse; then | 
|  | 49 | APACHE_NAME=apache2 | 
|  | 50 | APACHE_CONF=vhosts.d/horizon.conf | 
|  | 51 | fi | 
|  | 52 |  | 
| Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 53 |  | 
|  | 54 | # Functions | 
|  | 55 | # --------- | 
|  | 56 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 57 | # utility method of setting python option | 
|  | 58 | function _horizon_config_set() { | 
|  | 59 | local file=$1 | 
|  | 60 | local section=$2 | 
|  | 61 | local option=$3 | 
|  | 62 | local value=$4 | 
|  | 63 |  | 
|  | 64 | if grep -q "^$section" $file; then | 
|  | 65 | line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) | 
|  | 66 | if [ -n "$line" ]; then | 
|  | 67 | sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file | 
|  | 68 | else | 
|  | 69 | sed -i -e "/^$section/ a\n    '$option': $value,\n" $file | 
|  | 70 | fi | 
|  | 71 | else | 
|  | 72 | echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file | 
|  | 73 | fi | 
|  | 74 | } | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 75 |  | 
| Ian Wienand | ad43b39 | 2013-04-11 11:13:09 +1000 | [diff] [blame] | 76 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 77 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 78 | # Entry Points | 
|  | 79 | # ------------ | 
|  | 80 |  | 
|  | 81 | # cleanup_horizon() - Remove residual data files, anything left over from previous | 
|  | 82 | # runs that a clean run would need to clean up | 
|  | 83 | function cleanup_horizon() { | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 84 | if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then | 
|  | 85 | # If ``/usr/bin/node`` points into ``$DEST`` | 
|  | 86 | # we installed it via ``install_nodejs`` | 
|  | 87 | if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then | 
|  | 88 | sudo rm /usr/bin/node | 
|  | 89 | fi | 
|  | 90 | fi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 91 | } | 
|  | 92 |  | 
|  | 93 | # configure_horizon() - Set config files, create data dirs, etc | 
|  | 94 | function configure_horizon() { | 
|  | 95 | setup_develop $HORIZON_DIR | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 | # init_horizon() - Initialize databases, etc. | 
|  | 99 | function init_horizon() { | 
|  | 100 | # Remove stale session database. | 
|  | 101 | rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3 | 
|  | 102 |  | 
|  | 103 | # ``local_settings.py`` is used to override horizon default settings. | 
|  | 104 | local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py | 
| Akihiro MOTOKI | 7104ab4 | 2013-03-27 19:47:11 +0900 | [diff] [blame] | 105 | cp $HORIZON_SETTINGS $local_settings | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 106 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 107 | # enable loadbalancer dashboard in case service is enabled | 
|  | 108 | if is_service_enabled q-lbaas; then | 
|  | 109 | _horizon_config_set $local_settings OPENSTACK_QUANTUM_NETWORK enable_lb True | 
|  | 110 | fi | 
|  | 111 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 112 | # Initialize the horizon database (it stores sessions and notices shown to | 
|  | 113 | # users).  The user system is external (keystone). | 
|  | 114 | cd $HORIZON_DIR | 
|  | 115 | python manage.py syncdb --noinput | 
|  | 116 | cd $TOP_DIR | 
|  | 117 |  | 
|  | 118 | # Create an empty directory that apache uses as docroot | 
|  | 119 | sudo mkdir -p $HORIZON_DIR/.blackhole | 
|  | 120 |  | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 121 | HORIZON_REQUIRE='' | 
| 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 | 
|  | 126 | sudo touch /etc/$APACHE_NAME/$APACHE_CONF | 
|  | 127 | sudo a2ensite horizon | 
| Vincent Untz | f2a18c0 | 2012-12-04 18:34:25 +0100 | [diff] [blame] | 128 | # WSGI isn't enabled by default, enable it | 
| Sean Dague | e1864c3 | 2012-11-29 14:20:34 -0500 | [diff] [blame] | 129 | sudo a2enmod wsgi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 130 | elif is_fedora; then | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 131 | if [[ "$os_RELEASE" -ge "18" ]]; then | 
|  | 132 | # fedora 18 has Require all denied  in its httpd.conf | 
|  | 133 | # and requires explicit Require all granted | 
|  | 134 | HORIZON_REQUIRE='Require all granted' | 
|  | 135 | fi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 136 | sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf | 
|  | 137 | elif is_suse; then | 
| Vincent Untz | f2a18c0 | 2012-12-04 18:34:25 +0100 | [diff] [blame] | 138 | # WSGI isn't enabled by default, enable it | 
|  | 139 | sudo a2enmod wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 140 | else | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 141 | exit_distro_not_supported "apache configuration" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 142 | fi | 
|  | 143 |  | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 144 | # Remove old log files that could mess with how devstack detects whether Horizon | 
|  | 145 | # has been successfully started (see start_horizon() and functions::screen_it()) | 
|  | 146 | sudo rm -f /var/log/$APACHE_NAME/horizon_* | 
|  | 147 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 148 | # Configure apache to run horizon | 
|  | 149 | sudo sh -c "sed -e \" | 
|  | 150 | s,%USER%,$APACHE_USER,g; | 
|  | 151 | s,%GROUP%,$APACHE_GROUP,g; | 
|  | 152 | s,%HORIZON_DIR%,$HORIZON_DIR,g; | 
|  | 153 | s,%APACHE_NAME%,$APACHE_NAME,g; | 
|  | 154 | s,%DEST%,$DEST,g; | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 155 | s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g; | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 156 | \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 157 | } | 
|  | 158 |  | 
|  | 159 | # install_horizon() - Collect source and prepare | 
|  | 160 | function install_horizon() { | 
|  | 161 | # Apache installation, because we mark it NOPRIME | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 162 | if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 163 | # Install apache2, which is NOPRIME'd | 
|  | 164 | install_package apache2 libapache2-mod-wsgi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 165 | elif is_fedora; then | 
|  | 166 | sudo rm -f /etc/httpd/conf.d/000-* | 
|  | 167 | install_package httpd mod_wsgi | 
| Vincent Untz | ca5c471 | 2012-11-21 17:45:49 +0100 | [diff] [blame] | 168 | elif is_suse; then | 
|  | 169 | install_package apache2 apache2-mod_wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 170 | else | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 171 | exit_distro_not_supported "apache installation" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 172 | fi | 
|  | 173 |  | 
|  | 174 | # NOTE(sdague) quantal changed the name of the node binary | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 175 | if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 176 | if [[ ! -e "/usr/bin/node" ]]; then | 
|  | 177 | install_package nodejs-legacy | 
|  | 178 | fi | 
| Ian Wienand | 2bda6cf | 2013-05-23 09:25:10 +1000 | [diff] [blame] | 179 | elif is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -ge "18" ]]; then | 
| Sunil Thaha | 627d9c7 | 2013-04-10 14:11:44 +1000 | [diff] [blame] | 180 | install_package nodejs | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 181 | fi | 
|  | 182 |  | 
|  | 183 | git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | # start_horizon() - Start running processes, including screen | 
|  | 187 | function start_horizon() { | 
|  | 188 | restart_service $APACHE_NAME | 
|  | 189 | screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log" | 
|  | 190 | } | 
|  | 191 |  | 
|  | 192 | # stop_horizon() - Stop running processes (non-screen) | 
|  | 193 | function stop_horizon() { | 
| JordanP | 1e4587e | 2013-05-08 22:19:59 +0200 | [diff] [blame] | 194 | if [ -n "$APACHE_NAME" ]; then | 
|  | 195 | stop_service $APACHE_NAME | 
| Steven Dake | 532908f | 2013-01-14 11:35:17 -0700 | [diff] [blame] | 196 | else | 
|  | 197 | exit_distro_not_supported "apache configuration" | 
|  | 198 | fi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 199 | } | 
|  | 200 |  | 
| Dean Troyer | 1a6d449 | 2013-06-03 16:47:36 -0500 | [diff] [blame] | 201 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 202 | # Restore xtrace | 
|  | 203 | $XTRACE | 
| Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 204 |  | 
|  | 205 | # Local variables: | 
|  | 206 | # mode: shell-script | 
|  | 207 | # End: |