| 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 |  | 
| Martin Vidner | 2ed63f4 | 2012-12-04 10:33:49 +0100 | [diff] [blame] | 32 | # Allow overriding the default Apache user and group, default to | 
 | 33 | # current user and his default group. | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 34 | APACHE_USER=${APACHE_USER:-$USER} | 
| Martin Vidner | 2ed63f4 | 2012-12-04 10:33:49 +0100 | [diff] [blame] | 35 | APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)} | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 36 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 37 | # utility method of setting python option | 
 | 38 | function _horizon_config_set() { | 
 | 39 |     local file=$1 | 
 | 40 |     local section=$2 | 
 | 41 |     local option=$3 | 
 | 42 |     local value=$4 | 
 | 43 |  | 
 | 44 |     if grep -q "^$section" $file; then | 
 | 45 |         line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file) | 
 | 46 |         if [ -n "$line" ]; then | 
 | 47 |             sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file | 
 | 48 |         else | 
 | 49 |             sed -i -e "/^$section/ a\n    '$option': $value,\n" $file | 
 | 50 |         fi | 
 | 51 |     else | 
 | 52 |         echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file | 
 | 53 |     fi | 
 | 54 | } | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 55 |  | 
 | 56 | # Entry Points | 
 | 57 | # ------------ | 
 | 58 |  | 
 | 59 | # cleanup_horizon() - Remove residual data files, anything left over from previous | 
 | 60 | # runs that a clean run would need to clean up | 
 | 61 | function cleanup_horizon() { | 
 | 62 |     # kill instances (nova) | 
 | 63 |     # delete image files (glance) | 
 | 64 |     # This function intentionally left blank | 
 | 65 |     : | 
 | 66 | } | 
 | 67 |  | 
 | 68 | # configure_horizon() - Set config files, create data dirs, etc | 
 | 69 | function configure_horizon() { | 
 | 70 |     setup_develop $HORIZON_DIR | 
 | 71 | } | 
 | 72 |  | 
 | 73 | # init_horizon() - Initialize databases, etc. | 
 | 74 | function init_horizon() { | 
 | 75 |     # Remove stale session database. | 
 | 76 |     rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3 | 
 | 77 |  | 
 | 78 |     # ``local_settings.py`` is used to override horizon default settings. | 
 | 79 |     local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py | 
 | 80 |     cp $FILES/horizon_settings.py $local_settings | 
 | 81 |  | 
| Eugene Nikanorov | b663b33 | 2013-03-07 16:10:10 +0400 | [diff] [blame] | 82 |     # enable loadbalancer dashboard in case service is enabled | 
 | 83 |     if is_service_enabled q-lbaas; then | 
 | 84 |         _horizon_config_set $local_settings OPENSTACK_QUANTUM_NETWORK enable_lb True | 
 | 85 |     fi | 
 | 86 |  | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 87 |     # Initialize the horizon database (it stores sessions and notices shown to | 
 | 88 |     # users).  The user system is external (keystone). | 
 | 89 |     cd $HORIZON_DIR | 
 | 90 |     python manage.py syncdb --noinput | 
 | 91 |     cd $TOP_DIR | 
 | 92 |  | 
 | 93 |     # Create an empty directory that apache uses as docroot | 
 | 94 |     sudo mkdir -p $HORIZON_DIR/.blackhole | 
 | 95 |  | 
 | 96 |  | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 97 |     if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 98 |         APACHE_NAME=apache2 | 
 | 99 |         APACHE_CONF=sites-available/horizon | 
 | 100 |         # Clean up the old config name | 
 | 101 |         sudo rm -f /etc/apache2/sites-enabled/000-default | 
 | 102 |         # Be a good citizen and use the distro tools here | 
 | 103 |         sudo touch /etc/$APACHE_NAME/$APACHE_CONF | 
 | 104 |         sudo a2ensite horizon | 
| Vincent Untz | f2a18c0 | 2012-12-04 18:34:25 +0100 | [diff] [blame] | 105 |         # WSGI isn't enabled by default, enable it | 
| Sean Dague | e1864c3 | 2012-11-29 14:20:34 -0500 | [diff] [blame] | 106 |         sudo a2enmod wsgi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 107 |     elif is_fedora; then | 
 | 108 |         APACHE_NAME=httpd | 
 | 109 |         APACHE_CONF=conf.d/horizon.conf | 
 | 110 |         sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf | 
 | 111 |     elif is_suse; then | 
 | 112 |         APACHE_NAME=apache2 | 
 | 113 |         APACHE_CONF=vhosts.d/horizon.conf | 
| Vincent Untz | f2a18c0 | 2012-12-04 18:34:25 +0100 | [diff] [blame] | 114 |         # WSGI isn't enabled by default, enable it | 
 | 115 |         sudo a2enmod wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 116 |     else | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 117 |         exit_distro_not_supported "apache configuration" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 118 |     fi | 
 | 119 |  | 
 | 120 |     # Configure apache to run horizon | 
 | 121 |     sudo sh -c "sed -e \" | 
 | 122 |         s,%USER%,$APACHE_USER,g; | 
 | 123 |         s,%GROUP%,$APACHE_GROUP,g; | 
 | 124 |         s,%HORIZON_DIR%,$HORIZON_DIR,g; | 
 | 125 |         s,%APACHE_NAME%,$APACHE_NAME,g; | 
 | 126 |         s,%DEST%,$DEST,g; | 
 | 127 |     \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF" | 
 | 128 |  | 
 | 129 | } | 
 | 130 |  | 
 | 131 | # install_horizon() - Collect source and prepare | 
 | 132 | function install_horizon() { | 
 | 133 |     # Apache installation, because we mark it NOPRIME | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 134 |     if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 135 |         # Install apache2, which is NOPRIME'd | 
 | 136 |         install_package apache2 libapache2-mod-wsgi | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 137 |     elif is_fedora; then | 
 | 138 |         sudo rm -f /etc/httpd/conf.d/000-* | 
 | 139 |         install_package httpd mod_wsgi | 
| Vincent Untz | ca5c471 | 2012-11-21 17:45:49 +0100 | [diff] [blame] | 140 |     elif is_suse; then | 
 | 141 |         install_package apache2 apache2-mod_wsgi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 142 |     else | 
| Vincent Untz | 00011c0 | 2012-12-06 09:56:32 +0100 | [diff] [blame] | 143 |         exit_distro_not_supported "apache installation" | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 144 |     fi | 
 | 145 |  | 
 | 146 |     # NOTE(sdague) quantal changed the name of the node binary | 
| Vincent Untz | c18b965 | 2012-12-04 12:36:34 +0100 | [diff] [blame] | 147 |     if is_ubuntu; then | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 148 |         if [[ ! -e "/usr/bin/node" ]]; then | 
 | 149 |             install_package nodejs-legacy | 
 | 150 |         fi | 
 | 151 |     fi | 
 | 152 |  | 
 | 153 |     git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG | 
 | 154 | } | 
 | 155 |  | 
 | 156 | # start_horizon() - Start running processes, including screen | 
 | 157 | function start_horizon() { | 
 | 158 |     restart_service $APACHE_NAME | 
 | 159 |     screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log" | 
 | 160 | } | 
 | 161 |  | 
 | 162 | # stop_horizon() - Stop running processes (non-screen) | 
 | 163 | function stop_horizon() { | 
| Steven Dake | 532908f | 2013-01-14 11:35:17 -0700 | [diff] [blame] | 164 |     if is_ubuntu; then | 
 | 165 |         stop_service apache2 | 
 | 166 |     elif is_fedora; then | 
 | 167 |         stop_service httpd | 
 | 168 |     elif is_suse; then | 
 | 169 |         stop_service apache2 | 
 | 170 |     else | 
 | 171 |         exit_distro_not_supported "apache configuration" | 
 | 172 |     fi | 
| Sean Dague | b562e6a | 2012-11-19 16:00:01 -0500 | [diff] [blame] | 173 | } | 
 | 174 |  | 
 | 175 | # Restore xtrace | 
 | 176 | $XTRACE |