From f142e8089c1d2386070f97e2bbe462c3e0e2e0b9 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Sat, 21 Mar 2026 19:49:26 +0100 Subject: [PATCH] added new json-rpc-native mode --- README.md | 3 ++- entrypoint.sh | 2 +- src/main.go | 2 +- src/scripts/jsonrpc2-helper.go | 10 ++++++++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9ef2b7a..6b7d940 100644 --- a/README.md +++ b/README.md @@ -58,13 +58,14 @@ The `signal-cli-rest-api` supports three different modes of execution, which can * **`normal` Mode: (Default)** The `signal-cli` executable is invoked for every REST API request. Being a Java application, each REST call requires a new startup of the JVM (Java Virtual Machine), increasing the latency and hence leading to the slowest mode of operation. * **`native` Mode:** A precompiled binary `signal-cli-native` (using GraalVM) is used for every REST API request. This results in a much lower latency & memory usage on each call. On the `armv7` platform this mode is not available and falls back to `normal`. The native mode may also be less stable, due to the experimental state of GraalVM compiler. * `json-rpc` Mode: A single, JVM-based `signal-cli` instance is spawned as daemon process. This mode is usually the fastest, but requires more memory as the JVM keeps running. - +* `json-rpc-native` Mode: Uses the `signal-cli-native` binary and starts it in daemon mode (this mode basically combines the advantages of the `native` mode and the `json-rpc` mode). | mode | speed | resident memory usage | | ---------: | :------------------------------------------------------- | :-------------------- | | `normal` | :heavy_check_mark: | normal | | `native` | :heavy_check_mark: :heavy_check_mark: | normal | | `json-rpc` | :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: | increased | +| `json-rpc-native` | :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: :heavy_check_mark: | normal | **Example of running `signal-cli-rest` in `native` mode** diff --git a/entrypoint.sh b/entrypoint.sh index 05363d3..027254a 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -27,7 +27,7 @@ cap_prefix="-cap_" caps="$cap_prefix$(seq -s ",$cap_prefix" 0 $(cat /proc/sys/kernel/cap_last_cap))" # TODO: check mode -if [ "$MODE" = "json-rpc" ] +if [ "$MODE" = "json-rpc" ] || [ "$MODE" = "json-rpc-native" ] then /usr/bin/jsonrpc2-helper if [ -n "$JAVA_OPTS" ] ; then diff --git a/src/main.go b/src/main.go index 6c271ce..b71ab2d 100644 --- a/src/main.go +++ b/src/main.go @@ -123,7 +123,7 @@ func main() { mode := utils.GetEnv("MODE", "normal") if mode == "normal" { signalCliMode = client.Normal - } else if mode == "json-rpc" { + } else if mode == "json-rpc" || mode == "json-rpc-native" { signalCliMode = client.JsonRpc } else if mode == "native" { signalCliMode = client.Native diff --git a/src/scripts/jsonrpc2-helper.go b/src/scripts/jsonrpc2-helper.go index 36e3f0b..cc34071 100644 --- a/src/scripts/jsonrpc2-helper.go +++ b/src/scripts/jsonrpc2-helper.go @@ -13,7 +13,7 @@ import ( const supervisorctlConfigTemplate = ` [program:%s] process_name=%s -command=signal-cli --output=json --config %s%s daemon %s%s%s%s --tcp 127.0.0.1:%d +command=%s --output=json --config %s%s daemon %s%s%s%s --tcp 127.0.0.1:%d autostart=true autorestart=true startretries=10 @@ -43,6 +43,12 @@ func main() { jsonRpc2ClientConfig.AddEntry(utils.MULTI_ACCOUNT_NUMBER, utils.JsonRpc2ClientConfigEntry{TcpPort: tcpPort}) + signalCliBinary := "signal-cli" + signalMode := utils.GetEnv("MODE", "json-rpc") + if signalMode == "json-rpc-native" { + signalCliBinary = "signal-cli-native" + } + signalCliIgnoreAttachments := "" ignoreAttachments := utils.GetEnv("JSON_RPC_IGNORE_ATTACHMENTS", "") if ignoreAttachments == "true" { @@ -91,7 +97,7 @@ func main() { //write supervisorctl config supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf" - supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName, + supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName, signalCliBinary, signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, signalCliIgnoreAvatars, signalCliIgnoreStickers, tcpPort, supervisorctlProgramName, supervisorctlProgramName)