From 24c5c05308abaffe59f84a403b0d7c27c772700b Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 4 Oct 2024 19:30:57 +0300 Subject: [PATCH 1/3] Give friendlier messages when cgroup v2 is not enabled --- api/src/docker-entrypoint.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/api/src/docker-entrypoint.sh b/api/src/docker-entrypoint.sh index 7cf37e3..2a4e49c 100755 --- a/api/src/docker-entrypoint.sh +++ b/api/src/docker-entrypoint.sh @@ -1,5 +1,21 @@ #!/bin/bash +CGROUP_FS="/sys/fs/cgroup" +if [ ! -e "$CGROUP_FS" ]; then + echo "Cannot find $CGROUP_FS. Please make sure your system is using cgroup v2" + exit 1 +fi + +if [ -e "$CGROUP_FS/unified" ]; then + echo "Combined cgroup v1+v2 mode is not supported. Please make sure your system is using pure cgroup v2" + exit 1 +fi + +if [ ! -e "$CGROUP_FS/cgroup.subtree_control" ]; then + echo "Cgroup v2 not found. Please make sure cgroup v2 is enabled on your system" + exit 1 +fi + cd /sys/fs/cgroup && \ mkdir isolate/ && \ echo 1 > isolate/cgroup.procs && \ From 512b63d2b50902cb4a79ad85dfa1e726ec0f4041 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 4 Oct 2024 19:53:33 +0300 Subject: [PATCH 2/3] Document interactive execution --- readme.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/readme.md b/readme.md index f1172d3..9034264 100644 --- a/readme.md +++ b/readme.md @@ -320,6 +320,40 @@ Content-Type: application/json } ``` +#### Interactive execution endpoint (not available through the public API) + +To interact with running processes in real time, you can establish a WebSocket connection at `/api/v2/connect`. This allows you to both receive output and send input to active processes. + +Each message is structured as a JSON object with a `type` key, which indicates the action to perform. Below is a list of message types, their directions, and descriptions: + +- **init** (client -> server): Initializes a job with the same parameters as the `/execute` endpoint, except that stdin is discarded. +- **runtime** (server -> client): Provides details on the runtime environment, including the version and language. +- **stage** (server -> client): Indicates the current execution stage, either "compile" or "run." +- **data** (server <-> client): Exchanges data between the client and server, such as stdin, stdout, or stderr streams. +- **signal** (client -> server): Sends a signal (e.g., for termination) to the running process, whether it's in the "compile" or "run" stage. +- **exit** (server -> client): Signals the end of a stage, along with the exit code or signal. +- **error** (server -> client): Reports an error, typically right before the WebSocket is closed. + +An example of this endpoint in use is depicted below (**<** = client to server, **>** = server to client) + +1. Client establishes WebSocket connection to `/api/v2/connect` +2. **<** `{"type":"init", "language":"bash", "version":"*", "files":[{"content": "cat"}]}` +3. **>** `{"type":"runtime","language": "bash", "version": "5.1.0"}` +4. **>** `{"type":"stage", "stage":"run"}` +5. **<** `{"type":"data", "stream":"stdin", "data":"Hello World!"}` +6. **>** `{"type":"data", "stream":"stdout", "data":"Hello World!"}` +7. _time passes_ +8. **>** `{"type":"exit", "stage":"run", "code":null, "signal": "SIGKILL"}` + +Errors may return status codes as follows: + +- **4000: Already Initialized**: Sent when a second `init` command is issued. +- **4001: Initialization Timeout**: No `init` command was sent within 1 second of connection. +- **4002: Notified Error**: A fatal error occurred, and an `error` packet was transmitted. +- **4003: Not yet Initialized**: A non-`init` command was sent without a job context. +- **4004: Can only write to stdin**: The client attempted to write to a stream other than stdin. +- **4005: Invalid Signal**: An invalid signal was sent in a `signal` packet. +
# Supported Languages From 4e361dcf924b4594f038511ff69752ee1a3f49a9 Mon Sep 17 00:00:00 2001 From: Omar Brikaa Date: Fri, 11 Oct 2024 21:42:58 +0300 Subject: [PATCH 3/3] Add note to ensure the repository is cloned with LF line endings --- readme.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/readme.md b/readme.md index 9034264..7724fdb 100644 --- a/readme.md +++ b/readme.md @@ -114,6 +114,10 @@ POST https://emkc.org/api/v2/piston/execute git clone https://github.com/engineer-man/piston ``` +> [!NOTE] +> +> Ensure the repository is cloned with LF line endings + ### Installation ```sh