lib/horizon
e263c82e
 #!/bin/bash
 #
b562e6a7
 # lib/horizon
 # Functions to control the configuration and operation of the horizon service
 
 # Dependencies:
6a5aa7c6
 #
 # - ``functions`` file
 # - ``apache`` file
 # - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
b562e6a7
 
 # ``stack.sh`` calls the entry points in this order:
 #
6a5aa7c6
 # - install_horizon
 # - configure_horizon
 # - init_horizon
 # - start_horizon
 # - stop_horizon
 # - cleanup_horizon
b562e6a7
 
 # Save trace setting
523f4880
 _XTRACE_HORIZON=$(set +o | grep xtrace)
b562e6a7
 set +o xtrace
 
 
 # Defaults
 # --------
 
 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}
 
cc6b4435
 # Functions
 # ---------
 
b663b33f
 # utility method of setting python option
aee18c74
 function _horizon_config_set {
b663b33f
     local file=$1
     local section=$2
     local option=$3
     local value=$4
 
c31fa40b
     if [ -z "$section" ]; then
         sed -e "/^$option/d" -i $local_settings
         echo -e "\n$option=$value" >> $file
     elif grep -q "^$section" $file; then
ada886dd
         local line
         line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
b663b33f
         if [ -n "$line" ]; then
             sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
         else
95c93e2b
             sed -i -e "/^$section/a\    '$option': $value," $file
b663b33f
         fi
     else
         echo -e "\n\n$section = {\n    '$option': $value,\n}" >> $file
     fi
 }
b562e6a7
 
ad43b395
 
1a6d4492
 
b562e6a7
 # Entry Points
 # ------------
 
 # cleanup_horizon() - Remove residual data files, anything left over from previous
 # runs that a clean run would need to clean up
aee18c74
 function cleanup_horizon {
5631ca5e
     disable_apache_site horizon
     sudo rm -f $(apache_site_config_for horizon)
b562e6a7
 }
 
 # configure_horizon() - Set config files, create data dirs, etc
aee18c74
 function configure_horizon {
b562e6a7
     setup_develop $HORIZON_DIR
6518c0b8
 
     # Compile message catalogs.
     # Horizon is installed as develop mode, so we can compile here.
     # Message catalog compilation is handled by Django admin script,
     # so compiling them after the installation avoids Django installation twice.
51ecf0a8
     (cd $HORIZON_DIR; $PYTHON manage.py compilemessages)
b562e6a7
 
     # ``local_settings.py`` is used to override horizon default settings.
1bbfcc7a
     local local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
7104ab40
     cp $HORIZON_SETTINGS $local_settings
b562e6a7
 
7b105c57
     _horizon_config_set $local_settings "" WEBROOT \"$HORIZON_APACHE_ROOT/\"
 
45ce9827
     _horizon_config_set $local_settings "" COMPRESS_OFFLINE True
a7d0c6fa
     _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_DEFAULT_ROLE \"member\"
45ce9827
 
c31fa40b
     _horizon_config_set $local_settings "" OPENSTACK_HOST \"${KEYSTONE_SERVICE_HOST}\"
3fd71d68
 
05076fb7
     _horizon_config_set $local_settings "" OPENSTACK_API_VERSIONS {\"identity\":3}
e86b91ba
     _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_URL "\"${KEYSTONE_SERVICE_URI}/v3\""
c31fa40b
 
868a6631
     # note(trebskit): if HOST_IP points at non-localhost ip address, horizon cannot be accessed
     # from outside the virtual machine. This fixes is meant primarily for local development
     # purpose
     _horizon_config_set $local_settings "" ALLOWED_HOSTS [\"*\"]
 
c31fa40b
     if [ -f $SSL_BUNDLE_FILE ]; then
         _horizon_config_set $local_settings "" OPENSTACK_SSL_CACERT \"${SSL_BUNDLE_FILE}\"
     fi
cc363971
 
     if is_service_enabled ldap; then
         _horizon_config_set $local_settings "" OPENSTACK_KEYSTONE_MULTIDOMAIN_SUPPORT "True"
     fi
c31fa40b
 
b562e6a7
     # Create an empty directory that apache uses as docroot
     sudo mkdir -p $HORIZON_DIR/.blackhole
 
ada886dd
     local horizon_conf
     horizon_conf=$(apache_site_config_for horizon)
afda4efb
 
     # Configure apache to run horizon
43f62c08
     # Set up the django horizon application to serve via apache/wsgi
afda4efb
     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;
7b105c57
         s,%WEBROOT%,$HORIZON_APACHE_ROOT,g;
afda4efb
     \" $FILES/apache-horizon.template >$horizon_conf"
 
c18b9651
     if is_ubuntu; then
cbd97ca9
         disable_apache_site 000-default
d98a5d0a
         sudo touch $horizon_conf
5c4691af
     elif is_fedora || is_suse; then
3ac8612b
         : # nothing to do
b562e6a7
     else
15aa0fc3
         exit_distro_not_supported "horizon apache configuration"
b562e6a7
     fi
afda4efb
     enable_apache_site horizon
43f62c08
 }
b562e6a7
 
43f62c08
 # init_horizon() - Initialize databases, etc.
 function init_horizon {
dc97cb71
     # Remove old log files that could mess with how DevStack detects whether Horizon
1e4587ef
     # has been successfully started (see start_horizon() and functions::screen_it())
2f27a0ed
     # and run_process
1e4587ef
     sudo rm -f /var/log/$APACHE_NAME/horizon_*
 
088e6602
     # Setup alias for django-admin which could be different depending on distro
     local django_admin
     if type -p django-admin > /dev/null; then
         django_admin=django-admin
     else
         django_admin=django-admin.py
     fi
 
43f62c08
     # These need to be run after horizon plugins are configured.
088e6602
     DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin collectstatic --noinput
     DJANGO_SETTINGS_MODULE=openstack_dashboard.settings $django_admin compress --force
45ce9827
 
b562e6a7
 }
 
 # install_horizon() - Collect source and prepare
aee18c74
 function install_horizon {
b562e6a7
     # Apache installation, because we mark it NOPRIME
d98a5d0a
     install_apache_wsgi
b562e6a7
 
53753293
     git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH
b562e6a7
 }
 
0eebeb41
 # start_horizon() - Start running processes
aee18c74
 function start_horizon {
d98a5d0a
     restart_apache_server
b562e6a7
 }
 
0eebeb41
 # stop_horizon() - Stop running processes
aee18c74
 function stop_horizon {
d98a5d0a
     stop_apache_server
b562e6a7
 }
 
 # Restore xtrace
523f4880
 $_XTRACE_HORIZON
584d90ec
 
6a5aa7c6
 # Tell emacs to use shell-script-mode
 ## Local variables:
 ## mode: shell-script
 ## End: