Example #1
0
def socket_command(sock, args, instance):
    """Create a socket to be used by processes.
You need to specify a name, followed by name=value pairs for the connection
options. The name must not contain spaces.

Family and type options are:
    family - should be unix, inet, inet6 (default is unix if path is specified,
             of inet if no path)
    type - should be stream, dgram, raw, rdm or seqpacket (default is stream)
    backlog - specifies the listen backlog (default is 5)

Options for family=unix
    path - must be an absolute path (required)
    umask - override the current umask when creating the socket file

Options for family=inet or family=inet6
    port - if left out, the system will assign a port
    interface - only bind to a single ethernet adaptor
    host - you will usually want the default, which will be 127.0.0.1 if no
           interface it specified and 0.0.0.0 otherwise
    reuseport - on systems that support it, papa will create and bind a new
                socket for each process that uses this socket

The url must start with "tcp:", "udp:" or "unix:".
Examples:
    make socket uwsgi port=8080
    make socket chaussette path=/tmp/chaussette.sock
"""
    if not args:
        raise Error('Socket requires a name')
    name = args.pop(0)
    kwargs = extract_name_value_pairs(args)
    p = PapaSocket(name, instance, **kwargs)
    with instance['globals']['lock']:
        return str(p.start())
Example #2
0
def socket_command(sock, args, instance):
    """Create a socket to be used by processes.
You need to specify a name, followed by name=value pairs for the connection
options. The name must not contain spaces.

Family and type options are:
    family - should be unix, inet, inet6 (default is unix if path is specified,
             of inet if no path)
    type - should be stream, dgram, raw, rdm or seqpacket (default is stream)
    backlog - specifies the listen backlog (default is 5)

Options for family=unix
    path - must be an absolute path (required)
    umask - override the current umask when creating the socket file

Options for family=inet or family=inet6
    port - if left out, the system will assign a port
    interface - only bind to a single ethernet adaptor
    host - you will usually want the default, which will be 127.0.0.1 if no
           interface it specified and 0.0.0.0 otherwise
    reuseport - on systems that support it, papa will create and bind a new
                socket for each process that uses this socket

The url must start with "tcp:", "udp:" or "unix:".
Examples:
    make socket uwsgi port=8080
    make socket chaussette path=/tmp/chaussette.sock
"""
    if not args:
        raise Error('Socket requires a name')
    name = args.pop(0)
    kwargs = extract_name_value_pairs(args)
    p = PapaSocket(name, instance, **kwargs)
    with instance['globals']['lock']:
        return str(p.start())
Example #3
0
File: proc.py Project: meitham/papa
def process_command(sock, args, instance):
    """Create a process.
You need to specify a name, followed by name=value pairs for the process
options, followed by the command and args to execute. The name must not contain
spaces.

Process options are:
    uid - the username or user ID to use when starting the process
    gid - the group name or group ID to use when starting the process
    working_dir - must be an absolute path if specified
    output - size of each output buffer (default is 1m)

You can also specify environment variables by prefixing the name with 'env.' and
rlimits by prefixing the name with 'rlimit.'

Examples:
    make process sf uid=1001 gid=2000 working_dir=/sf/bin/ output=1m /sf/bin/uwsgi --ini uwsgi-live.ini --socket fd://27 --stats 127.0.0.1:8090
    make process nginx /usr/local/nginx/sbin/nginx
"""
    if not args:
        raise Error('Process requires a name')
    name = args.pop(0)
    env = {}
    rlimits = {}
    kwargs = {}
    for key, value in extract_name_value_pairs(args).items():
        if key.startswith('env.'):
            env[key[4:]] = value
        elif key.startswith('rlimit.'):
            key = key[7:]
            try:
                rlimits[getattr(resource,
                                'RLIMIT_%s' % key.upper())] = int(value)
            except AttributeError:
                raise utils.Error('Unknown rlimit "%s"' % key)
            except ValueError:
                raise utils.Error(
                    'The rlimit value for "%s" must be an integer, not "%s"' %
                    (key, value))
        else:
            kwargs[key] = value
    watch = int(kwargs.pop('watch', 0))
    p = Process(name, args, env, rlimits, instance, **kwargs)
    with instance['globals']['lock']:
        result = p.spawn()
    if watch:
        send_with_retry(sock, cast_bytes('{0}\n'.format(result)))
        return _do_watch(sock, {name: {
            'p': result,
            't': 0,
            'closed': False
        }}, instance)

    return str(result)
Example #4
0
def process_command(sock, args, instance):
    """Create a process.
You need to specify a name, followed by name=value pairs for the process
options, followed by the command and args to execute. The name must not contain
spaces.

Process options are:
    uid - the username or user ID to use when starting the process
    gid - the group name or group ID to use when starting the process
    working_dir - must be an absolute path if specified
    output - size of each output buffer (default is 1m)

You can also specify environment variables by prefixing the name with 'env.' and
rlimits by prefixing the name with 'rlimit.'

Examples:
    make process sf uid=1001 gid=2000 working_dir=/sf/bin/ output=1m /sf/bin/uwsgi --ini uwsgi-live.ini --socket fd://27 --stats 127.0.0.1:8090
    make process nginx /usr/local/nginx/sbin/nginx
"""
    if not args:
        raise Error('Process requires a name')
    name = args.pop(0)
    env = {}
    rlimits = {}
    kwargs = {}
    for key, value in extract_name_value_pairs(args).items():
        if key.startswith('env.'):
            env[key[4:]] = value
        elif key.startswith('rlimit.'):
            key = key[7:]
            try:
                rlimits[getattr(resource, 'RLIMIT_%s' % key.upper())] = int(value)
            except AttributeError:
                raise utils.Error('Unknown rlimit "%s"' % key)
            except ValueError:
                raise utils.Error('The rlimit value for "%s" must be an integer, not "%s"' % (key, value))
        else:
            kwargs[key] = value
    watch = int(kwargs.pop('watch', 0))
    p = Process(name, args, env, rlimits, instance, **kwargs)
    with instance['globals']['lock']:
        result = p.spawn()
    if watch:
        send_with_retry(sock, cast_bytes('{0}\n'.format(result)))
        return _do_watch(sock, {name: {'p': result, 't': 0, 'closed': False}}, instance)

    return str(result)