Main process

class uwsgiconf.options.main_process.MainProcess(*args, **kwargs)

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.

class actions

Actions available for .set_hook().

alarm

alias of uwsgiconf.options.main_process_actions.ActionAlarm

call

alias of uwsgiconf.options.main_process_actions.ActionCall

dir_change

alias of uwsgiconf.options.main_process_actions.ActionDirChange

dir_create

alias of uwsgiconf.options.main_process_actions.ActionDirCreate

execute

alias of uwsgiconf.options.main_process_actions.ActionExecute

exit

alias of uwsgiconf.options.main_process_actions.ActionExit

fifo_write

alias of uwsgiconf.options.main_process_actions.ActionFifoWrite

file_create

alias of uwsgiconf.options.main_process_actions.ActionFileCreate

file_write

alias of uwsgiconf.options.main_process_actions.ActionFileWrite

mount

alias of uwsgiconf.options.main_process_actions.ActionMount

printout

alias of uwsgiconf.options.main_process_actions.ActionPrintout

set_host_name

alias of uwsgiconf.options.main_process_actions.ActionSetHostName

alias of uwsgiconf.options.main_process_actions.ActionUnlink

class 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)).

ASAP = 'asap'

As soon as possible. Fatal

Run directly after configuration file has been parsed, before anything else is done.

JAIL_PRE = 'pre-jail'

Before jailing. Fatal

Run before any attempt to drop privileges or put the process in some form of jail.

JAIL_IN = 'in-jail'

In jail after initialization. Fatal

Run soon after jayling, but after post-jail. If jailing requires fork(), the chidlren run this phase.

JAIL_POST = 'post-jail'

After jailing. Fatal

Run soon after any jailing, but before privileges drop. If jailing requires fork(), the parent process run this phase.

PRIV_DROP_PRE = 'as-root'

Before privileges drop. Fatal

Last chance to run something as root.

PRIV_DROP_POST = 'as-user'

After privileges drop. Fatal

MASTER_START = 'master-start'

When Master starts.

EMPEROR_START = 'emperor-start'

When Emperor starts.

EMPEROR_STOP = 'emperor-stop'

When Emperor sent a stop message.

EMPEROR_RELOAD = 'emperor-reload'

When Emperor sent a reload message.

EMPEROR_LOST = 'emperor-lost'

When Emperor connection is lost.

EXIT = 'as-user-atexit'

Before app exit and reload.

APP_LOAD_PRE = 'pre-app'

Before app loading. Fatal

APP_LOAD_POST = 'post-app'

After app loading. Fatal

VASSAL_ON_DEMAND_IN = 'as-on-demand-vassal'

Whenever a vassal enters on-demand mode.

VASSAL_CONFIG_CHANGE_POST = 'as-on-config-vassal'

Whenever the emperor detects a config change for an on-demand vassal.

VASSAL_START_PRE = 'as-emperor-before-vassal'

Before the new vassal is spawned.

VASSAL_PRIV_DRP_PRE = 'as-vassal-before-drop'

In vassal, before dropping its privileges.

VASSAL_SET_NAMESPACE = 'as-emperor-setns'

In the emperor entering vassal namespace.

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 = '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
GATEWAY_START_IN_EACH = 'as-gateway'

In each gateway on start.

MULE_START_IN_EACH = 'as-mule'

In each mule on start.

WORKER_ACCEPTING_PRE_EACH = 'accepting'

Before the each worker starts accepting requests.

Note

Since 1.9.21

WORKER_ACCEPTING_PRE_FIRST = 'accepting1'

Before the first worker starts accepting requests.

Note

Since 1.9.21

WORKER_ACCEPTING_PRE_EACH_ONCE = 'accepting-once'

Before the each worker starts accepting requests, one time per instance.

Note

Since 1.9.21

WORKER_ACCEPTING_PRE_FIRST_ONCE = 'accepting1-once'

Before the first worker starts accepting requests, one time per instance.

Note

Since 1.9.21

set_basic_params(*, touch_reload: Union[str, List[str]] = None, priority: int = None, vacuum: bool = None, binary_path: str = None, honour_stdin: bool = None)
Parameters:
  • touch_reload – Reload uWSGI if the specified file or directory is modified/touched.
  • priority – Set processes/threads priority (nice) value.
  • vacuum – Try to remove all of the generated files/sockets (UNIX sockets and pidfiles) upon exit.
  • binary_path – 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.
  • honour_stdin – 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_memory_params(*, ksm_interval: int = None, no_swap: bool = None)

Set memory related parameters.

Parameters:
  • ksm_interval

    Kernel Samepage Merging frequency option, that can reduce memory usage. Accepts a number of requests (or master process cycles) to run page scanner after.

    Note

    Linux only.

  • no_swap – Lock all memory pages avoiding swapping.
daemonize(log_into: str, *, after_app_loading: bool = False)

Daemonize uWSGI.

Parameters:
  • log_into (str) –

    Logging destination:

    • File: /tmp/mylog.log
    • UPD: 192.168.1.2:1717

      Note

      This will require an UDP server to manage log messages. Use networking.register_socket('192.168.1.2:1717, type=networking.SOCK_UDP) to start uWSGI UDP server.

  • after_app_loading – Whether to daemonize after or before applications loading.
change_dir(to: str, *, after_app_loading: bool = False)

Chdir to specified directory before or after apps loading.

Parameters:
  • to – Target directory.
  • after_app_loadingTrue - after load False - before load
set_owner_params(*, uid: Union[str, int] = None, gid: Union[str, int] = None, add_gids: Union[str, int, List[Union[str, int]]] = None, set_asap: bool = False)

Set process owner params - user, group.

Parameters:
  • uid – Set uid to the specified username or uid.
  • gid – Set gid to the specified groupname or gid.
  • add_gids – 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_asap – 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.
get_owner(*, default: bool = True) → Tuple[Union[str, int, None], Union[str, int, None]]

Return (User ID, Group ID) tuple

Parameters:default – Whether to return default if not set.
set_hook(phase: str, action: Union[str, HookAction, List[Union[str, HookAction]]])

Allows setting hooks (attaching actions) for various uWSGI phases.

Parameters:
  • phase – See constants in .phases.
  • action
set_hook_touch(fpath: Union[str, pathlib.Path], action: Union[str, HookAction, List[Union[str, HookAction]]])

Allows running certain action when the specified file is touched.

Parameters:
  • fpath – File path.
  • action
set_hook_after_request(func: str)

Run the specified function/symbol (C level) after each request.

Parameters:func
set_on_exit_params(*, skip_hooks: bool = None, skip_teardown: bool = None)

Set params related to process exit procedure.

Parameters:
  • skip_hooks

    Skip EXIT phase hook.

    Note

    Ignored by the master.

  • skip_teardown

    Allows skipping teardown (finalization) processes for some plugins.

    Note

    Ignored by the master.

    Supported by:
    • Perl
    • Python
run_command_on_event(command: str, *, phase: str = 'asap')

Run the given command on a given phase.

Parameters:
  • command
  • phase – See constants in Phases class.
run_command_on_touch(command: str, *, target: str)

Run command when the specified file is modified/touched.

Parameters:
  • command
  • target – File path.
set_pid_file(fpath: Union[str, pathlib.Path], *, before_priv_drop: bool = True, safe: bool = False)

Creates pidfile before or after privileges drop.

Parameters:
  • fpath – File path.
  • before_priv_drop

    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.

  • safe – The safe-pidfile works similar to pidfile but performs the 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.
set_naming_params(*, autonaming: bool = None, prefix: str = None, suffix: str = None, name: str = None)

Setups processes naming parameters.

Parameters:
  • autonaming – Automatically set process name to something meaningful. Generated process names may be ‘uWSGI Master’, ‘uWSGI Worker #’, etc.
  • prefix – Add prefix to process names.
  • suffix – Append string to process names.
  • name – Set process names to given static value.