blob: 1e758bfc43d68fea438d691d4aac15348c84017c [file] [log] [blame]
Sean Dagueb562e6a2012-11-19 16:00:01 -05001# 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
zhang-hared98a5d02013-06-21 18:18:02 +08007# ``apache`` file
Sean Dagueb562e6a2012-11-19 16:00:01 -05008# ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
9# <list other global vars that are assumed to be defined>
10
11# ``stack.sh`` calls the entry points in this order:
12#
13# install_horizon
14# configure_horizon
15# init_horizon
16# start_horizon
17# stop_horizon
18# cleanup_horizon
19
20# Save trace setting
21XTRACE=$(set +o | grep xtrace)
22set +o xtrace
23
24
25# Defaults
26# --------
27
28# <define global variables here that belong to this project>
29
30# Set up default directories
31HORIZON_DIR=$DEST/horizon
32
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090033# local_settings.py is used to customize Dashboard settings.
34# The example file in Horizon repo is used by default.
35HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
36
Dean Troyercc6b4432013-04-08 15:38:03 -050037
38# Functions
39# ---------
40
Eugene Nikanorovb663b332013-03-07 16:10:10 +040041# utility method of setting python option
42function _horizon_config_set() {
43 local file=$1
44 local section=$2
45 local option=$3
46 local value=$4
47
48 if grep -q "^$section" $file; then
49 line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
50 if [ -n "$line" ]; then
51 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
52 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070053 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040054 fi
55 else
56 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
57 fi
58}
Sean Dagueb562e6a2012-11-19 16:00:01 -050059
Ian Wienandad43b392013-04-11 11:13:09 +100060
Dean Troyer1a6d4492013-06-03 16:47:36 -050061
Sean Dagueb562e6a2012-11-19 16:00:01 -050062# Entry Points
63# ------------
64
65# cleanup_horizon() - Remove residual data files, anything left over from previous
66# runs that a clean run would need to clean up
67function cleanup_horizon() {
Dean Troyer1a6d4492013-06-03 16:47:36 -050068 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
69 # If ``/usr/bin/node`` points into ``$DEST``
70 # we installed it via ``install_nodejs``
71 if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
72 sudo rm /usr/bin/node
73 fi
74 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -050075}
76
77# configure_horizon() - Set config files, create data dirs, etc
78function configure_horizon() {
79 setup_develop $HORIZON_DIR
80}
81
82# init_horizon() - Initialize databases, etc.
83function init_horizon() {
84 # Remove stale session database.
85 rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
86
87 # ``local_settings.py`` is used to override horizon default settings.
88 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090089 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050090
Edgar Maganac973f122013-07-29 16:39:56 -070091 if is_service_enabled neutron; then
92 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP
93 fi
Eugene Nikanorovb663b332013-03-07 16:10:10 +040094 # enable loadbalancer dashboard in case service is enabled
95 if is_service_enabled q-lbaas; then
Nobuto MURATA73a39bf2013-07-11 16:26:02 +090096 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True
Eugene Nikanorovb663b332013-03-07 16:10:10 +040097 fi
98
Ravi Chunduru95c93e22013-07-16 04:18:47 -070099 # enable firewall dashboard in case service is enabled
100 if is_service_enabled q-fwaas; then
101 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_firewall True
102 fi
103
Sean Dagueb562e6a2012-11-19 16:00:01 -0500104 # Initialize the horizon database (it stores sessions and notices shown to
105 # users). The user system is external (keystone).
106 cd $HORIZON_DIR
107 python manage.py syncdb --noinput
108 cd $TOP_DIR
109
110 # Create an empty directory that apache uses as docroot
111 sudo mkdir -p $HORIZON_DIR/.blackhole
112
Sunil Thaha627d9c72013-04-10 14:11:44 +1000113 HORIZON_REQUIRE=''
zhang-hared98a5d02013-06-21 18:18:02 +0800114 local horizon_conf=/etc/$APACHE_NAME/$APACHE_CONF_DIR/horizon
Vincent Untzc18b9652012-12-04 12:36:34 +0100115 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500116 # Clean up the old config name
117 sudo rm -f /etc/apache2/sites-enabled/000-default
118 # Be a good citizen and use the distro tools here
zhang-hared98a5d02013-06-21 18:18:02 +0800119 sudo touch $horizon_conf
Sean Dagueb562e6a2012-11-19 16:00:01 -0500120 sudo a2ensite horizon
Vincent Untzf2a18c02012-12-04 18:34:25 +0100121 # WSGI isn't enabled by default, enable it
Sean Daguee1864c32012-11-29 14:20:34 -0500122 sudo a2enmod wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100123 elif is_fedora; then
Sunil Thaha627d9c72013-04-10 14:11:44 +1000124 if [[ "$os_RELEASE" -ge "18" ]]; then
125 # fedora 18 has Require all denied in its httpd.conf
126 # and requires explicit Require all granted
127 HORIZON_REQUIRE='Require all granted'
128 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100129 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
130 elif is_suse; then
Vincent Untzf2a18c02012-12-04 18:34:25 +0100131 # WSGI isn't enabled by default, enable it
132 sudo a2enmod wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500133 else
Vincent Untz00011c02012-12-06 09:56:32 +0100134 exit_distro_not_supported "apache configuration"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500135 fi
136
JordanP1e4587e2013-05-08 22:19:59 +0200137 # Remove old log files that could mess with how devstack detects whether Horizon
138 # has been successfully started (see start_horizon() and functions::screen_it())
139 sudo rm -f /var/log/$APACHE_NAME/horizon_*
140
Sean Dagueb562e6a2012-11-19 16:00:01 -0500141 # Configure apache to run horizon
142 sudo sh -c "sed -e \"
143 s,%USER%,$APACHE_USER,g;
144 s,%GROUP%,$APACHE_GROUP,g;
145 s,%HORIZON_DIR%,$HORIZON_DIR,g;
146 s,%APACHE_NAME%,$APACHE_NAME,g;
147 s,%DEST%,$DEST,g;
Sunil Thaha627d9c72013-04-10 14:11:44 +1000148 s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800149 \" $FILES/apache-horizon.template >$horizon_conf"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500150}
151
152# install_horizon() - Collect source and prepare
153function install_horizon() {
154 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800155 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500156
157 # NOTE(sdague) quantal changed the name of the node binary
Vincent Untzc18b9652012-12-04 12:36:34 +0100158 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500159 if [[ ! -e "/usr/bin/node" ]]; then
160 install_package nodejs-legacy
161 fi
Ian Wienand2bda6cf2013-05-23 09:25:10 +1000162 elif is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -ge "18" ]]; then
Sunil Thaha627d9c72013-04-10 14:11:44 +1000163 install_package nodejs
Sean Dagueb562e6a2012-11-19 16:00:01 -0500164 fi
165
166 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
167}
168
169# start_horizon() - Start running processes, including screen
170function start_horizon() {
zhang-hared98a5d02013-06-21 18:18:02 +0800171 restart_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500172 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
173}
174
175# stop_horizon() - Stop running processes (non-screen)
176function stop_horizon() {
zhang-hared98a5d02013-06-21 18:18:02 +0800177 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500178}
179
Dean Troyer1a6d4492013-06-03 16:47:36 -0500180
Sean Dagueb562e6a2012-11-19 16:00:01 -0500181# Restore xtrace
182$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400183
184# Local variables:
185# mode: shell-script
186# End: