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

Set memory related parameters.

Parameters:
  • ksm_interval (int) –

    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 (bool) – Lock all memory pages avoiding swapping.
daemonize(log_into, after_app_loading=False)

Daemonize uWSGI.

Parameters:
  • log_into (str|unicode) –

    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.

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

Chdir to specified directory before or after apps loading.

Parameters:
  • to (str|unicode) – Target directory.
  • after_app_loading (bool) – True - after load False - before load
set_owner_params(uid=None, gid=None, add_gids=None, set_asap=False)

Set process owner params - user, group.

Parameters:
  • uid (str|unicode|int) – Set uid to the specified username or uid.
  • gid (str|unicode|int) – Set gid to the specified groupname or gid.
  • add_gids (list|str|unicode|int) – 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 (bool) – 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=True)

Return (User ID, Group ID) tuple

Parameters:default (bool) – Whether to return default if not set.
Return type:tuple[int, int]
set_hook(phase, action)

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

Parameters:
  • phase (str|unicode) – See constants in .phases.
  • action (str|unicode|list|HookAction|list[HookAction]) –
set_hook_touch(fpath, action)

Allows running certain action when the specified file is touched.

Parameters:
  • fpath (str|unicode) – File path.
  • action (str|unicode|list|HookAction|list[HookAction]) –
set_hook_after_request(func)

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

Parameters:func (str|unicode) –
set_on_exit_params(skip_hooks=None, skip_teardown=None)

Set params related to process exit procedure.

Parameters:
  • skip_hooks (bool) –

    Skip EXIT phase hook.

    Note

    Ignored by the master.

  • skip_teardown (bool) –

    Allows skipping teardown (finalization) processes for some plugins.

    Note

    Ignored by the master.

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

Run the given command on a given phase.

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

Run command when the specified file is modified/touched.

Parameters:
  • command (str|unicode) –
  • target (str|unicode) – File path.
set_pid_file(fpath, before_priv_drop=True, safe=False)

Creates pidfile before or after privileges drop.

Parameters:
  • fpath (str|unicode) – File path.
  • before_priv_drop (bool) –

    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 (bool) – 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=None, prefix=None, suffix=None, name=None)

Setups processes naming parameters.

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