blob: c116ec257a002811493c659d78cc61d792e1241a [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
Sean Dagueb562e6a2012-11-19 16:00:01 -05003
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``apache`` file
8# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
Sean Dagueb562e6a2012-11-19 16:00:01 -05009
10# ``stack.sh`` calls the entry points in this order:
11#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010012# - install_horizon
13# - configure_horizon
14# - init_horizon
15# - start_horizon
16# - stop_horizon
17# - cleanup_horizon
Sean Dagueb562e6a2012-11-19 16:00:01 -050018
19# Save trace setting
20XTRACE=$(set +o | grep xtrace)
21set +o xtrace
22
23
24# Defaults
25# --------
26
Sean Dagueb562e6a2012-11-19 16:00:01 -050027# Set up default directories
28HORIZON_DIR=$DEST/horizon
29
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090030# local_settings.py is used to customize Dashboard settings.
31# The example file in Horizon repo is used by default.
32HORIZON_SETTINGS=${HORIZON_SETTINGS:-$HORIZON_DIR/openstack_dashboard/local/local_settings.py.example}
33
Dean Troyercc6b4432013-04-08 15:38:03 -050034
35# Functions
36# ---------
37
Eugene Nikanorovb663b332013-03-07 16:10:10 +040038# utility method of setting python option
39function _horizon_config_set() {
40 local file=$1
41 local section=$2
42 local option=$3
43 local value=$4
44
45 if grep -q "^$section" $file; then
46 line=$(sed -ne "/^$section/,/^}/ { /^ *'$option':/ p; }" $file)
47 if [ -n "$line" ]; then
48 sed -i -e "/^$section/,/^}/ s/^\( *'$option'\) *:.*$/\1: $value,/" $file
49 else
Ravi Chunduru95c93e22013-07-16 04:18:47 -070050 sed -i -e "/^$section/a\ '$option': $value," $file
Eugene Nikanorovb663b332013-03-07 16:10:10 +040051 fi
52 else
53 echo -e "\n\n$section = {\n '$option': $value,\n}" >> $file
54 fi
55}
Sean Dagueb562e6a2012-11-19 16:00:01 -050056
Ian Wienandad43b392013-04-11 11:13:09 +100057
Dean Troyer1a6d4492013-06-03 16:47:36 -050058
Sean Dagueb562e6a2012-11-19 16:00:01 -050059# Entry Points
60# ------------
61
62# cleanup_horizon() - Remove residual data files, anything left over from previous
63# runs that a clean run would need to clean up
64function cleanup_horizon() {
Dean Troyer1a6d4492013-06-03 16:47:36 -050065 if [[ is_fedora && $DISTRO =~ (rhel6) ]]; then
66 # If ``/usr/bin/node`` points into ``$DEST``
67 # we installed it via ``install_nodejs``
68 if [[ $(readlink -f /usr/bin/node) =~ ($DEST) ]]; then
69 sudo rm /usr/bin/node
70 fi
71 fi
Sean Dagueb562e6a2012-11-19 16:00:01 -050072}
73
74# configure_horizon() - Set config files, create data dirs, etc
75function configure_horizon() {
76 setup_develop $HORIZON_DIR
77}
78
79# init_horizon() - Initialize databases, etc.
80function init_horizon() {
81 # Remove stale session database.
82 rm -f $HORIZON_DIR/openstack_dashboard/local/dashboard_openstack.sqlite3
83
84 # ``local_settings.py`` is used to override horizon default settings.
85 local_settings=$HORIZON_DIR/openstack_dashboard/local/local_settings.py
Akihiro MOTOKI7104ab42013-03-27 19:47:11 +090086 cp $HORIZON_SETTINGS $local_settings
Sean Dagueb562e6a2012-11-19 16:00:01 -050087
Edgar Maganac973f122013-07-29 16:39:56 -070088 if is_service_enabled neutron; then
89 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_security_group $Q_USE_SECGROUP
90 fi
Eugene Nikanorovb663b332013-03-07 16:10:10 +040091 # enable loadbalancer dashboard in case service is enabled
92 if is_service_enabled q-lbaas; then
Nobuto MURATA73a39bf2013-07-11 16:26:02 +090093 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_lb True
Eugene Nikanorovb663b332013-03-07 16:10:10 +040094 fi
95
Ravi Chunduru95c93e22013-07-16 04:18:47 -070096 # enable firewall dashboard in case service is enabled
97 if is_service_enabled q-fwaas; then
98 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_firewall True
99 fi
100
Akihiro MOTOKIeaa9e1e2013-09-10 05:22:37 +0900101 # enable VPN dashboard in case service is enabled
102 if is_service_enabled q-vpn; then
103 _horizon_config_set $local_settings OPENSTACK_NEUTRON_NETWORK enable_vpn True
104 fi
105
Sean Dagueb562e6a2012-11-19 16:00:01 -0500106 # Initialize the horizon database (it stores sessions and notices shown to
107 # users). The user system is external (keystone).
108 cd $HORIZON_DIR
109 python manage.py syncdb --noinput
110 cd $TOP_DIR
111
112 # Create an empty directory that apache uses as docroot
113 sudo mkdir -p $HORIZON_DIR/.blackhole
114
Sunil Thaha627d9c72013-04-10 14:11:44 +1000115 HORIZON_REQUIRE=''
Attila Fazekas248a8cc2013-08-06 08:00:06 +0200116 local horizon_conf=/etc/$APACHE_NAME/$APACHE_CONF_DIR/horizon.conf
Vincent Untzc18b9652012-12-04 12:36:34 +0100117 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500118 # Clean up the old config name
119 sudo rm -f /etc/apache2/sites-enabled/000-default
120 # Be a good citizen and use the distro tools here
zhang-hared98a5d02013-06-21 18:18:02 +0800121 sudo touch $horizon_conf
Attila Fazekas248a8cc2013-08-06 08:00:06 +0200122 sudo a2ensite horizon.conf
Peter Feiner62e8a302013-10-24 17:49:00 -0400123 if [[ "$DISTRO" == "saucy" ]]; then
124 # Ubuntu 13.10 has Require all denied in apache2.conf
125 # and requires explicit Require all granted
126 HORIZON_REQUIRE='Require all granted'
127 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100128 elif is_fedora; then
Sunil Thaha627d9c72013-04-10 14:11:44 +1000129 if [[ "$os_RELEASE" -ge "18" ]]; then
130 # fedora 18 has Require all denied in its httpd.conf
131 # and requires explicit Require all granted
132 HORIZON_REQUIRE='Require all granted'
133 fi
Vincent Untz00011c02012-12-06 09:56:32 +0100134 sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
Adam Spiers3ac86122013-10-01 01:08:20 +0100135 elif is_suse; then
136 : # nothing to do
Sean Dagueb562e6a2012-11-19 16:00:01 -0500137 else
Adam Spiers15aa0fc2013-10-01 01:10:16 +0100138 exit_distro_not_supported "horizon apache configuration"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500139 fi
140
JordanP1e4587e2013-05-08 22:19:59 +0200141 # Remove old log files that could mess with how devstack detects whether Horizon
142 # has been successfully started (see start_horizon() and functions::screen_it())
143 sudo rm -f /var/log/$APACHE_NAME/horizon_*
144
Sean Dagueb562e6a2012-11-19 16:00:01 -0500145 # Configure apache to run horizon
146 sudo sh -c "sed -e \"
147 s,%USER%,$APACHE_USER,g;
148 s,%GROUP%,$APACHE_GROUP,g;
149 s,%HORIZON_DIR%,$HORIZON_DIR,g;
150 s,%APACHE_NAME%,$APACHE_NAME,g;
151 s,%DEST%,$DEST,g;
Sunil Thaha627d9c72013-04-10 14:11:44 +1000152 s,%HORIZON_REQUIRE%,$HORIZON_REQUIRE,g;
zhang-hared98a5d02013-06-21 18:18:02 +0800153 \" $FILES/apache-horizon.template >$horizon_conf"
Sean Dagueb562e6a2012-11-19 16:00:01 -0500154}
155
156# install_horizon() - Collect source and prepare
157function install_horizon() {
158 # Apache installation, because we mark it NOPRIME
zhang-hared98a5d02013-06-21 18:18:02 +0800159 install_apache_wsgi
Sean Dagueb562e6a2012-11-19 16:00:01 -0500160
161 # NOTE(sdague) quantal changed the name of the node binary
Vincent Untzc18b9652012-12-04 12:36:34 +0100162 if is_ubuntu; then
Sean Dagueb562e6a2012-11-19 16:00:01 -0500163 if [[ ! -e "/usr/bin/node" ]]; then
164 install_package nodejs-legacy
165 fi
Ian Wienand2bda6cf2013-05-23 09:25:10 +1000166 elif is_fedora && [[ $DISTRO =~ (rhel6) || "$os_RELEASE" -ge "18" ]]; then
Sunil Thaha627d9c72013-04-10 14:11:44 +1000167 install_package nodejs
Sean Dagueb562e6a2012-11-19 16:00:01 -0500168 fi
169
170 git_clone $HORIZON_REPO $HORIZON_DIR $HORIZON_BRANCH $HORIZON_TAG
171}
172
173# start_horizon() - Start running processes, including screen
174function start_horizon() {
zhang-hared98a5d02013-06-21 18:18:02 +0800175 restart_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500176 screen_it horizon "cd $HORIZON_DIR && sudo tail -f /var/log/$APACHE_NAME/horizon_error.log"
177}
178
179# stop_horizon() - Stop running processes (non-screen)
180function stop_horizon() {
zhang-hared98a5d02013-06-21 18:18:02 +0800181 stop_apache_server
Sean Dagueb562e6a2012-11-19 16:00:01 -0500182}
183
Dean Troyer1a6d4492013-06-03 16:47:36 -0500184
Sean Dagueb562e6a2012-11-19 16:00:01 -0500185# Restore xtrace
186$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400187
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100188# Tell emacs to use shell-script-mode
189## Local variables:
190## mode: shell-script
191## End: