Coverage for ion/core/cc/service : 70.16%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#!/usr/bin/env python
@author Dorian Raymer @author Michael Meisinger @brief Python Capability Container Twisted application plugin for twistd """
""" Extra arg for file of "program"/"module" to run. This class must be named Options with the usage.Options base class for the Twisted ServiceMaker to find it. """
["sysname", "s", None, "System name for group of capability containers" ], ["broker_host", "h", "localhost", "Message space broker hostname"], ["broker_port", "p", 5672, "Message space broker port"], ["broker_vhost", "v", "/", "Message space..."], ["broker_heartbeat", None, 30, "Heartbeat rate [seconds]"], ["broker_username", None, "guest", "Username to log into virtual host as"], ["broker_password", None, "guest", ""], ["broker_credfile", None, None, "File containing broker username and password"], ["boot_script", "b", None, "Boot script (python source)."], ["lockfile", None, None, "Lockfile used to denote container startup completion"], ["args", "a", '', "Additional startup arguments such as sysname=me" ], ] ["no_shell", "n", "Do not start shell"], ["no_history", "i", "Do not read/write history file"], ["no_dbmanhole", None, "Do not start dbmanhole"], ]
from ion import version print "ION Capability Container version:", version.short() sys.exit(0)
""" Gets a list of apps/rels/scripts to run as additional arguments to the container. @see CapabilityContainer.start_scripts """ self['scripts'] = args
""" Hack to actually make the -s option work since it was never implemented by whoever added it. """ if self['sysname']: if self['args'].count('sysname'): """I guess it's a good idea to override a redundantly supplied sysname in args""" args = self['args'] new_args = re.sub("sysname=\w+", "sysname=%s" % (self['sysname'],), args) self['args'] = new_args else: self['args'] = 'sysname=%s, %s' % (self['sysname'], self['args'],)
# Keep a reference to the CC service instance
""" This Twisted service is the ION Python Capability Container runtime environment. """
""" This service expects the config object to hold specific options. use phases to do things in order and wait for success/fail """
# calls back when the CC service starts up - anyone may attach to this callback and # use it for whatever is needed.
self.lockfile = open(lockfilepath, 'w') fcntl.lockf(self.lockfile, fcntl.LOCK_EX)
def startService(self): """ This is the main boot up point.
- start container which connects to broker - start container agent which notifies message space of presence - start any designated progs - start shell if appropriate """
# signal successful container start fcntl.lockf(self.lockfile, fcntl.LOCK_UN) self.lockfile.close() # The spawning process must cleanup the lockfile to avoid race conditions
stdioshell = shell.STDIOShell(cc_instance) stdioshell.startService() self.child_services.append(stdioshell) ns = shell.makeNamespace() ns.update({'cc':cc_instance}) telnetshell = shell.TelnetShell(ns) telnetshell.startService() self.child_services.append(telnetshell)
# event notify that the startup is good to go! # don't spawn - we don't want to register with the proc_manager, as they are never removed?
def stopService(self): svc.stopService()
def start_container(self): """ When deferred done, fire next step @retval Deferred """
def do_start_actions(self): yield self.run_boot_script()
def start_scripts(self): """ given the path to a file, open that file and exec the code. The file may be an .app, a .rel, or a python code script. """ # Try two script locations, one for IDEs and another for shell. log.error('Bad startup script path: %s' % script) else: elif script.endswith('.rel'): yield self.container.start_rel(rel_filename=script) else: log.info("Executing script %s ..." % script) execfile(script, {})
""" """ variable = 'boot' # have to have it... file_name = os.path.abspath(self.config['boot_script']) if os.path.isfile(file_name): boot = sob.loadValueFromFile(file_name, variable) return boot() raise RuntimeError('Bad boot script path')
""" Twisted plugin service instantiation. Required by Twisted; IServiceMaker interface """ global cc_instance cc_instance = CapabilityContainer(config) return cc_instance |