Continue working on getting horizon back in shape

This commit is contained in:
Joshua Harlow
2012-08-28 20:54:01 -07:00
parent d54afb7485
commit 8eb7f0d80c
5 changed files with 90 additions and 50 deletions

View File

@@ -37,7 +37,7 @@ DASH_NAME = 'dashboard'
# Config files messed with
HORIZON_PY_CONF = "horizon_settings.py"
HORIZON_APACHE_CONF = '000-default'
HORIZON_APACHE_CONF = 'horizon.conf'
CONFIGS = [HORIZON_PY_CONF, HORIZON_APACHE_CONF]
# DB sync that needs to happen for horizon
@@ -58,7 +58,13 @@ class HorizonUninstaller(comp.PythonUninstallComponent):
class HorizonInstaller(comp.PythonInstallComponent):
def __init__(self, *args, **kargs):
comp.PythonInstallComponent.__init__(self, *args, **kargs)
self.log_dir = sh.joinpths(self.get_option('component_dir'), 'logs')
self.blackhole_dir = sh.joinpths(self.get_option('app_dir'), '.blackhole')
self.access_log = sh.joinpths('/var/log/',
self.distro.get_command_config('apache', 'name'),
'horizon_access.log')
self.error_log = sh.joinpths('/var/log/',
self.distro.get_command_config('apache', 'name'),
'horizon_error.log')
def _filter_pip_requires_line(self, line):
# Knock off all nova, quantum, swift, keystone, cinder
@@ -75,14 +81,8 @@ class HorizonInstaller(comp.PythonInstallComponent):
@property
def symlinks(self):
links = super(HorizonInstaller, self).symlinks
tgt = self.distro.get_command_config('apache', 'settings', 'conf-link-target', quiet=True)
if not tgt:
return links
src = self.target_config(HORIZON_APACHE_CONF)
if src in links:
links[src].append(tgt)
else:
links[src] = [tgt]
links[self.access_log] = [sh.joinpths(self.link_dir, 'access.log')]
links[self.error_log] = [sh.joinpths(self.link_dir, 'error.log')]
return links
def _check_ug(self):
@@ -102,8 +102,7 @@ class HorizonInstaller(comp.PythonInstallComponent):
def target_config(self, config_name):
if config_name == HORIZON_PY_CONF:
# FIXME(harlowja) don't write to checked out locations...
dash_dir = sh.joinpths(self.get_option('app_dir'), ROOT_DASH)
return sh.joinpths(dash_dir, 'local', 'local_settings.py')
return sh.joinpths(self.get_option('app_dir'), ROOT_DASH, 'local', 'local_settings.py')
else:
return comp.PythonInstallComponent.target_config(self, config_name)
@@ -113,8 +112,20 @@ class HorizonInstaller(comp.PythonInstallComponent):
def _setup_blackhole(self):
# Create an empty directory that apache uses as docroot
black_hole_dir = sh.joinpths(self.get_option('app_dir'), '.blackhole')
self.tracewriter.dirs_made(*sh.mkdirslist(black_hole_dir))
self.tracewriter.dirs_made(*sh.mkdirslist(self.blackhole_dir))
def _setup_logs(self, clear):
log_fns = [self.access_log, self.error_log]
utils.log_iterable(log_fns, logger=LOG,
header="Adjusting %s log files" % (len(log_fns)))
for fn in log_fns:
with sh.Rooted(True):
if clear:
sh.unlink(fn, True)
sh.touch_file(fn, die_if_there=False)
sh.chmod(fn, 0666)
self.tracewriter.file_touched(fn)
return len(log_fns)
def _sync_db(self):
# Initialize the horizon database (it stores sessions and notices shown to users).
@@ -134,12 +145,10 @@ class HorizonInstaller(comp.PythonInstallComponent):
**utils.merge_dicts(self.get_option('db'),
dbhelper.get_shared_passwords(self)))
def pre_install(self):
comp.PythonInstallComponent.pre_install(self)
self.tracewriter.dirs_made(*sh.mkdirslist(self.log_dir))
def _config_fixups(self):
pass
def _configure_files(self):
am = comp.PythonInstallComponent._configure_files(self)
am += self._setup_logs(self.get_bool_option('clear-logs'))
return am
def post_install(self):
comp.PythonInstallComponent.post_install(self)
@@ -148,7 +157,6 @@ class HorizonInstaller(comp.PythonInstallComponent):
self._sync_db()
if self.get_bool_option('make-blackhole'):
self._setup_blackhole()
self._config_fixups()
def _get_apache_user_group(self):
return (self.get_option('apache_user'), self.get_option('apache_group'))
@@ -164,6 +172,9 @@ class HorizonInstaller(comp.PythonInstallComponent):
mp['HORIZON_DIR'] = self.get_option('app_dir')
mp['HORIZON_PORT'] = self.get_int_option('port', default_value=80)
mp['APACHE_NAME'] = self.distro.get_command_config('apache', 'name')
mp['ERROR_LOG'] = self.error_log
mp['ACCESS_LOG'] = self.access_log
mp['BLACK_HOLE_DIR'] = self.blackhole_dir
else:
mp['OPENSTACK_HOST'] = self.get_option('ip')
mp['DB_NAME'] = DB_NAME

View File

@@ -54,37 +54,32 @@ DEF_IDENT = 'unix-group:libvirtd'
class DBInstaller(db.DBInstaller):
MYSQL_CONF = '/etc/my.cnf'
def _configure_db_confs(self):
LOG.info("Fixing up %s mysql configs.", colorizer.quote(self.distro.name))
fc = sh.load_file('/etc/my.cnf')
lines = fc.splitlines()
new_lines = []
for line in lines:
for line in sh.load_file(DBInstaller.MYSQL_CONF).splitlines():
if line.startswith('skip-grant-tables'):
line = '#' + line
new_lines.append(line)
fc = utils.joinlinesep(*new_lines)
new_lines.append('#' + line)
elif line.startswith('bind-address'):
new_lines.append('#' + line)
new_lines.append('bind-address = 0.0.0.0')
else:
new_lines.append(line)
with sh.Rooted(True):
sh.write_file('/etc/my.cnf', fc)
sh.write_file_and_backup(DBInstaller.MYSQL_CONF, utils.joinlinesep(*new_lines))
class HorizonInstaller(horizon.HorizonInstaller):
def _config_fix_wsgi(self):
# This is recorded so it gets cleaned up during uninstall
self.tracewriter.file_touched("/etc/httpd/conf.d/wsgi-socket-prefix.conf")
LOG.info("Fixing up: %s", colorizer.quote("/etc/httpd/conf.d/wsgi-socket-prefix.conf"))
contents = "WSGISocketPrefix %s" % (sh.joinpths(self.log_dir, "wsgi-socket"))
with sh.Rooted(True):
# The name seems to need to come after wsgi.conf (so thats what we are doing)
sh.write_file("/etc/httpd/conf.d/wsgi-socket-prefix.conf", contents)
HTTPD_CONF = '/etc/httpd/conf/httpd.conf'
def _config_fix_httpd(self):
LOG.info("Fixing up: %s", colorizer.quote('/etc/httpd/conf/httpd.conf'))
LOG.info("Fixing up: %s", colorizer.quote(HorizonInstaller.HTTPD_CONF))
(user, group) = self._get_apache_user_group()
old_lines = sh.load_file('/etc/httpd/conf/httpd.conf').splitlines()
new_lines = list()
for line in old_lines:
new_lines = []
for line in sh.load_file(HorizonInstaller.HTTPD_CONF).splitlines():
# Directives in the configuration files are case-insensitive,
# but arguments to directives are often case sensitive...
# NOTE(harlowja): we aren't handling multi-line fixups...
@@ -95,14 +90,26 @@ class HorizonInstaller(horizon.HorizonInstaller):
if re.match("^\s*Listen\s+(.*)$", line, re.I):
line = "Listen 0.0.0.0:80"
new_lines.append(line)
contents = utils.joinlinesep(*new_lines)
with sh.Rooted(True):
sh.write_file('/etc/httpd/conf/httpd.conf', contents)
sh.write_file_and_backup(HorizonInstaller.HTTPD_CONF, utils.joinlinesep(*new_lines))
def _config_fixups(self):
self._config_fix_wsgi()
self._config_fix_httpd()
def post_install(self):
horizon.HorizonInstaller.post_install(self)
self._config_fixups()
@property
def symlinks(self):
links = super(HorizonInstaller, self).symlinks
links[self.target_config(horizon.HORIZON_APACHE_CONF)].append(sh.joinpths('/etc/',
self.distro.get_command_config('apache', 'name'),
'conf.d',
horizon.HORIZON_APACHE_CONF))
return links
class RabbitRuntime(rabbit.RabbitRuntime):

View File

@@ -250,6 +250,10 @@ def shellquote(text):
return text
def fileperms(path):
return (os.stat(path).st_mode & 0777)
def listdir(path):
return os.listdir(path)
@@ -655,6 +659,23 @@ def move(src, dst):
return dst
def write_file_and_backup(path, contents, bk_ext='org'):
perms = None
backup_path = None
if isfile(path):
perms = fileperms(path)
backup_path = "%s.%s" % (path, bk_ext)
if not isfile(backup_path):
LOG.debug("Backing up %s => %s", path, backup_path)
move(path, backup_path)
else:
LOG.debug("Leaving original backup of %s at %s", path, backup_path)
write_file(path, contents)
if perms is not None:
chmod(path, perms)
return backup_path
def chmod(fname, mode):
LOG.debug("Applying chmod: %r to %o" % (fname, mode))
if not is_dry_run():

View File

@@ -7,8 +7,6 @@ commands:
apache:
name: httpd
restart: service httpd restart
settings:
conf-link-target: /etc/httpd/conf.d/horizon.conf
start: service httpd start
status: service httpd status
stop: service httpd stop

View File

@@ -2,14 +2,17 @@
This is a cheetah template!
*#
<VirtualHost *:$HORIZON_PORT>
WSGIScriptAlias / $HORIZON_DIR/openstack_dashboard/wsgi/django.wsgi
WSGIScriptAlias / ${HORIZON_DIR}/openstack_dashboard/wsgi/django.wsgi
WSGIDaemonProcess horizon user=$USER group=$GROUP processes=3 threads=10 home=$HORIZON_DIR
WSGIApplicationGroup %{GLOBAL}
SetEnv APACHE_RUN_USER $USER
SetEnv APACHE_RUN_GROUP $GROUP
WSGIProcessGroup horizon
DocumentRoot $HORIZON_DIR/.blackhole/
#if $BLACK_HOLE_DIR
DocumentRoot $BLACK_HOLE_DIR
#end if
Alias /media $HORIZON_DIR/openstack_dashboard/static
<Directory />
@@ -17,15 +20,15 @@
AllowOverride None
</Directory>
<Directory $HORIZON_DIR/>
<Directory ${HORIZON_DIR}>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/$APACHE_NAME/horizon_error.log
CustomLog /var/log/$APACHE_NAME/horizon_access.log combined
ErrorLog ${ERROR_LOG}
CustomLog ${ACCESS_LOG} combined
LogLevel warn
</VirtualHost>