def run_server(self) -> None: """Prepare and run the server.""" # Prevent preparing twice when in development mode due to reloader if not self.debug or os.environ.get('RUN_MAIN') == 'true': self.prepare_server() print('Starting server..') if self.debug: # Run in development call_command('runserver', '0.0.0.0:8000') else: import pyuwsgi # Run in production pyuwsgi.run(['--ini', 'uwsgi.ini'])
def run_server(self) -> None: """Prepare and run the web server.""" in_reloader = os.environ.get('RUN_MAIN') == 'true' # Prevent preparing twice when in dev mode due to reloader if not self.debug or in_reloader: self.prepare_server() print("Starting server.") # Run the development server if self.debug: call_command("runserver", "0.0.0.0:8000") return # Run uwsgi for production server pyuwsgi.run(["--ini", "docker/uwsgi.ini"])
def run(self) -> None: """Runs server with standard Django runner (dev) or with pyuwsgi (production).""" in_reloader = os.environ.get('RUN_MAIN') == 'true' # Prevent preparing twice when in dev mode due to reloader if not self.debug or in_reloader: self.prepare_site() log.info("Starting server...") # Development mode if self.debug: call_command("runserver", "0.0.0.0:8080") return # Production mode import pyuwsgi pyuwsgi.run(["--ini", "docker/uwsgi.ini"])
def run(module, bind, **kwargs): options = { "auto_procname": True, "chmod_socket": 777, "die_on_term": True, "disable_write_exception": True, "enable_threads": True, "ignore_sigpipe": True, "ignore_write_errors": True, "lazy_apps": True, "log_format": '%(addr) - %(user) [%(ltime)] "%(method) %(uri) %(proto)" %(status) %(size) "%(referer)" "%(uagent)"', "log_x_forwarded_for": True, "master": True, "module": module, "need_app": True, "processes": 1, "protocol": os.environ.pop("UWSGI_PROTOCOL", "http"), "single_interpreter": True, "threads": 1, "thunder_lock": True, "vacuum": True, "virtualenv": sys.prefix, "wsgi_env_behavior": "holy", } options.setdefault("%s_socket" % options["protocol"], bind) options.update(kwargs) prepare_environ(options, os.environ) try: import pyuwsgi except ImportError: os.execvp("uwsgi", ("uwsgi",)) else: pyuwsgi.run([])
def main(): os.environ.setdefault( "DJANGO_SETTINGS_MODULE", "basxconnect_demo.settings.production" ) if "manage" in sys.argv[1:2]: from django.core.management import execute_from_command_line execute_from_command_line(sys.argv[1:]) else: import configparser import pyuwsgi args = [] if "--ini" in sys.argv: config = configparser.ConfigParser() config.read(sys.argv[sys.argv.index("--ini") + 1]) for key, value in config["uwsgi"].items(): if key != "privileged-binary-patch": args.append(f"--{key}") args.append(value) pyuwsgi.run(*(args + ["--strict", "--need-app", "--module", "wsgi"]))
import sys import os import pyuwsgi orig_args = sys.argv orig_executable = sys.executable orig_args.insert(0, orig_executable) uwsgi_args = [] for arg in sys.argv[2:]: uwsgi_args.append(arg) # pyuwsgi.run('welcome.ini') pyuwsgi.run(uwsgi_args) # if you are here uWSGI has been reloaded os.execv(orig_executable, orig_args)
import sys import os import pyuwsgi orig_args = sys.argv orig_executable = sys.executable orig_args.insert(0, orig_executable) uwsgi_args = [] uwsgi_args.append('--socket') uwsgi_args.append(':3031') #uwsgi_args.append('--master') uwsgi_args.append('--module') #uwsgi_args.append('welcome') uwsgi_args.append('hello') #pyuwsgi.run('welcome.ini') pyuwsgi.run(uwsgi_args) # if you are here uWSGI has been reloaded os.execv(orig_executable, orig_args)
def spawn(self, config: 'Configuration', replace: bool = False, filepath: str = None, embedded: bool = False): """Spawns uWSGI using the given configuration module. .. note:: uWSGI loader schemas: * From a symbol -- sym://uwsgi_funny_function * From binary appended data -- data://0 * From http -- http://example.com/hello * From a file descriptor -- fd://3 * From a process stdout -- exec://foo.pl * From a function call returning a char * -- call://uwsgi_func Loading in config: foo = @(sym://uwsgi_funny_function) :param config: Configuration object to spawn uWSGI with. :param filepath: Override configuration file path. :param replace: Whether a new process should replace current one. :param embedded: Flag. Do not create a configuration file even if required, translate all config parameters into command line arguments and pass it to ``pyuwsgi``. """ args = ['uwsgi'] if embedded: import pyuwsgi # noqa args.extend(config.format(formatter='args')) pyuwsgi.run(args[1:]) else: args.append('--ini') filepath = filepath or config.tofile() if os.path.splitext(os.path.basename(filepath))[1] == '.ini': args.append(filepath) else: # Consider it to be a python script (uwsgicfg.py). # Pass --conf as an argument to have a chance to use # touch reloading form .py configuration file change. args.append( f'exec://{self.binary_python} {filepath} --conf {config.alias}' ) if replace: try: return os.execvp('uwsgi', args) except FileNotFoundError: raise UwsgiconfException( 'uWSGI executable not found. ' 'Please make sure it is installed and available.') return os.spawnvp(os.P_NOWAIT, 'uwsgi', args)
def run_from_argv(self, argv): args = get_default_args() + argv[2:] pyuwsgi.run(*args)
def start_server(self, *args): pyuwsgi.run(args)