lib/horizon
b562e6a7
 # lib/horizon
 # Functions to control the configuration and operation of the horizon service
 # <do not include this template file in ``stack.sh``!>
 
 # Dependencies:
 # ``functions`` file
 # ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
 # <list other global vars that are assumed to be defined>
 
 # ``stack.sh`` calls the entry points in this order:
 #
 # install_horizon
 # configure_horizon
 # init_horizon
 # start_horizon
 # stop_horizon
 # cleanup_horizon
 
 # Save trace setting
 XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
 
 # Defaults
 # --------
 
 # <define global variables here that belong to this project>
 
 # Set up default directories
 HORIZON_DIR=$DEST/horizon
 
7104ab40
 # local_settings.py is used to customize Dashboard settings.
 # The example file in Horizon repo is used by default.
 HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
 
2ed63f4f
 # Allow overriding the default Apache user and group, default to
 # current user and his default group.
b562e6a7
 APACHE_USER=${APACHE_USER:-$USER}
2ed63f4f
 APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)}
b562e6a7
 
b663b33f
 # utility method of setting python option
 function _horizon_config_set() {
     local file=$1
     local section=$2
     local option=$3
     local value=$4
 
     if grep -q "^$section" $file; then
         line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
         if [ -n "$line" ]; then
             sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
         else
             sed -i -e "/^$section/ a\n    '$option': $value,\n" $file
         fi
     else
         echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file
     fi
 }
b562e6a7
 
 # Entry Points
 # ------------
 
 # cleanup_horizon() - Remove residual data files, anything left over from previous
 # runs that a clean run would need to clean up
 function cleanup_horizon() {
     # kill instances (nova)
     # delete image files (glance)
     # This function intentionally left blank
     :
 }
 
 # configure_horizon() - Set config files, create data dirs, etc
 function configure_horizon() {
     setup_develop $HORIZON_DIR
 }
 
 # init_horizon() - Initialize databases, etc.
 function init_horizon() {
     # Remove stale session database.
     rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
 
     # ``local_settings.py`` is used to override horizon default settings.
     local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
7104ab40
     cp $HORIZON_SETTINGS $local_settings
b562e6a7
 
b663b33f
     # enable loadbalancer dashboard in case service is enabled
     if is_service_enabled q-lbaas; then
         _horizon_config_set $local_settings OPENSTACK_QUANTUM_NETWORK enable_lb True
     fi
 
b562e6a7
     # Initialize the horizon database (it stores sessions and notices shown to
     # users).  The user system is external (keystone).
     cd $HORIZON_DIR
     python manage.py syncdb --noinput
     cd $TOP_DIR
 
     # Create an empty directory that apache uses as docroot
     sudo mkdir -p $HORIZON_DIR/.blackhole
 
 
c18b9651
     if is_ubuntu; then
b562e6a7
         APACHE_NAME=apache2
         APACHE_CONF=sites-available/horizon
         # Clean up the old config name
         sudo rm -f /etc/apache2/sites-enabled/000-default
         # Be a good citizen and use the distro tools here
         sudo touch /etc/$APACHE_NAME/$APACHE_CONF
         sudo a2ensite horizon
f2a18c06
         # WSGI isn't enabled by default, enable it
e1864c37
         sudo a2enmod wsgi
00011c08
     elif is_fedora; then
         APACHE_NAME=httpd
         APACHE_CONF=conf.d/horizon.conf
         sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
     elif is_suse; then
         APACHE_NAME=apache2
         APACHE_CONF=vhosts.d/horizon.conf
f2a18c06
         # WSGI isn't enabled by default, enable it
         sudo a2enmod wsgi
b562e6a7
     else
00011c08
         exit_distro_not_supported "apache configuration"
b562e6a7
     fi
 
     # Configure apache to run horizon
     sudo sh -c "sed -e \"
         s,%USER%,$APACHE_USER,g;
         s,%GROUP%,$APACHE_GROUP,g;
         s,%HORIZON_DIR%,$HORIZON_DIR,g;
         s,%APACHE_NAME%,$APACHE_NAME,g;
         s,%DEST%,$DEST,g;
     \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
 
 }
 
 # install_horizon() - Collect source and prepare
 function install_horizon() {
     # Apache installation, because we mark it NOPRIME
c18b9651
     if is_ubuntu; then
b562e6a7
         # Install apache2, which is NOPRIME'd
         install_package apache2 libapache2-mod-wsgi
00011c08
     elif is_fedora; then
         sudo rm -f /etc/httpd/conf.d/000-*
         install_package httpd mod_wsgi
ca5c4713
     elif is_suse; then
         install_package apache2 apache2-mod_wsgi
b562e6a7
     else
00011c08
         exit_distro_not_supported "apache installation"
b562e6a7
     fi
 
     # NOTE(sdague) quantal changed the name of the node binary
c18b9651
     if is_ubuntu; then
b562e6a7
         if [[ ! -e "/usr/bin/node" ]]; then
             install_package nodejs-legacy
         fi
     fi
 
     git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
 }
 
 # start_horizon() - Start running processes, including screen
 function start_horizon() {
     restart_service $APACHE_NAME
     screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
 }
 
 # stop_horizon() - Stop running processes (non-screen)
 function stop_horizon() {
532908f6
     if is_ubuntu; then
         stop_service apache2
     elif is_fedora; then
         stop_service httpd
     elif is_suse; then
         stop_service apache2
     else
         exit_distro_not_supported "apache configuration"
     fi
b562e6a7
 }
 
 # Restore xtrace
 $XTRACE
584d90ec
 
 # Local variables:
 # mode: shell-script
 # End: