Changes to move upstart config building into pre_start
This commit is contained in:
parent
4b7b6239fb
commit
f3ce73cc53
conf/templates/general
devstack
@ -5,8 +5,8 @@
|
||||
author "%AUTHOR%"
|
||||
description "This is the upstart file for %SHORT_NAME% made on %MADE_DATE%"
|
||||
|
||||
start on %START_EVENT%
|
||||
stop on %STOP_EVENT%
|
||||
start on %START_EVENT% or %COMPONENT_START_EVENT%
|
||||
stop on %STOP_EVENT% or %COMPONENT_STOP_EVENT%
|
||||
|
||||
%RESPAWN%
|
||||
|
||||
|
@ -387,7 +387,24 @@ class ProgramRuntime(ComponentBase):
|
||||
}
|
||||
|
||||
def pre_start(self):
|
||||
pass
|
||||
run_type = utils.fetch_run_type(self.cfg)
|
||||
# Get access to the starter
|
||||
startercls = self._getstartercls(run_type)
|
||||
starter = startercls(self.cfg)
|
||||
#Do any configuration needed by the component
|
||||
apps = self._get_apps_to_start()
|
||||
for app_info in apps:
|
||||
#extract needed keys
|
||||
app_name = app_info["name"]
|
||||
app_pth = app_info.get("path", app_name)
|
||||
app_dir = app_info.get("app_dir", self.appdir)
|
||||
#adjust the program options now that we have real locations
|
||||
program_opts = utils.param_replace_list(self._get_app_options(app_name), self._get_param_map(app_name))
|
||||
#configure it with the given settings
|
||||
LOG.debug("Configure [%s] with options [%s] with runner type [%s]" % (app_name, ", ".join(program_opts), run_type))
|
||||
runtime_info = (app_pth, app_dir, program_opts)
|
||||
starter.configure(self.component_name, app_name, runtime_info, self.tracedir)
|
||||
LOG.debug("Configured %s" % (app_name))
|
||||
|
||||
def post_start(self):
|
||||
pass
|
||||
@ -401,21 +418,6 @@ class ProgramRuntime(ComponentBase):
|
||||
#this fns list will have info about what was started
|
||||
fns = list()
|
||||
apps = self._get_apps_to_start()
|
||||
# First make a pass and make sure all runtime (e.g. upstart) config
|
||||
# files are in place
|
||||
for app_info in apps:
|
||||
#extract needed keys
|
||||
app_name = app_info["name"]
|
||||
app_pth = app_info.get("path", app_name)
|
||||
app_dir = app_info.get("app_dir", self.appdir)
|
||||
#adjust the program options now that we have real locations
|
||||
program_opts = utils.param_replace_list(self._get_app_options(app_name), self._get_param_map(app_name))
|
||||
#configure it with the given settings
|
||||
LOG.debug("Configure [%s] with options [%s] with runner type [%s]" % (app_name, ", ".join(program_opts), run_type))
|
||||
runtime_info = (app_pth, app_dir, program_opts)
|
||||
starter.configure(app_name, runtime_info, self.tracedir)
|
||||
LOG.debug("Configured %s" % (app_name))
|
||||
# Make a second pass to do the actual starting
|
||||
for app_info in apps:
|
||||
#extract needed keys
|
||||
app_name = app_info["name"]
|
||||
|
@ -465,6 +465,8 @@ class NovaRuntime(comp.PythonRuntime):
|
||||
return result
|
||||
|
||||
def pre_start(self):
|
||||
# Let the parent class do its thing
|
||||
comp.PythonRuntime.pre_start(self)
|
||||
virt_driver = _canon_virt_driver(self.cfg.get('nova', 'virt_driver'))
|
||||
if virt_driver == virsh.VIRT_TYPE:
|
||||
virt_type = _canon_libvirt_type(self.cfg.get('nova', 'libvirt_type'))
|
||||
|
@ -20,5 +20,5 @@ class RunnerBase(object):
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
|
||||
def configure(self, app_name, runtime_info, tracedir):
|
||||
def configure(self, component_name, app_name, runtime_info, tracedir):
|
||||
return list()
|
||||
|
@ -16,6 +16,9 @@
|
||||
|
||||
import json
|
||||
|
||||
# To run the initctl command
|
||||
import subprocess
|
||||
|
||||
from runnerbase import RunnerBase
|
||||
from devstack import date
|
||||
from devstack import log as logging
|
||||
@ -35,6 +38,9 @@ UPSTART_TEMPL = "%s.upstart"
|
||||
ARGS = "ARGS"
|
||||
NAME = "NAME"
|
||||
|
||||
START_EVENT_SUFFIX = "_start"
|
||||
STOP_EVENT_SUFFIX = "_stop"
|
||||
|
||||
#where upstart configs go
|
||||
CONF_ROOT = "/etc/init"
|
||||
CONF_EXT = ".conf"
|
||||
@ -51,22 +57,24 @@ class UpstartRunner(RunnerBase):
|
||||
msg = "Not implemented yet"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
def configure(self, app_name, runtime_info, tracedir):
|
||||
def configure(self, component_name, app_name, runtime_info, tracedir):
|
||||
LOG.info("Configure called for app:%s" % (app_name))
|
||||
result = list()
|
||||
result.append(self._do_upstart_configure(app_name, app_name, runtime_info))
|
||||
result.append(self._do_upstart_configure(component_name, app_name, runtime_info))
|
||||
return result
|
||||
|
||||
def _get_upstart_conf_params(self, name, program_name, *program_args):
|
||||
def _get_upstart_conf_params(self, component_name, program_name, *program_args):
|
||||
params = dict()
|
||||
if self.cfg.getboolean('upstart', 'respawn'):
|
||||
params['RESPAWN'] = "respawn"
|
||||
else:
|
||||
params['RESPAWN'] = ""
|
||||
params['SHORT_NAME'] = program_name
|
||||
params['SHORT_NAME'] = program_name
|
||||
params['MADE_DATE'] = date.rcf8222date()
|
||||
params['START_EVENT'] = self.cfg.get('upstart', 'start_event')
|
||||
params['STOP_EVENT'] = self.cfg.get('upstart', 'stop_event')
|
||||
params['COMPONENT_START_EVENT'] = component_name + START_EVENT_SUFFIX
|
||||
params['COMPONENT_STOP_EVENT'] = component_name + STOP_EVENT_SUFFIX
|
||||
params['PROGRAM_NAME'] = sh.shellquote(program_name)
|
||||
params['AUTHOR'] = settings.PROG_NICE_NAME
|
||||
if program_args:
|
||||
@ -79,37 +87,40 @@ class UpstartRunner(RunnerBase):
|
||||
params['PROGRAM_OPTIONS'] = ''
|
||||
return params
|
||||
|
||||
def _do_upstart_configure(self, name, program_name, runtime_info):
|
||||
def _do_upstart_configure(self, component_name, program_name, runtime_info):
|
||||
(app_pth, app_dir, program_args) = runtime_info
|
||||
root_fn = name + CONF_EXT
|
||||
root_fn = program_name + CONF_EXT
|
||||
# TODO FIXME symlinks won't work. Need to copy the files there.
|
||||
# https://bugs.launchpad.net/upstart/+bug/665022
|
||||
cfg_fn = sh.joinpths(CONF_ROOT, root_fn)
|
||||
if sh.isfile(cfg_fn):
|
||||
LOG.debug("Upstart config file already exists:%s" % (cfg_fn))
|
||||
LOG.info("Upstart config file already exists:%s" % (cfg_fn))
|
||||
return
|
||||
LOG.debug("Loading upstart template to be used by: %s" % (cfg_fn))
|
||||
(_, contents) = utils.load_template('general', UPSTART_CONF_TMPL)
|
||||
params = self._get_upstart_conf_params(name, program_name, *program_args)
|
||||
params = self._get_upstart_conf_params(component_name, program_name, *program_args)
|
||||
adjusted_contents = utils.param_replace(contents, params)
|
||||
LOG.debug("Generated up start config for %s: %s" % (name, adjusted_contents))
|
||||
LOG.debug("Generated up start config for %s: %s" % (program_name, adjusted_contents))
|
||||
with sh.Rooted(True):
|
||||
sh.write_file(cfg_fn, adjusted_contents)
|
||||
sh.chmod(cfg_fn, 0666)
|
||||
return cfg_fn
|
||||
|
||||
def _start(self, name, program, *program_args, **kargs):
|
||||
tracedir = kargs["trace_dir"]
|
||||
def _start(self, name, program, program_args, tracedir):
|
||||
fn_name = UPSTART_TEMPL % (name)
|
||||
tracefn = tr.touch_trace(tracedir, fn_name)
|
||||
runtrace = tr.Trace(tracefn)
|
||||
runtrace.trace(TYPE, RUN_TYPE)
|
||||
runtrace.trace(NAME, name)
|
||||
runtrace.trace(ARGS, json.dumps(program_args))
|
||||
with sh.Rooted(True):
|
||||
# Emit the start, keep track and only do one per component name
|
||||
component_event = name + START_EVENT_SUFFIX
|
||||
LOG.info("About to emit event %s" % (component_event))
|
||||
rc = subprocess.call(["/sbin/initctl", "emit", component_event])
|
||||
LOG.error("Emit returned %s" % (rc))
|
||||
return tracefn
|
||||
|
||||
def start(self, name, runtime_info, tracedir):
|
||||
#(program, appdir, program_args) = runtime_info
|
||||
msg = "Not implemented yet"
|
||||
#raise NotImplementedError(msg)
|
||||
LOG.debug("Start called for %s" % (name))
|
||||
(program, appdir, program_args) = runtime_info
|
||||
return self._start(name, program, program_args, tracedir)
|
||||
|
Loading…
x
Reference in New Issue
Block a user