4

Is there a service (linux) that starts the service on an incoming TCP request (if it does not already exist) and then forwards it to the application? For example, for a docker container that would only start if you want to use it. The container is stopped by cron at night.

Workflow:

  • TCP client -> TCP server (Gateway)
  • gateway check service is available
  • if available then forward to
  • if not available then
    • parking the TCP connection
    • start service
    • if started then forward connection to

2 Answers 2

4

Technically, yes.

In 1986, the 4.3BSD Unix OS had the inetd service whose job was simply to listen for TCP connections and spawn the real service on activity. Inetd did not need to forward actual traffic – the service itself would inherit the real TCP socket and would be able to directly read/write the network data. However, the service did need to be written specifically to expect the socket to be already provided, instead of setting up everything on its own.

Many BSDs still have inetd (although it's mostly unused), and most Linux distributions have xinetd available. Additionally, every Linux distribution using systemd has this functionality available through systemd.socket units where it's called "socket activation".

(It is even possible to start whole containers this way, but the container manager also needs specific support for this feature. For example, systemd-nspawn makes it possible – unfortunately, as far as I know, Docker does not. This did not stop a few companies from using on-demand started containers in production, though.)

A proxy/gateway tool can be used to implement on-demand startup for programs (or containers) which don't support socket passing on their own. For example, systemd again has systemd-socket-proxyd which will start the real thing and relay connections to it (there's an example with Podman on the Red Hat blog, and here's a Docker example); this can also be implemented with (x)inetd using ordinary netcat or socat as the relay.

1

Podman supports socket activation of containers since Podman version 3.4.0 (released in September 2021).

If the service inside the container supports socket activation, you can use systemd together with Podman to have systemd listen on the TCP socket. In case a client connects to the TCP socket, systemd will start Podman in such a way that the socket file descriptor is available to the Podman process. Podman will pass on the file descriptor to the container.

See the Podman socket activation tutorial that contains examples of how to run socket-activated containers with Podman.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .