blob: f88247cd0030b8cabfc91bc6819f39bd0b68c693 [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
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
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
27# <define global variables here that belong to this project>
28
29# Set up default directories
30HORIZON_DIR=$DEST/horizon
31
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090032# local_settings.py is used to customize Dashboard settings.
33# The example file in Horizon repo is used by default.
34HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
35
Martin Vidner2ed63f42012-12-04 10:33:49 +010036# Allow overriding the default Apache user and group, default to
37# current user and his default group.
Sean Dagueb562e6a2012-11-19 16:00:01 -050038APACHE_USER=${APACHE_USER:-$USER}
Martin Vidner2ed63f42012-12-04 10:33:49 +010039APACHE_GROUP=${APACHE_GROUP:-$(id -gn $APACHE_USER)}
Sean Dagueb562e6a2012-11-19 16:00:01 -050040
JordanP1e4587e2013-05-08 22:19:59 +020041# Set up service name and configuration path
42if is_ubuntu; then
43 APACHE_NAME=apache2
44 APACHE_CONF=sites-available/horizon
45elif is_fedora; then
46 APACHE_NAME=httpd
47 APACHE_CONF=conf.d/horizon.conf
48elif is_suse; then
49 APACHE_NAME=apache2
50 APACHE_CONF=vhosts.d/horizon.conf
51fi
52
Dean Troyercc6b4432013-04-08 15:38:03 -050053
54# Functions
55# ---------
56
Eugene Nikanorovb663b332013-03-07 16:10:10 +040057# utility method of setting python option
58function _horizon_config_set() {
59 local file=$1
60 local section=$2
61 local option=$3
62 local value=$4
63
64 if grep -q "^$section" $file; then
65 line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
66 if [ -n "$line" ]; then
67 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
68 else
69 sed -i -e "/^$section/ a\n '$option': $value,\n" $file
70 fi
71 else
72 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
73 fi
74}
Sean Dagueb562e6a2012-11-19 16:00:01 -050075
Ian Wienandad43b392013-04-11 11:13:09 +100076
Dean Troyer1a6d4492013-06-03 16:47:36 -050077
Sean Dagueb562e6a2012-11-19 16:00:01 -050078# Entry Points
79# ------------
80
81# cleanup_horizon() - Remove residual data files, anything left over from previous
82# runs that a clean run would need to clean up
83function cleanup_horizon() {
Dean Troyer1a6d4492013-06-03 16:47:36 -050084 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
85 # If ``/usr/bin/node`` points into ``$DEST``
86 # we installed it via ``install_nodejs``
87 if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
88 sudo rm /usr/bin/node
89 fi
90 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -050091}
92
93# configure_horizon() - Set config files, create data dirs, etc
94function configure_horizon() {
95 setup_develop $HORIZON_DIR
96}
97
98# init_horizon() - Initialize databases, etc.
99function init_horizon() {
100 # Remove stale session database.
101 rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
102
103 # ``local_settings.py`` is used to override horizon default settings.
104 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +0900105 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -0500106
Edgar Maganac973f122013-07-29 16:39:56 -0700107 if is_service_enabled neutron; then
108 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP
109 fi
Eugene Nikanorovb663b332013-03-07 16:10:10 +0400110 # enable loadbalancer dashboard in case service is enabled
111 if is_service_enabled q-lbaas; then
Nobuto MURATA73a39bf2013-07-11 16:26:02 +0900112 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True
Eugene Nikanorovb663b332013-03-07 16:10:10 +0400113 fi
114
Sean Dagueb562e6a2012-11-19 16:00:01 -0500115 # Initialize the horizon database (it stores sessions and notices shown to
116 # users). The user system is external (keystone).
117 cd $HORIZON_DIR
118 python manage.py syncdb --noinput
119 cd $TOP_DIR
120
121 # Create an empty directory that apache uses as docroot
122 sudo mkdir -p $HORIZON_DIR/.blackhole
123
Sunil Thaha627d9c72013-04-10 14:11:44 +1000124 HORIZON_REQUIRE=''
Vincent Untzc18b9652012-12-04 12:36:34 +0100125 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500126 # Clean up the old config name
127 sudo rm -f /etc/apache2/sites-enabled/000-default
128 # Be a good citizen and use the distro tools here
129 sudo touch /etc/$APACHE_NAME/$APACHE_CONF
130 sudo a2ensite horizon
Vincent Untzf2a18c02012-12-04 18:34:25 +0100131 # WSGI isn't enabled by default, enable it
Sean Daguee1864c32012-11-29 14:20:34 -0500132 sudo a2enmod wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100133 elif is_fedora; then
Sunil Thaha627d9c72013-04-10 14:11:44 +1000134 if [[ "$os_RELEASE" -ge "18" ]]; then
135 # fedora 18 has Require all denied in its httpd.conf
136 # and requires explicit Require all granted
137 HORIZON_REQUIRE='Require all granted'
138 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100139 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
140 elif is_suse; then
Vincent Untzf2a18c02012-12-04 18:34:25 +0100141 # WSGI isn't enabled by default, enable it
142 sudo a2enmod wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500143 else
Vincent Untz00011c02012-12-06 09:56:32 +0100144 exit_distro_not_supported "apache configuration"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500145 fi
146
JordanP1e4587e2013-05-08 22:19:59 +0200147 # Remove old log files that could mess with how devstack detects whether Horizon
148 # has been successfully started (see start_horizon() and functions::screen_it())
149 sudo rm -f /var/log/$APACHE_NAME/horizon_*
150
Sean Dagueb562e6a2012-11-19 16:00:01 -0500151 # Configure apache to run horizon
152 sudo sh -c "sed -e \"
153 s,%USER%,$APACHE_USER,g;
154 s,%GROUP%,$APACHE_GROUP,g;
155 s,%HORIZON_DIR%,$HORIZON_DIR,g;
156 s,%APACHE_NAME%,$APACHE_NAME,g;
157 s,%DEST%,$DEST,g;
Sunil Thaha627d9c72013-04-10 14:11:44 +1000158 s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g;
Sean Dagueb562e6a2012-11-19 16:00:01 -0500159 \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500160}
161
162# install_horizon() - Collect source and prepare
163function install_horizon() {
164 # Apache installation, because we mark it NOPRIME
Vincent Untzc18b9652012-12-04 12:36:34 +0100165 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500166 # Install apache2, which is NOPRIME'd
167 install_package apache2 libapache2-mod-wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100168 elif is_fedora; then
169 sudo rm -f /etc/httpd/conf.d/000-*
170 install_package httpd mod_wsgi
Vincent Untzca5c4712012-11-21 17:45:49 +0100171 elif is_suse; then
172 install_package apache2 apache2-mod_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500173 else
Vincent Untz00011c02012-12-06 09:56:32 +0100174 exit_distro_not_supported "apache installation"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500175 fi
176
177 # NOTE(sdague) quantal changed the name of the node binary
Vincent Untzc18b9652012-12-04 12:36:34 +0100178 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500179 if [[ ! -e "/usr/bin/node" ]]; then
180 install_package nodejs-legacy
181 fi
Ian Wienand2bda6cf2013-05-23 09:25:10 +1000182 elif is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -ge "18" ]]; then
Sunil Thaha627d9c72013-04-10 14:11:44 +1000183 install_package nodejs
Sean Dagueb562e6a2012-11-19 16:00:01 -0500184 fi
185
186 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
187}
188
189# start_horizon() - Start running processes, including screen
190function start_horizon() {
191 restart_service $APACHE_NAME
192 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
193}
194
195# stop_horizon() - Stop running processes (non-screen)
196function stop_horizon() {
JordanP1e4587e2013-05-08 22:19:59 +0200197 if [ -n "$APACHE_NAME" ]; then
198 stop_service $APACHE_NAME
Steven Dake532908f2013-01-14 11:35:17 -0700199 else
200 exit_distro_not_supported "apache configuration"
201 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500202}
203
Dean Troyer1a6d4492013-06-03 16:47:36 -0500204
Sean Dagueb562e6a2012-11-19 16:00:01 -0500205# Restore xtrace
206$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400207
208# Local variables:
209# mode: shell-script
210# End: