Master process¶
-
class
uwsgiconf.options.master_process.
MasterProcess
(*args, **kwargs)¶ Master process is a separate process offering mentoring capabilities for other processes. Only one master process per uWSGI instance.
uWSGI’s built-in prefork+threading multi-worker management mode, activated by flicking the master switch on.
Note
For all practical serving deployments it’s not really a good idea not to use master mode.
-
set_basic_params
(*, enable: bool = None, name: str = None, no_orphans: bool = None, as_root: bool = None, subproc_check_interval: int = None, fifo_file: str = None)¶ Parameters: - enable – Enable uWSGI master process.
- name – Set master process name to given value.
- no_orphans – Automatically kill workers if master dies (can be dangerous for availability).
- as_root – Leave master process running as root.
- subproc_check_interval –
Set the interval (in seconds) of master checks. Default: 1 The master process makes a scan of subprocesses, etc. every N seconds.
Warning
You can increase this time if you need to, but it’s DISCOURAGED.
- fifo_file –
Enables the master FIFO.
Note
Placeholders can be used to build paths, e.g.: {project_runtime_dir}.fifo See
Section.project_name
andSection.runtime_dir
.Instead of signals, you can tell the master to create a UNIX named pipe (FIFO) that you may use to issue commands to the master.
Up to 10 different FIFO files supported. By default the first specified is bound (mapped as ‘0’).
Note
Since 1.9.17
-
set_exit_events
(*, no_workers: bool = None, idle: bool = None, reload: bool = None, sig_term: bool = None)¶ Do exit on certain events
Parameters: - no_workers (bool) – Shutdown uWSGI when no workers are running.
- idle (bool) – Shutdown uWSGI when idle.
- reload (bool) – Force exit even if a reload is requested.
- sig_term (bool) –
Exit on SIGTERM instead of brutal workers reload.
Note
Before 2.1 SIGTERM reloaded the stack while SIGINT/SIGQUIT shut it down.
-
set_exception_handling_params
(*, handler: Union[str, List[str]] = None, catch: bool = None, no_write_exception: bool = None)¶ Exception handling related params.
Parameters: - handler – Register one or more exception handling C-functions.
- catch –
Catch exceptions and report them as http output (including stack trace and env params).
Warning
Use only for testing purposes.
- no_write_exception –
Disable exception generation on write()/writev().
Note
This can be combined with
logging.set_filters(write_errors=False, sigpipe=False)
.
-
set_idle_params
(*, timeout: int = None, exit: bool = None)¶ Activate idle mode - put uWSGI in cheap mode after inactivity timeout.
Parameters: - timeout – Inactivity timeout in seconds.
- exit – Shutdown uWSGI when idle.
-
set_reload_params
(*, mercy: int = None, exit: bool = None)¶ Set reload related params.
Parameters: - mercy – Set the maximum time (in seconds) we wait for workers and other processes to die during reload/shutdown.
- exit – Force exit even if a reload is requested.
-
add_cron_task
(command: str, *, weekday: Union[str, int] = None, month: Union[str, int] = None, day: Union[str, int] = None, hour: Union[str, int] = None, minute: Union[str, int] = None, legion: str = None, unique: bool = None, harakiri: int = None)¶ Adds a cron task running the given command on the given schedule. http://uwsgi.readthedocs.io/en/latest/Cron.html
- HINTS:
- Use negative values to say every:
- hour=-3 stands for every 3 hours
- Use - (minus) to make interval:
- minute=’13-18’ stands for from minute 13 to 18
Note
We use cron2 option available since 1.9.11.
Parameters: - command – Command to execute on schedule (with or without path).
- weekday – Day of a the week number. Defaults to each. 0 - Sunday 1 - Monday 2 - Tuesday 3 - Wednesday 4 - Thursday 5 - Friday 6 - Saturday
- month – Month number 1-12. Defaults to each.
- day – Day of the month number 1-31. Defaults to each.
- hour – Hour 0-23. Defaults to each.
- minute – Minute 0-59. Defaults to each.
- legion – Set legion (cluster) name to use this cron command against. Such commands are only executed by legion lord node.
- unique – Marks command as unique. Default to not unique. Some commands can take a long time to finish or just hang doing their thing. Sometimes this is okay, but there are also cases when running multiple instances of the same command can be dangerous.
- harakiri – Enforce a time limit (in seconds) on executed commands. If a command is taking longer it will be killed.
-
attach_process_classic
(command_or_pid_path: str, *, background: bool, control: bool = False, for_legion: bool = False)¶ Attaches a command/daemon to the master process optionally managed by a pidfile.
This will allow the uWSGI master to control/monitor/respawn this process.
Note
This uses old classic uWSGI means of process attaching To have more control use
.attach_process()
method (requires uWSGI 2.0+)http://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html
Parameters: - command_or_pid_path –
- background – Must indicate whether process is in background.
- control –
Consider this process a control: when the daemon dies, the master exits.
Note
pidfile managed processed not supported.
- for_legion –
Legion daemons will be executed only on the legion lord node, so there will always be a single daemon instance running in each legion. Once the lord dies a daemon will be spawned on another node.
Note
uWSGI 1.9.9+ required.
-
attach_process
(command: str, *, for_legion: bool = False, broken_counter: int = None, pidfile: str = None, control: bool = None, daemonize: bool = None, touch_reload: Union[str, List[str]] = None, signal_stop: int = None, signal_reload: int = None, honour_stdin: bool = None, uid: Union[str, int] = None, gid: Union[str, int] = None, new_pid_ns: bool = None, change_dir: str = None)¶ Attaches a command/daemon to the master process.
This will allow the uWSGI master to control/monitor/respawn this process.
http://uwsgi-docs.readthedocs.io/en/latest/AttachingDaemons.html
Parameters: - command – The command line to execute.
- for_legion – Legion daemons will be executed only on the legion lord node, so there will always be a single daemon instance running in each legion. Once the lord dies a daemon will be spawned on another node.
- broken_counter – Maximum attempts before considering a daemon “broken”.
- pidfile – The pidfile path to check (enable smart mode).
- control – If True, the daemon becomes a control one: if it dies the whole uWSGI instance dies.
- daemonize – Daemonize the process (enable smart2 mode).
- touch_reload – List of files to check: whenever they are ‘touched’, the daemon is restarted
- signal_stop – The signal number to send to the daemon when uWSGI is stopped.
- signal_reload – The signal number to send to the daemon when uWSGI is reloaded.
- honour_stdin – The signal number to send to the daemon when uWSGI is reloaded.
- uid –
Drop privileges to the specified uid.
Note
Requires master running as root.
- gid –
Drop privileges to the specified gid.
Note
Requires master running as root.
- new_pid_ns –
Spawn the process in a new pid namespace.
Note
Requires master running as root.
Note
Linux only.
- change_dir – Use chdir() to the specified directory before running the command.
-