blob: 05bf6d3915764214468903994df2622cd7e394c6 [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
Dean Troyercc6b4432013-04-08 15:38:03 -050041
42# Functions
43# ---------
44
Eugene Nikanorovb663b332013-03-07 16:10:10 +040045# utility method of setting python option
46function _horizon_config_set() {
47 local file=$1
48 local section=$2
49 local option=$3
50 local value=$4
51
52 if grep -q "^$section" $file; then
53 line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
54 if [ -n "$line" ]; then
55 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
56 else
57 sed -i -e "/^$section/ a\n '$option': $value,\n" $file
58 fi
59 else
60 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
61 fi
62}
Sean Dagueb562e6a2012-11-19 16:00:01 -050063
64# Entry Points
65# ------------
66
67# cleanup_horizon() - Remove residual data files, anything left over from previous
68# runs that a clean run would need to clean up
69function cleanup_horizon() {
70 # kill instances (nova)
71 # delete image files (glance)
72 # This function intentionally left blank
73 :
74}
75
76# configure_horizon() - Set config files, create data dirs, etc
77function configure_horizon() {
78 setup_develop $HORIZON_DIR
79}
80
81# init_horizon() - Initialize databases, etc.
82function init_horizon() {
83 # Remove stale session database.
84 rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
85
86 # ``local_settings.py`` is used to override horizon default settings.
87 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090088 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050089
Eugene Nikanorovb663b332013-03-07 16:10:10 +040090 # enable loadbalancer dashboard in case service is enabled
91 if is_service_enabled q-lbaas; then
92 _horizon_config_set $local_settings OPENSTACK_QUANTUM_NETWORK enable_lb True
93 fi
94
Sean Dagueb562e6a2012-11-19 16:00:01 -050095 # Initialize the horizon database (it stores sessions and notices shown to
96 # users). The user system is external (keystone).
97 cd $HORIZON_DIR
98 python manage.py syncdb --noinput
99 cd $TOP_DIR
100
101 # Create an empty directory that apache uses as docroot
102 sudo mkdir -p $HORIZON_DIR/.blackhole
103
104
Sunil Thaha627d9c72013-04-10 14:11:44 +1000105 HORIZON_REQUIRE=''
Vincent Untzc18b9652012-12-04 12:36:34 +0100106 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500107 APACHE_NAME=apache2
108 APACHE_CONF=sites-available/horizon
109 # Clean up the old config name
110 sudo rm -f /etc/apache2/sites-enabled/000-default
111 # Be a good citizen and use the distro tools here
112 sudo touch /etc/$APACHE_NAME/$APACHE_CONF
113 sudo a2ensite horizon
Vincent Untzf2a18c02012-12-04 18:34:25 +0100114 # WSGI isn't enabled by default, enable it
Sean Daguee1864c32012-11-29 14:20:34 -0500115 sudo a2enmod wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100116 elif is_fedora; then
117 APACHE_NAME=httpd
118 APACHE_CONF=conf.d/horizon.conf
Sunil Thaha627d9c72013-04-10 14:11:44 +1000119
120 if [[ "$os_RELEASE" -ge "18" ]]; then
121 # fedora 18 has Require all denied in its httpd.conf
122 # and requires explicit Require all granted
123 HORIZON_REQUIRE='Require all granted'
124 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100125 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
126 elif is_suse; then
127 APACHE_NAME=apache2
128 APACHE_CONF=vhosts.d/horizon.conf
Vincent Untzf2a18c02012-12-04 18:34:25 +0100129 # WSGI isn't enabled by default, enable it
130 sudo a2enmod wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500131 else
Vincent Untz00011c02012-12-06 09:56:32 +0100132 exit_distro_not_supported "apache configuration"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500133 fi
134
135 # Configure apache to run horizon
136 sudo sh -c "sed -e \"
137 s,%USER%,$APACHE_USER,g;
138 s,%GROUP%,$APACHE_GROUP,g;
139 s,%HORIZON_DIR%,$HORIZON_DIR,g;
140 s,%APACHE_NAME%,$APACHE_NAME,g;
141 s,%DEST%,$DEST,g;
Sunil Thaha627d9c72013-04-10 14:11:44 +1000142 s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g;
Sean Dagueb562e6a2012-11-19 16:00:01 -0500143 \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
144
145}
146
147# install_horizon() - Collect source and prepare
148function install_horizon() {
149 # Apache installation, because we mark it NOPRIME
Vincent Untzc18b9652012-12-04 12:36:34 +0100150 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500151 # Install apache2, which is NOPRIME'd
152 install_package apache2 libapache2-mod-wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100153 elif is_fedora; then
154 sudo rm -f /etc/httpd/conf.d/000-*
155 install_package httpd mod_wsgi
Vincent Untzca5c4712012-11-21 17:45:49 +0100156 elif is_suse; then
157 install_package apache2 apache2-mod_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500158 else
Vincent Untz00011c02012-12-06 09:56:32 +0100159 exit_distro_not_supported "apache installation"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500160 fi
161
162 # NOTE(sdague) quantal changed the name of the node binary
Vincent Untzc18b9652012-12-04 12:36:34 +0100163 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500164 if [[ ! -e "/usr/bin/node" ]]; then
165 install_package nodejs-legacy
166 fi
Sunil Thaha627d9c72013-04-10 14:11:44 +1000167 elif is_fedora && [[ "$os_RELEASE" -ge "18" ]]; then
168 # fedora 18 and higher gets nodejs
169 install_package nodejs
Sean Dagueb562e6a2012-11-19 16:00:01 -0500170 fi
171
172 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
173}
174
175# start_horizon() - Start running processes, including screen
176function start_horizon() {
177 restart_service $APACHE_NAME
178 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
179}
180
181# stop_horizon() - Stop running processes (non-screen)
182function stop_horizon() {
Steven Dake532908f2013-01-14 11:35:17 -0700183 if is_ubuntu; then
184 stop_service apache2
185 elif is_fedora; then
186 stop_service httpd
187 elif is_suse; then
188 stop_service apache2
189 else
190 exit_distro_not_supported "apache configuration"
191 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500192}
193
194# Restore xtrace
195$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400196
197# Local variables:
198# mode: shell-script
199# End: