Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

zegelin/python-systemd-socketserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

systemd-socketserver

systemd-socketserver is a simple Python 3 package that provides the SystemdSocketServer class, a socket server implementation that works in tandem with systemd's socket activation feature.

Very useful for writing basic socket activated daemons.

Installation

Install from PyPi:

pip install systemd-socketserver

Or clone from Git and install from source:

setup.py install

Basic Usage

For a full example see the example directory.

The following Python module, when activated via .socket unit, will echo the first sent line to the socket then disconnect.

class EchoHandler(socketserver.StreamRequestHandler):
    def handle(self):
        self.data = self.rfile.readline()
        self.wfile.write(self.data.upper())
        
server = systemd_socketserver.listen_server(EchoHandler)

if server is None:
    print('this example only supports socket activation', file=sys.stderr)
    return
    
server.listen_forever()

Features:

  • Supports and auto detects both listen and accept sockets (Accept=true|false in the .socket unit)

  • Supports named file descriptors, making it easy to bind different handlers to different sockets.

    This feature relies on functionality currently not present in the most recent package release of python-systemd, namely the listen_fds_with_names function. Calling listen_servers_with_names will throw a NotImplementedException in this case.

    Building python-systemd from source will include support for listen_fds_with_names and hence this feature will work.

    For an example of this functionality see the code in the example directory.

Known Limitations

  • This module has only been tested with INET sockets.
  • Better documentation TODO.

About

Socket server implementation that works with systemd socket activation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
Morty Proxy This is a proxified and sanitized view of the page, visit original site.