blob: b63e1f8b0145d9b40e68c0344fcd527f808969cd [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
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
53 sed -i -e "/^$section/ a\n '$option': $value,\n" $file
54 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
60# Entry Points
61# ------------
62
63# cleanup_horizon() - Remove residual data files, anything left over from previous
64# runs that a clean run would need to clean up
65function cleanup_horizon() {
66 # kill instances (nova)
67 # delete image files (glance)
68 # This function intentionally left blank
69 :
70}
71
72# configure_horizon() - Set config files, create data dirs, etc
73function configure_horizon() {
74 setup_develop $HORIZON_DIR
75}
76
77# init_horizon() - Initialize databases, etc.
78function init_horizon() {
79 # Remove stale session database.
80 rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
81
82 # ``local_settings.py`` is used to override horizon default settings.
83 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090084 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050085
Eugene Nikanorovb663b332013-03-07 16:10:10 +040086 # enable loadbalancer dashboard in case service is enabled
87 if is_service_enabled q-lbaas; then
88 _horizon_config_set $local_settings OPENSTACK_QUANTUM_NETWORK enable_lb True
89 fi
90
Sean Dagueb562e6a2012-11-19 16:00:01 -050091 # Initialize the horizon database (it stores sessions and notices shown to
92 # users). The user system is external (keystone).
93 cd $HORIZON_DIR
94 python manage.py syncdb --noinput
95 cd $TOP_DIR
96
97 # Create an empty directory that apache uses as docroot
98 sudo mkdir -p $HORIZON_DIR/.blackhole
99
100
Vincent Untzc18b9652012-12-04 12:36:34 +0100101 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500102 APACHE_NAME=apache2
103 APACHE_CONF=sites-available/horizon
104 # Clean up the old config name
105 sudo rm -f /etc/apache2/sites-enabled/000-default
106 # Be a good citizen and use the distro tools here
107 sudo touch /etc/$APACHE_NAME/$APACHE_CONF
108 sudo a2ensite horizon
Vincent Untzf2a18c02012-12-04 18:34:25 +0100109 # WSGI isn't enabled by default, enable it
Sean Daguee1864c32012-11-29 14:20:34 -0500110 sudo a2enmod wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100111 elif is_fedora; then
112 APACHE_NAME=httpd
113 APACHE_CONF=conf.d/horizon.conf
114 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
115 elif is_suse; then
116 APACHE_NAME=apache2
117 APACHE_CONF=vhosts.d/horizon.conf
Vincent Untzf2a18c02012-12-04 18:34:25 +0100118 # WSGI isn't enabled by default, enable it
119 sudo a2enmod wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500120 else
Vincent Untz00011c02012-12-06 09:56:32 +0100121 exit_distro_not_supported "apache configuration"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500122 fi
123
124 # Configure apache to run horizon
125 sudo sh -c "sed -e \"
126 s,%USER%,$APACHE_USER,g;
127 s,%GROUP%,$APACHE_GROUP,g;
128 s,%HORIZON_DIR%,$HORIZON_DIR,g;
129 s,%APACHE_NAME%,$APACHE_NAME,g;
130 s,%DEST%,$DEST,g;
131 \" $FILES/apache-horizon.template >/etc/$APACHE_NAME/$APACHE_CONF"
132
133}
134
135# install_horizon() - Collect source and prepare
136function install_horizon() {
137 # Apache installation, because we mark it NOPRIME
Vincent Untzc18b9652012-12-04 12:36:34 +0100138 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500139 # Install apache2, which is NOPRIME'd
140 install_package apache2 libapache2-mod-wsgi
Vincent Untz00011c02012-12-06 09:56:32 +0100141 elif is_fedora; then
142 sudo rm -f /etc/httpd/conf.d/000-*
143 install_package httpd mod_wsgi
Vincent Untzca5c4712012-11-21 17:45:49 +0100144 elif is_suse; then
145 install_package apache2 apache2-mod_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500146 else
Vincent Untz00011c02012-12-06 09:56:32 +0100147 exit_distro_not_supported "apache installation"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500148 fi
149
150 # NOTE(sdague) quantal changed the name of the node binary
Vincent Untzc18b9652012-12-04 12:36:34 +0100151 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500152 if [[ ! -e "/usr/bin/node" ]]; then
153 install_package nodejs-legacy
154 fi
155 fi
156
157 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
158}
159
160# start_horizon() - Start running processes, including screen
161function start_horizon() {
162 restart_service $APACHE_NAME
163 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
164}
165
166# stop_horizon() - Stop running processes (non-screen)
167function stop_horizon() {
Steven Dake532908f2013-01-14 11:35:17 -0700168 if is_ubuntu; then
169 stop_service apache2
170 elif is_fedora; then
171 stop_service httpd
172 elif is_suse; then
173 stop_service apache2
174 else
175 exit_distro_not_supported "apache configuration"
176 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500177}
178
179# Restore xtrace
180$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400181
182# Local variables:
183# mode: shell-script
184# End: