F1bonacc1 / process-compose

Process Compose is a simple and flexible scheduler and orchestrator to manage non-containerized applications.
https://f1bonacc1.github.io/process-compose/
Apache License 2.0
1.32k stars 51 forks source link

Support unix socket for HTTP #172

Closed domenkozar closed 7 months ago

domenkozar commented 7 months ago

See https://github.com/cachix/devenv/issues/1091

F1bonacc1 commented 7 months ago

Hey @domenkozar,

Can you please explain what is the ask here? Maybe the flag --no-server to disable the process-compose server can help? Process Compose should run on Windows. Is the proposal to maintain both ports and UNIX sockets?

domenkozar commented 7 months ago

Currently port 9999 is opened and I would like to see support for UNIX sockets, so that multiple process-compose can run in parallel.

thenonameguy commented 7 months ago

What Domen is asking for really is a file-based socket, that is easy to spawn more of, without conflict (think tmpfile in a pre-specified folder).

The port 9999 is just a default value for devenv as the current default port commonly conflicts with other HTTP servers.

Support should be added to the process-compose CLI as well to use this method of communicating, by accepting the file path as an env var/explicit arg.

Is the proposal to maintain both ports and UNIX sockets?

Yes.

Maybe the flag --no-server to disable the process-compose server can help?

That helps for the short term, but it's common to have multiple devenv instances running in parallel (subfolders in a monorepo with different process graphs). The --no-server would band-aid the problem, but losing CLI/RPC access would be not a good tradeoff.

adrian-gierakowski commented 7 months ago

You can run multiple instances of PC at different ports

thenonameguy commented 7 months ago

You can run multiple instances of PC at different ports

Thanks, but this is clear to everyone, see the original reply from @domenkozar from yesterday: https://github.com/cachix/devenv/issues/1091#issuecomment-2031063105

To be able to provide an automatic way in devenv to not have port conflicts (without remembering which ports are taken), a file-based socket with a random name allows an external wrapper of process-compose to handle this.

thenonameguy commented 7 months ago
graph TD
    subgraph project1[Random Project 1]
        devenv-1[devenv]
        process-compose-1[Process Compose port 9999]

        devenv-1 --> process-compose-1
    end

    subgraph project2[Random Project 2]
        devenv-2
        process-compose-2[Process Compose port 9999]
        devenv-2 --> process-compose-2
    end

The goal would be to support running 2 random projects at the same time on the same host, without modifying anything. Think of picking 2 random devenv/process-compose projects of of Github.

F1bonacc1 commented 7 months ago

To sum up:

  1. The default behavior will be port based.
  2. I will provide a flag to start with UDS with ports disabled.
  3. The socket file name is optional (?).
  4. The UDS mode won't be available on Windows.

Question: If no socket file name is provided should the default be random: /tmp/process-compose-<random>.sock or predefined: /tmp/process-compose.sock?

Random advantage:

Predefined advantage:

adrian-gierakowski commented 7 months ago

If PC decides a random socket file, how would the client know which file to use when connecting?

thenonameguy commented 7 months ago

Here's how the Clojure NREPL server solves it (that does random port assignment): It randomly chooses an open available port at runtime and writes the number to a gitignored .nrepl-port file. Clients then always look at that file (or the closest file like by walking up the FS tree) to know which port to connect to.

A similar approach could be done with the UDS (.process-compose-uds), although with the above, it might not even be necessary.

domenkozar commented 7 months ago

To sum up:

  1. The default behavior will be port based.
  2. I will provide a flag to start with UDS with ports disabled.
  3. The socket file name is optional (?).
  4. The UDS mode won't be available on Windows.

Question: If no socket file name is provided should the default be random: /tmp/process-compose-<random>.sock or predefined: /tmp/process-compose.sock?

Random advantage:

  • Can start multiple projects with 0 configuration.

Predefined advantage:

  • Clients can connect without additional flags (except UDS mode).

What's important for devenv is to be able to specify the socket path, as we want to store it into $DEVENV_RUNTIME to avoid long paths that sockets are sensitive to.

Something like defaulting to $TMPDIR/process-compose-{pid}.pid and being to override it with $PC_SOCKET_PATH would be ideal.

F1bonacc1 commented 7 months ago

Added in v1.2.0

domenkozar commented 7 months ago

Thank you!