def prepare(self, runtime): if self['configured']: return config = self['config'] if not config.exists(): raise TaskError("configure file '%s' does not exist" % config) self.runtime = Runtime(str(config)) self.runtime.deploy()
class SpireTask(Task): parameters = { 'config': Path(description='path to spire configuration file', default=path('spire.yaml')), 'configured': Boolean(hidden=True, default=False), } @property def assembly(self): return Assembly.current() def prepare(self, runtime): if self['configured']: return config = self['config'] if not config.exists(): raise TaskError("configure file '%s' does not exist" % config) self.runtime = Runtime(str(config)) self.runtime.deploy()
import sys from werkzeug.wsgi import SharedDataMiddleware from spire.runtime.runtime import Runtime from spire.wsgi.server import WsgiServer from spire.wsgi.util import Mount, MountDispatcher class Runtime(Runtime): def __init__(self, address, configuration=None, assembly=None): super(Runtime, self).__init__(configuration, assembly) self.deploy() self.startup() self.dispatcher = MountDispatcher() for unit in self.assembly.collate(Mount): self.dispatcher.mount(unit) wsgi = self.configuration.get('wsgi') if wsgi and 'static-map' in wsgi: map = wsgi['static-map'].split('=') self.dispatcher = SharedDataMiddleware(self.dispatcher, { map[0]: os.path.abspath(map[1]) }, cache=False) self.server = WsgiServer(address, self.dispatcher) self.server.serve() if __name__ == '__main__': Runtime(*sys.argv[1:])
mule = self.mules[name] = Mule(len(self.mules) + 1, name, function) self.postforks.append(mule) def register_signal(self, name, target=None, function=None): id = len(self.signals) + 10 self.signals[id], self.signals[name] = name, id if target: uwsgi.register_signal(id, target, function) def reload(self): uwsgi.reload() def run_postforks(self): purge_context_locals() for function in self.postforks: function() def signal(self, name): uwsgi.signal(self.signals[name]) def unlock(self): uwsgi.unlock() def wait(self, signal=None): if signal: uwsgi.signal_wait(self.signals[signal]) if uwsgi: uwsgi.applications = {'': Runtime()}
import os import sys from spire.runtime.runtime import Runtime if __name__ == '__main__': if os.getenv('PYTHONSTARTUP', False): if os.path.exists(os.environ['PYTHONSTARTUP']): execfile(os.environ['PYTHONSTARTUP']) Runtime().configure(sys.argv[1]).deploy()