Moving upstart stuff to runners where it should be.
This commit is contained in:
parent
96884e3e4b
commit
53d1c7c38d
@ -1,11 +1,12 @@
|
||||
# This is a primative starting point for generic upstart configuration files
|
||||
# for various nova components.
|
||||
author "DevstackPy"
|
||||
description "This is the upstart file for %IMAGE%"
|
||||
# This is a primative starting point for
|
||||
# generic upstart configuration files
|
||||
# for various openstack components.
|
||||
author "%AUTHOR%"
|
||||
description "This is the upstart file for %SHORT_NAME% made on %MADE_DATE%"
|
||||
|
||||
start on %START_EVENT%
|
||||
stop on %STOP_EVENT%
|
||||
|
||||
%RESPAWN%
|
||||
|
||||
exec python %BINDIR%/%IMAGE% --flagfile %CFGFILE%
|
||||
exec %PROGRAM_NAME% %PROGRAM_OPTIONS%
|
||||
|
@ -24,6 +24,7 @@ from devstack import trace as tr
|
||||
from devstack import utils
|
||||
|
||||
from devstack.runners import fork
|
||||
from devstack.runners import upstart
|
||||
|
||||
LOG = logging.getLogger("devstack.component")
|
||||
|
||||
@ -345,9 +346,11 @@ class ProgramRuntime(ComponentBase):
|
||||
#what classes handle different running/stopping types
|
||||
STARTER_CLS_MAPPING = {
|
||||
settings.RUN_TYPE_FORK: fork.ForkRunner,
|
||||
settings.RUN_TYPE_UPSTART: upstart.UpstartRunner,
|
||||
}
|
||||
STOPPER_CLS_MAPPING = {
|
||||
settings.RUN_TYPE_FORK: fork.ForkRunner,
|
||||
settings.RUN_TYPE_UPSTART: upstart.UpstartRunner,
|
||||
}
|
||||
|
||||
def __init__(self, component_name, *args, **kargs):
|
||||
@ -390,7 +393,7 @@ class ProgramRuntime(ComponentBase):
|
||||
msg = "Unknown run type %s found in configuration" % (run_type)
|
||||
raise excp.ConfigException(msg)
|
||||
startercls = self._getstartercls(run_type)
|
||||
starter = startercls()
|
||||
starter = startercls(self.cfg)
|
||||
#start all apps
|
||||
#this fns list will have info about what was started
|
||||
fns = list()
|
||||
@ -437,7 +440,7 @@ class ProgramRuntime(ComponentBase):
|
||||
killcls = None
|
||||
runtype = None
|
||||
for (cmd, action) in contents:
|
||||
if cmd == settings.RUN_TYPE_TYPE:
|
||||
if cmd == settings.RUN_TYPE_TYPE and action:
|
||||
runtype = action
|
||||
killcls = self._getstoppercls(runtype)
|
||||
break
|
||||
@ -446,7 +449,7 @@ class ProgramRuntime(ComponentBase):
|
||||
#we can try to stop it
|
||||
LOG.debug("Stopping %s of run type %s" % (name, runtype))
|
||||
#create an instance of the killer class and attempt to stop
|
||||
killer = killcls()
|
||||
killer = killcls(self.cfg)
|
||||
killer.stop(name, trace_dir=self.tracedir)
|
||||
killedam += 1
|
||||
else:
|
||||
|
@ -268,10 +268,6 @@ class NovaInstaller(comp.PythonInstallComponent):
|
||||
self.xvnc_enabled = False
|
||||
if not self.component_opts or NXVNC in self.component_opts:
|
||||
self.xvnc_enabled = True
|
||||
self.run_type = utils.fetch_run_type(self.cfg)
|
||||
self.upstart_on = False
|
||||
if self.run_type == settings.RUN_TYPE_UPSTART:
|
||||
self.upstart_on = True
|
||||
|
||||
def _get_pkgs(self):
|
||||
pkgs = list(REQ_PKGS)
|
||||
@ -284,17 +280,8 @@ class NovaInstaller(comp.PythonInstallComponent):
|
||||
def _get_symlinks(self):
|
||||
links = dict()
|
||||
for fn in self._get_config_files():
|
||||
LOG.info("getting symlink for fn:%s" % (fn))
|
||||
source_fn = self._get_target_config_name(fn)
|
||||
LOG.info("symlink for source_fn:%s" % (source_fn))
|
||||
# Anything in APP_OPTIONS is actually an upstart config and will go into /etc/init
|
||||
# TODO FIXME symlinks won't work. Need to copy the files there.
|
||||
# https://bugs.launchpad.net/upstart/+bug/665022
|
||||
if fn in APP_OPTIONS and self.upstart_on:
|
||||
#links[source_fn] = sh.joinpths("/", "etc", "init", fn + ".conf")
|
||||
pass
|
||||
elif fn in CONFIGS:
|
||||
links[source_fn] = sh.joinpths("/", "etc", "nova", fn)
|
||||
links[source_fn] = sh.joinpths("/", "etc", "nova", fn)
|
||||
source_fn = sh.joinpths(self.cfgdir, API_CONF)
|
||||
links[source_fn] = sh.joinpths("/", "etc", "nova", API_CONF)
|
||||
return links
|
||||
@ -316,9 +303,6 @@ class NovaInstaller(comp.PythonInstallComponent):
|
||||
|
||||
def _get_config_files(self):
|
||||
cfg_files = list(CONFIGS)
|
||||
if self.upstart_on:
|
||||
# We'll include the keys from APP_OPTIONS since we want to create upstart config files for those.
|
||||
cfg_files.extend(APP_OPTIONS.keys())
|
||||
return cfg_files
|
||||
|
||||
def _setup_network(self):
|
||||
@ -409,43 +393,12 @@ class NovaInstaller(comp.PythonInstallComponent):
|
||||
name = PASTE_SOURCE_FN
|
||||
elif config_fn == LOGGING_CONF:
|
||||
name = LOGGING_SOURCE_FN
|
||||
elif config_fn in APP_OPTIONS and self.upstart_on:
|
||||
# This is one of the upstart configs, use our general template for the source
|
||||
LOG.debug("Loading upstart template to be used by: %s" % (config_fn))
|
||||
(_, contents) = utils.load_template('general', settings.UPSTART_CONF_TMPL)
|
||||
return (config_fn, contents)
|
||||
# It's not an upstart, go get it from the nova conf dir
|
||||
srcfn = sh.joinpths(self.cfgdir, "nova", name)
|
||||
contents = sh.load_file(srcfn)
|
||||
return (srcfn, contents)
|
||||
|
||||
def _get_target_config_name(self, config_fn):
|
||||
if config_fn in APP_OPTIONS and self.upstart_on:
|
||||
# This is one of the upstart configs. It'll eventually get
|
||||
# symlinked to /etc/init. Use the APP_OPTIONS key as the base filename
|
||||
return sh.joinpths(self.cfgdir, config_fn + ".conf")
|
||||
else:
|
||||
# It's not an upstart config, just do what we used to do
|
||||
return comp.PythonInstallComponent._get_target_config_name(self, config_fn)
|
||||
|
||||
def _get_param_map(self, config_fn):
|
||||
if config_fn in APP_OPTIONS and self.upstart_on:
|
||||
# We're processing an upstart config file. We'll need to set
|
||||
# specific values from the general upstart config template
|
||||
LOG.debug("Returning parms for update config: %s" % (config_fn))
|
||||
params = dict()
|
||||
params['CFGFILE'] = sh.joinpths(self.cfgdir, API_CONF)
|
||||
params['BINDIR'] = self.bindir
|
||||
params['IMAGE'] = config_fn
|
||||
if self.cfg.getboolean('upstart', 'respawn'):
|
||||
params['RESPAWN'] = "respawn"
|
||||
else:
|
||||
params['RESPAWN'] = ""
|
||||
params['START_EVENT'] = self.cfg.get('upstart', 'start_event')
|
||||
params['STOP_EVENT'] = self.cfg.get('upstart', 'stop_event')
|
||||
return params
|
||||
else:
|
||||
return keystone.get_shared_params(self.cfg)
|
||||
return keystone.get_shared_params(self.cfg)
|
||||
|
||||
def configure(self):
|
||||
configs_made = comp.PythonInstallComponent.configure(self)
|
||||
|
@ -51,8 +51,8 @@ FORK_TEMPL = "%s.fork"
|
||||
|
||||
|
||||
class ForkRunner(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
|
||||
def _stop_pid(self, pid):
|
||||
killed = False
|
||||
@ -161,7 +161,7 @@ class ForkRunner(object):
|
||||
#be bad right now
|
||||
os._exit(0)
|
||||
|
||||
def start(self, name, program, *args, **kargs):
|
||||
def start(self, name, program, *program_args, **kargs):
|
||||
tracedir = kargs.get("trace_dir")
|
||||
appdir = kargs.get("app_dir")
|
||||
fn_name = FORK_TEMPL % (name)
|
||||
@ -172,8 +172,8 @@ class ForkRunner(object):
|
||||
runtrace.trace(PID_FN, pidfile)
|
||||
runtrace.trace(STDERR_FN, stderrfn)
|
||||
runtrace.trace(STDOUT_FN, stdoutfn)
|
||||
runtrace.trace(ARGS, json.dumps(args))
|
||||
runtrace.trace(ARGS, json.dumps(program_args))
|
||||
LOG.debug("Forking [%s] by running command [%s]" % (name, program))
|
||||
with sh.Rooted(kargs.get("run_as_root", True)):
|
||||
self._fork_start(program, appdir, pidfile, stdoutfn, stderrfn, *args)
|
||||
self._fork_start(program, appdir, pidfile, stdoutfn, stderrfn, *program_args)
|
||||
return tracefn
|
||||
|
102
devstack/runners/upstart.py
Normal file
102
devstack/runners/upstart.py
Normal file
@ -0,0 +1,102 @@
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright (C) 2012 Yahoo! Inc. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
|
||||
from devstack import date
|
||||
from devstack import log as logging
|
||||
from devstack import settings
|
||||
from devstack import shell as sh
|
||||
from devstack import trace as tr
|
||||
from devstack import utils
|
||||
|
||||
LOG = logging.getLogger("devstack.runners.upstart")
|
||||
|
||||
#my type
|
||||
RUN_TYPE = settings.RUN_TYPE_UPSTART
|
||||
TYPE = settings.RUN_TYPE_TYPE
|
||||
|
||||
#trace constants
|
||||
UPSTART_TEMPL = "%s.upstart"
|
||||
ARGS = "ARGS"
|
||||
NAME = "NAME"
|
||||
|
||||
#where upstart configs go
|
||||
CONF_ROOT = "/etc/init"
|
||||
CONF_EXT = ".conf"
|
||||
|
||||
#shared template
|
||||
UPSTART_CONF_TMPL = 'upstart.conf'
|
||||
|
||||
|
||||
class UpstartRunner(object):
|
||||
def __init__(self, cfg):
|
||||
self.cfg = cfg
|
||||
|
||||
def stop(self, name, *args, **kargs):
|
||||
msg = "Not implemented yet"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
def _get_upstart_conf_params(self, name, program_name, *program_args):
|
||||
params = dict()
|
||||
if self.cfg.getboolean('upstart', 'respawn'):
|
||||
params['RESPAWN'] = "respawn"
|
||||
else:
|
||||
params['RESPAWN'] = ""
|
||||
params['SHORT_NAME'] = 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['PROGRAM_NAME'] = sh.shellquote(program_name)
|
||||
params['AUTHOR'] = settings.PROG_NICE_NAME
|
||||
if program_args:
|
||||
escaped_args = list()
|
||||
for opt in program_args:
|
||||
escaped_args.append(sh.shellquote(opt))
|
||||
params['PROGRAM_OPTIONS'] = " ".join(escaped_args)
|
||||
else:
|
||||
params['PROGRAM_OPTIONS'] = ''
|
||||
return params
|
||||
|
||||
def _do_upstart_configure(self, name, program_name, *program_args):
|
||||
root_fn = 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):
|
||||
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)
|
||||
adjusted_contents = utils.param_replace(contents, params)
|
||||
LOG.debug("Generated up start config for %s: %s" % (name, adjusted_contents))
|
||||
with sh.Rooted(True):
|
||||
sh.write_file(cfg_fn, adjusted_contents)
|
||||
sh.chmod(cfg_fn, 0666)
|
||||
|
||||
def _start(self, name, program, *program_args, **kargs):
|
||||
tracedir = kargs.get("trace_dir")
|
||||
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))
|
||||
return tracefn
|
||||
|
||||
def start(self, name, program, *program_args, **kargs):
|
||||
msg = "Not implemented yet"
|
||||
raise NotImplementedError(msg)
|
@ -99,9 +99,6 @@ RUN_TYPES_KNOWN = [RUN_TYPE_UPSTART, RUN_TYPE_FORK, RUN_TYPE_DEF]
|
||||
# Used to find the type in trace files
|
||||
RUN_TYPE_TYPE = "TYPE"
|
||||
|
||||
# Shared template
|
||||
UPSTART_CONF_TMPL = 'upstart.conf'
|
||||
|
||||
# Default subdirs of a components root directory
|
||||
COMPONENT_TRACE_DIR = "traces"
|
||||
COMPONENT_APP_DIR = "app"
|
||||
|
Loading…
x
Reference in New Issue
Block a user