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