Main process
Classes
MainProcess
MainProcess ( * args , ** kwargs )
OptionsGroup
Main process is the uWSGI process.
Warning
Do not run uWSGI instances as root.
You can start your uWSGIs as root, but be sure to drop privileges
with the uid and gid options from set_owner_params.
name
Name to represent the group.
plugin
. plugin : bool | str = False
Indication this option group belongs to a plugin.
change_dir
. change_dir (
to : Strpath , # (1)!
after_app_loading : bool = False , # (2)!
)
Target directory.
True - after load
False - before load
Chdir to specified directory before or after apps loading.
daemonize
. daemonize (
log_into : str ,
after_app_loading : bool = False , # (1)!
)
Whether to daemonize after
or before applications loading.
Daemonize uWSGI.
get_owner
. get_owner (
default : bool = True , # (1)!
) -> tuple [ Strint | None , Strint | None ]
Whether to return default if not set.
Return (User ID, Group ID) tuple
run_command_on_event
. run_command_on_event (
command : str ,
phase : str = phases . ASAP , # (1)!
)
See constants in Phases class.
Run the given command on a given phase.
run_command_on_touch
. run_command_on_touch (
command : str ,
target : str , # (1)!
)
File path.
Run command when the specified file is modified/touched.
set_basic_params
. set_basic_params (
touch_reload : Strlist = None , # (1)!
priority : int | None = None , # (2)!
vacuum : bool | None = None , # (3)!
binary_path : str | None = None , # (4)!
honour_stdin : bool | None = None , # (5)!
)
Reload uWSGI if the specified file or directory is modified/touched.
Set processes/threads priority (nice) value.
Try to remove all the generated files/sockets
(UNIX sockets and pidfiles) upon exit.
Force uWSGI binary path.
If you do not have uWSGI in the system path you can force its path with this option
to permit the reloading system and the Emperor to easily find the binary to execute.
Do not remap stdin to /dev/null.
By default, stdin is remapped to /dev/null on uWSGI startup.
If you need a valid stdin (for debugging, piping and so on) use this option.
set_hook
. set_hook (
phase : str , # (1)!
action : TypeActionExt
)
See constants in .phases.
Allows setting hooks (attaching actions) for various uWSGI phases.
set_hook_after_request
. set_hook_after_request ( func : str )
Run the specified function/symbol (C level) after each request.
set_hook_touch
. set_hook_touch (
fpath : Strpath , # (1)!
action : TypeActionExt
)
File path.
Allows running certain action when the specified file is touched.
set_memory_params
. set_memory_params (
ksm_interval : int | None = None , # (1)!
no_swap : bool | None = None , # (2)!
)
Kernel Samepage Merging frequency option, that can reduce memory usage.
Accepts a number of requests (or master process cycles) to run page scanner after.
Lock all memory pages avoiding swapping.
Set memory related parameters.
set_naming_params
. set_naming_params (
autonaming : bool | None = None , # (1)!
prefix : str | None = None , # (2)!
suffix : str | None = None , # (3)!
name : str | None = None , # (4)!
)
Automatically set process name to something meaningful.
Generated process names may be 'uWSGI Master', 'uWSGI Worker #', etc.
Add prefix to process names.
Append string to process names.
Set process names to given static value.
Setups processes naming parameters.
set_on_exit_params
. set_on_exit_params (
skip_hooks : bool | None = None , # (1)!
skip_teardown : bool | None = None , # (2)!
)
Skip EXIT phase hook.
.. note:: Ignored by the master.
Allows skipping teardown (finalization) processes for some plugins.
.. note:: Ignored by the master.
Supported by:
* Perl
* Python
Set params related to process exit procedure.
set_owner_params
. set_owner_params (
uid : Strint = None , # (1)!
gid : Strint = None , # (2)!
add_gids : Strint | list [ Strint ] = None , # (3)!
set_asap : bool = False , # (4)!
drop_after : str = '' , # (5)!
)
Set uid to the specified username or uid.
Set gid to the specified groupname or gid.
Add the specified group id to the process credentials.
This options allows you to add additional group ids to the current process.
You can specify it multiple times.
Set as soon as possible.
Setting them on top of your vassal file will force the instance to setuid()/setgid()
as soon as possible and without the (theoretical) possibility to override them.
When to drop privileges (e.g. if initially run as root):
'init' - drop after plugin initialization
'apps' - drop after apps loading
Set process owner params - user, group.
set_pid_file
. set_pid_file (
fpath : Strpath , # (1)!
before_priv_drop : bool = True , # (2)!
safe : bool = False , # (3)!
)
File path.
Whether to create pidfile before privileges are dropped.
.. note:: Vacuum is made after privileges drop, so it may not be able
to delete PID file if it was created before dropping.
The safe-pidfile works similar to pidfile
but performs write a little later in the loading process.
This avoids overwriting the value when app loading fails,
with the consequent loss of a valid PID number.
Creates pidfile before or after privileges drop.
actions
Actions available for .set_hook().
phases
Phases available for hooking using .set_hook().
Some of them may be fatal - a failing hook for them
will mean failing of the whole uWSGI instance (generally calling exit(1)).
APP_LOAD_POST
. APP_LOAD_POST = 'post-app'
After app loading. Fatal
APP_LOAD_PRE
. APP_LOAD_PRE = 'pre-app'
Before app loading. Fatal
ASAP
As soon as possible. Fatal
Run directly after configuration file has been parsed, before anything else is done.
EMPEROR_LOST
. EMPEROR_LOST = 'emperor-lost'
When Emperor connection is lost.
EMPEROR_RELOAD
. EMPEROR_RELOAD = 'emperor-reload'
When Emperor sent a reload message.
EMPEROR_START
. EMPEROR_START = 'emperor-start'
When Emperor starts.
EMPEROR_STOP
. EMPEROR_STOP = 'emperor-stop'
When Emperor sent a stop message.
EXIT
Before app exit and reload.
GATEWAY_START_IN_EACH
. GATEWAY_START_IN_EACH = 'as-gateway'
In each gateway on start.
JAIL_IN
In jail after initialization. Fatal
Run soon after jayling, but after post-jail.
If jailing requires fork(), the chidlren run this phase.
JAIL_POST
After jailing. Fatal
Run soon after any jailing, but before privileges drop.
If jailing requires fork(), the parent process run this phase.
JAIL_PRE
Before jailing. Fatal
Run before any attempt to drop privileges or put the process in some form of jail.
MASTER_START
. MASTER_START = 'master-start'
When Master starts.
MULE_START_IN_EACH
. MULE_START_IN_EACH = 'as-mule'
In each mule on start.
PRIV_DROP_POST
. PRIV_DROP_POST = 'as-user'
After privileges drop. Fatal
PRIV_DROP_PRE
. PRIV_DROP_PRE = 'as-root'
Before privileges drop. Fatal
Last chance to run something as root.
VASSAL_CONFIG_CHANGE_POST
. VASSAL_CONFIG_CHANGE_POST = 'as-on-config-vassal'
Whenever the emperor detects a config change for an on-demand vassal.
VASSAL_ON_DEMAND_IN
. VASSAL_ON_DEMAND_IN = 'as-on-demand-vassal'
Whenever a vassal enters on-demand mode.
VASSAL_PRIV_DRP_PRE
. VASSAL_PRIV_DRP_PRE = 'as-vassal-before-drop'
In vassal, before dropping its privileges.
VASSAL_SET_NAMESPACE
. VASSAL_SET_NAMESPACE = 'as-emperor-setns'
In the emperor entering vassal namespace.
VASSAL_START_IN
. VASSAL_START_IN = 'as-vassal'
In the vassal before executing the uwsgi binary. Fatal
In vassal on start just before calling exec() directly in the new namespace.
VASSAL_START_POST
. VASSAL_START_POST = 'as-emperor'
In the emperor soon after a vassal has been spawn.
Setting 4 env vars:
* UWSGI_VASSAL_CONFIG
* UWSGI_VASSAL_PID
* UWSGI_VASSAL_UID
* UWSGI_VASSAL_GID
VASSAL_START_PRE
. VASSAL_START_PRE = 'as-emperor-before-vassal'
Before the new vassal is spawned.
WORKER_ACCEPTING_PRE_EACH
. WORKER_ACCEPTING_PRE_EACH = 'accepting'
Before the each worker starts accepting requests.
WORKER_ACCEPTING_PRE_EACH_ONCE
. WORKER_ACCEPTING_PRE_EACH_ONCE = 'accepting-once'
Before the each worker starts accepting requests, one time per instance.
WORKER_ACCEPTING_PRE_FIRST
. WORKER_ACCEPTING_PRE_FIRST = 'accepting1'
Before the first worker starts accepting requests.
WORKER_ACCEPTING_PRE_FIRST_ONCE
. WORKER_ACCEPTING_PRE_FIRST_ONCE = 'accepting1-once'
Before the first worker starts accepting requests, one time per instance.