Package wtf :: Package opi
[hide private]
[frames] | no frames]

Package opi

source code

The modules in this package implement the different ways of integration within other frameworks. Currently there are:

daemon
The application is running as a standalone daemon, optionally forking itself into the background (Not forking is a both a debugging and production feature -- imagine integration into djb's daemontools and stuff.

The typical way to load the proper implementation is:

from wtf import opi
opi.factory(config, opts, args).work()

This evaluates the [wtf] section of the config, where the following options are recognized:

protocol = scgi|http

Required option, because there's no sensible default. fastcgi also handles regular CGI if:

XXX: implement it!

mode = Integration mode
daemon is default.
basedir = path
The directory to change into immediatly after startup. Default is: /
umask = umask
The umask to apply. The default umask is 0. The value is interpreted as octal number. You can specify inherit in order to inherit the umask from the caller (e.g. the shell).

In daemon mode the following options are used to determine the behaviour in detail:

detach = yes|no

Required option, because there's no sensible default. This option determines whether the daemon should fork itself into the background or not. If this option is set to yes, command line parameters become interesting. The last parameter is evaluated and has to be one of the following:

start
Start a new daemon. If there's already one running, this is a failure.
stop
Stop the daemon. If there's none running, this is not a failure. If there's one running, this option is identical to sending a SIGTERM + SIGCONT to the process in question.
logrotate|logreopen
Reopen the error log file.

The presence of another running daemon is determined by the pidfile (which is advisory locked for this purpose). Furthermore a forked away daemon does the usual detaching magic like closing all descriptors and stuff. This especially means, that STDIN, STDOUT and STDERR all point to /dev/null. If you specify an errorlog it will be attached to STDERR.

listen = [tcp:]host:port | [unix:]path[(perm)] ...
Required option, because there's no sensible default. This option determines where the daemon should listen for requests. This is a list of socket specifications which can be either TCP/IP or a unix domain sockets (you can mix them, if you want.) The optional perm parameter for unix sockets is an octal value and controls the permissions of the socket path. Note that socket paths are limited in length by the OS. See unix(7) for details.
workermodel = model
Required option, because there's no sensible default. This option determines the worker pool implementation.
errorlog = path
The file which STDERR should be attached to. By default STDERR goes to /dev/null.
pidfile = path
The option is required. It contains the name of the file where the PID of the main process is written into. The file is also used to determine a concurrently running daemon by locking it (The lock is automatically cleared if the daemon dies).
user = id|name
The user the working process should change to. If the application is started as root, it's strongly recommended to define such a user. See also group. If the application is not started as root, the option is ignored.
group = id|name
The group the working process should change to. If the application is started as root, it's strongly recommended to define such a group. See also user. If the application is not started as root, the option is ignored.

Author: André Malo

Submodules [hide private]

Classes [hide private]
  OPIError
OPI error
  OPIDone
OPI done
  OPIInterface
Interface for OPI implementations
Functions [hide private]
OPIInterface
factory(config, opts, args)
Create the OPI instance selected by configuration
source code
 
register(name, klass)
Register an OPI implementation
source code
Variables [hide private]
  __package__ = 'wtf.opi'
Function Details [hide private]

factory(config, opts, args)

source code 
Create the OPI instance selected by configuration
Parameters:
  • config (config.Config) - configuration
  • opts (optparse.OptionContainer) - Option container
  • args (list) - Fixed arguments
Returns: OPIInterface
OPI instance

register(name, klass)

source code 
Register an OPI implementation
Parameters:
  • name (str) - The name (in the config)
  • klass (OPIInterface) - The implementation class