Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for socket groups, so different sockets can be connected to different watchers #1076

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tjikkun
Copy link

@tjikkun tjikkun commented Aug 14, 2018

This is useful if you use circus for socket activation of multiple daemons,
connected to different sockets.

…to different watchers

This can be useful if you use circus for socket activation of multiple daemons,
connected to different sockets.
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.06%) to 62.884% when pulling 7fca067 on AntagonistHQ:sock_act_groups into 6ca0d18 on circus-tent:master.

@tjikkun
Copy link
Author

tjikkun commented Aug 14, 2018

I hope I can get some feedback on this pull request. If the general idea is fine, I will work on test coverage and failing tests.

@k4nar
Copy link
Contributor

k4nar commented Aug 14, 2018

Thanks for the PR!

I'm not sure to understand the purpose. Could you show an example of configuration using it?

@tjikkun
Copy link
Author

tjikkun commented Aug 14, 2018

@k4nar Suppose you have the following config:
/tmp/testsock1.py:

#!/usr/bin/env python3

from socketserver import UnixStreamServer, StreamRequestHandler
import socket
import logging
import sys

class Handler(StreamRequestHandler):
    def handle(self):
        self.data = self.rfile.readline().strip()
        logging.info("From <%s>: %s" % (self.client_address, self.data))
        self.wfile.write(self.data.upper() + "\r\n".encode("utf-8"))

class Server(UnixStreamServer):
    
    def __init__(self, server_address, handler_cls):
        # Invoke base but omit bind/listen steps (performed by systemd activation!)
        UnixStreamServer.__init__(
            self, server_address, handler_cls, bind_and_activate=False)
        # Override socket
        self.socket = socket.socket(fileno=int(sys.argv[1]))

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    PATH = None # not really needed here
    server = Server(PATH, Handler)
    server.serve_forever()

/tmp/testsock2.py

#!/usr/bin/env python3

from socketserver import UnixStreamServer, StreamRequestHandler
import socket
import logging
import sys

class Handler(StreamRequestHandler):
    def handle(self):
        self.data = self.rfile.readline().strip()
        logging.info("From <%s>: %s" % (self.client_address, self.data))
        self.wfile.write(self.data.lower() + "\r\n".encode("utf-8"))

class Server(UnixStreamServer):
    
    def __init__(self, server_address, handler_cls):
        # Invoke base but omit bind/listen steps (performed by systemd activation!)
        UnixStreamServer.__init__(
            self, server_address, handler_cls, bind_and_activate=False)
        # Override socket
        self.socket = socket.socket(fileno=int(sys.argv[1]))

if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    PATH = None # not really needed here
    server = Server(PATH, Handler)
    server.serve_forever()
[watcher:watcher1]
cmd = /tmp/testsock1.py $(circus.sockets.socket1)
uid = root
gid = root
use_sockets = True
on_demand = True
singleton = True
socket_group = sockettest1

[socket:socket1]
path = /tmp/upsock
umask = 077
replace = True
group = sockettest1

[watcher:watcher2]
cmd = /tmp/testsock2.py $(circus.sockets.socket2)
uid = root
gid = root
use_sockets = True
on_demand = True
singleton = True
socket_group = sockettest2

[socket:socket2]
path = /tmp/downsock
umask = 077
replace = True
group = sockettest2

Without this patch and socket_group and group, if you connect to either socket, only watcher1 is started.
This means /tmp/upsock works fine, but /tmp/downsock doesn't.

With the patch, but without socket_group and group, if you connect to the socket both watchers are started, and you are connected to the right watcher.

With the patch, and with socket_group and group, if you connect to the socket only the corresponding watcher is started and you are connected to the right watcher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants