mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-14 10:34:06 +02:00
Libre threads (#5303)
# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
@@ -0,0 +1,212 @@
|
||||
# Stirling-PDF with Remote UNO Servers
|
||||
|
||||
This docker-compose configuration demonstrates running Stirling-PDF with **separate UNO server containers** for LibreOffice document conversion, enabling horizontal scaling and better resource isolation.
|
||||
|
||||
## Architecture
|
||||
|
||||
```
|
||||
┌─────────────────────┐
|
||||
│ Stirling-PDF │
|
||||
│ (Main App) │
|
||||
│ │
|
||||
│ Uses BlockingQueue │
|
||||
│ pool to distribute │
|
||||
│ load across servers │
|
||||
└──────┬──────┬───────┘
|
||||
│ │
|
||||
│ │ Remote endpoints
|
||||
│ │ (hostLocation: remote)
|
||||
│ │
|
||||
┌───▼──┐ ┌─▼────┐
|
||||
│ UNO │ │ UNO │
|
||||
│ #1 │ │ #2 │
|
||||
│:2002 │ │:2002 │
|
||||
└──────┘ └──────┘
|
||||
```
|
||||
|
||||
## Key Features Demonstrated
|
||||
|
||||
### 1. Remote UNO Server Configuration
|
||||
- **hostLocation: "remote"** - Required for cross-container communication
|
||||
- **BlockingQueue pool** - Optimal endpoint selection under load
|
||||
- **Health checks** - Each UNO server has `unoping` health check
|
||||
|
||||
### 2. Environment Variable Configuration
|
||||
```yaml
|
||||
PROCESS_EXECUTOR_AUTO_UNO_SERVER: "false" # Disable local servers
|
||||
|
||||
# Define remote endpoints (Spring Boot list syntax)
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_HOST: "unoserver1"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_PORT: "2002"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_HOST_LOCATION: "remote" # Critical!
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_PROTOCOL: "http"
|
||||
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_HOST: "unoserver2"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_PORT: "2002"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_HOST_LOCATION: "remote"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_PROTOCOL: "http"
|
||||
```
|
||||
|
||||
### 3. Session Limit
|
||||
```yaml
|
||||
PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT: "2"
|
||||
```
|
||||
Should match endpoint count for optimal concurrency.
|
||||
|
||||
## Usage
|
||||
|
||||
### Start the Stack
|
||||
```bash
|
||||
docker compose -f docker-compose-latest-security-remote-uno.yml up -d
|
||||
```
|
||||
|
||||
### Monitor Logs
|
||||
```bash
|
||||
# Watch all services
|
||||
docker compose -f docker-compose-latest-security-remote-uno.yml logs -f
|
||||
|
||||
# Watch just UNO servers
|
||||
docker compose -f docker-compose-latest-security-remote-uno.yml logs -f unoserver1 unoserver2
|
||||
|
||||
# Watch main app
|
||||
docker compose -f docker-compose-latest-security-remote-uno.yml logs -f stirling-pdf
|
||||
```
|
||||
|
||||
### Health Check Status
|
||||
```bash
|
||||
docker compose -f docker-compose-latest-security-remote-uno.yml ps
|
||||
```
|
||||
|
||||
Should show all services healthy:
|
||||
```
|
||||
NAME STATUS
|
||||
Stirling-PDF-Security-Remote-UNO Up (healthy)
|
||||
UNO-Server-1 Up (healthy)
|
||||
UNO-Server-2 Up (healthy)
|
||||
```
|
||||
|
||||
### Test Conversion Load Distribution
|
||||
Upload multiple documents for conversion and watch the logs - you'll see requests distributed across both UNO servers via the BlockingQueue pool.
|
||||
|
||||
## Scaling UNO Servers
|
||||
|
||||
### Add More Servers
|
||||
To add a 3rd UNO server:
|
||||
|
||||
1. Add service to compose file:
|
||||
```yaml
|
||||
unoserver3:
|
||||
container_name: UNO-Server-3
|
||||
image: ghcr.io/unoconv/unoserver-docker:0.4.4
|
||||
# ... same config as unoserver1/2
|
||||
```
|
||||
|
||||
2. Add environment variables to stirling-pdf service:
|
||||
```yaml
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_2_HOST: "unoserver3"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_2_PORT: "2002"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_2_HOST_LOCATION: "remote"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_2_PROTOCOL: "http"
|
||||
PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT: "3" # Update!
|
||||
```
|
||||
|
||||
3. Add to `depends_on`:
|
||||
```yaml
|
||||
depends_on:
|
||||
unoserver1:
|
||||
condition: service_healthy
|
||||
unoserver2:
|
||||
condition: service_healthy
|
||||
unoserver3:
|
||||
condition: service_healthy
|
||||
```
|
||||
|
||||
### Scale with Docker Compose (Alternative)
|
||||
```bash
|
||||
docker compose -f docker-compose-latest-security-remote-uno.yml up -d --scale unoserver1=3
|
||||
```
|
||||
Note: This requires removing `container_name` and hardcoded ports.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### "Connection refused" errors
|
||||
- **Cause**: `hostLocation: "auto"` or missing
|
||||
- **Fix**: Set `HOSTLOCATION: "remote"` for all endpoints
|
||||
|
||||
### Conversions using only one server
|
||||
- **Cause**: Session limit too low or not matching endpoint count
|
||||
- **Fix**: Set `PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT` to match endpoint count
|
||||
|
||||
### UNO server not starting
|
||||
- **Check**: `docker compose logs unoserver1`
|
||||
- **Common**: LibreOffice profile corruption
|
||||
- **Fix**: `docker compose down -v` (removes volumes)
|
||||
|
||||
## Comparison: Local vs Remote UNO Servers
|
||||
|
||||
### Local (Auto) Mode
|
||||
```yaml
|
||||
PROCESS_EXECUTOR_AUTO_UNO_SERVER: "true"
|
||||
PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT: "2"
|
||||
# Creates 2 servers on 127.0.0.1:2003, 127.0.0.1:2005 inside container (Stirling-PDF's own servers)
|
||||
```
|
||||
- ✅ Simpler configuration
|
||||
- ✅ Lower latency
|
||||
- ❌ All in one container (resource competition)
|
||||
- ❌ Can't scale independently
|
||||
|
||||
### Remote Mode (This File)
|
||||
```yaml
|
||||
PROCESS_EXECUTOR_AUTO_UNO_SERVER: "false"
|
||||
# Define external endpoints with hostLocation: "remote"
|
||||
```
|
||||
- ✅ Resource isolation (separate containers)
|
||||
- ✅ Independent scaling
|
||||
- ✅ Better resilience (restart one without affecting others)
|
||||
- ❌ Slightly higher network overhead
|
||||
- ❌ More complex configuration
|
||||
|
||||
## Advanced Configuration
|
||||
|
||||
### HTTPS UNO Servers
|
||||
If your UNO servers use HTTPS (e.g., behind a reverse proxy):
|
||||
```yaml
|
||||
PROCESS_EXECUTOR_UNOSERVERENDPOINTS_0_PROTOCOL: "https"
|
||||
```
|
||||
|
||||
### Custom Health Check Interval
|
||||
```yaml
|
||||
unoserver1:
|
||||
healthcheck:
|
||||
interval: 5s # Check more frequently
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
start_period: 60s # Give more startup time
|
||||
```
|
||||
|
||||
### Debug Mode
|
||||
To see detailed endpoint selection logs:
|
||||
```yaml
|
||||
environment:
|
||||
LOGGING_LEVEL_STIRLING_SOFTWARE_COMMON_UTIL_PROCESSEXECUTOR: DEBUG
|
||||
```
|
||||
|
||||
## What This Demonstrates
|
||||
|
||||
This configuration showcases all the improvements from the PR reviews:
|
||||
|
||||
1. ✅ **Remote endpoint support** (`hostLocation: "remote"`)
|
||||
2. ✅ **BlockingQueue pool** (optimal endpoint distribution)
|
||||
3. ✅ **Idempotent lease close** (thread-safe)
|
||||
4. ✅ **Robust health checks** (unoping → TCP → PID fallbacks)
|
||||
5. ✅ **Proper validation** (hostLocation/protocol normalized)
|
||||
6. ✅ **Session limit warnings** (logs mismatch if misconfigured)
|
||||
|
||||
## Performance Expectations
|
||||
|
||||
With 2 UNO servers, you can expect:
|
||||
- **2x concurrent conversions** vs single server
|
||||
- **~50% reduction in queue wait time** under load
|
||||
- **Better resilience**: One server failure = 50% capacity, not 0%
|
||||
|
||||
Tested with 100GB+ PDFs - BlockingQueue ensures no endpoint starvation.
|
||||
@@ -0,0 +1,99 @@
|
||||
services:
|
||||
stirling-pdf:
|
||||
container_name: Stirling-PDF-Security-Remote-UNO
|
||||
image: docker.stirlingpdf.com/stirlingtools/stirling-pdf:latest
|
||||
build:
|
||||
context: ../../..
|
||||
dockerfile: docker/embedded/Dockerfile
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP'"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
retries: 16
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- ../../../stirling/latest/data:/usr/share/tessdata:rw
|
||||
- ../../../stirling/latest/config:/configs:rw
|
||||
- ../../../stirling/latest/logs:/logs:rw
|
||||
- stirling-tmp:/tmp/stirling-pdf:rw
|
||||
environment:
|
||||
DISABLE_ADDITIONAL_FEATURES: "false"
|
||||
SECURITY_ENABLELOGIN: "false"
|
||||
# Disable auto UNO server (we're using remote servers instead)
|
||||
PROCESS_EXECUTOR_AUTO_UNO_SERVER: "false"
|
||||
# Configure remote UNO server pool
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_HOST: "unoserver1"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_PORT: "2003"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_HOST_LOCATION: "remote"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_0_PROTOCOL: "http"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_HOST: "unoserver2"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_PORT: "2003"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_HOST_LOCATION: "remote"
|
||||
PROCESS_EXECUTOR_UNO_SERVER_ENDPOINTS_1_PROTOCOL: "http"
|
||||
# Session limit should match endpoint count for optimal concurrency
|
||||
PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT: "2"
|
||||
PUID: 1002
|
||||
PGID: 1002
|
||||
UMASK: "022"
|
||||
SYSTEM_DEFAULTLOCALE: en-US
|
||||
UI_APPNAME: Stirling-PDF
|
||||
UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest with Security + Remote UNO Servers
|
||||
UI_APPNAMENAVBAR: Stirling-PDF Latest
|
||||
SYSTEM_MAXFILESIZE: "100"
|
||||
METRICS_ENABLED: "true"
|
||||
SYSTEM_GOOGLEVISIBILITY: "true"
|
||||
SHOW_SURVEY: "true"
|
||||
depends_on:
|
||||
unoserver1:
|
||||
condition: service_healthy
|
||||
unoserver2:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- stirling-network
|
||||
restart: on-failure:5
|
||||
|
||||
unoserver1:
|
||||
container_name: UNO-Server-1
|
||||
# NOTE: This image needs to be updated to unoserver 3.6 to match Stirling-PDF's client version
|
||||
# Current :latest uses 3.4 which causes API mismatch errors
|
||||
image: ghcr.io/unoconv/unoserver-docker:latest
|
||||
volumes:
|
||||
- stirling-tmp:/tmp/stirling-pdf:rw
|
||||
expose:
|
||||
- "2003"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "timeout 2 bash -c 'cat < /dev/null > /dev/tcp/localhost/2003' || exit 1"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
networks:
|
||||
- stirling-network
|
||||
restart: on-failure:5
|
||||
|
||||
unoserver2:
|
||||
container_name: UNO-Server-2
|
||||
# NOTE: This image needs to be updated to unoserver 3.6 to match Stirling-PDF's client version
|
||||
# Current :latest uses 3.4 which causes API mismatch errors
|
||||
image: ghcr.io/unoconv/unoserver-docker:latest
|
||||
volumes:
|
||||
- stirling-tmp:/tmp/stirling-pdf:rw
|
||||
expose:
|
||||
- "2003"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "timeout 2 bash -c 'cat < /dev/null > /dev/tcp/localhost/2003' || exit 1"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 30s
|
||||
networks:
|
||||
- stirling-network
|
||||
restart: on-failure:5
|
||||
|
||||
networks:
|
||||
stirling-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
stirling-tmp:
|
||||
@@ -0,0 +1,35 @@
|
||||
services:
|
||||
stirling-pdf:
|
||||
container_name: Stirling-PDF-Security
|
||||
image: docker.stirlingpdf.com/stirlingtools/stirling-pdf:latest
|
||||
build:
|
||||
context: ../../..
|
||||
dockerfile: docker/embedded/Dockerfile
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "curl -f http://localhost:8080/api/v1/info/status | grep -q 'UP'"]
|
||||
interval: 5s
|
||||
timeout: 10s
|
||||
retries: 16
|
||||
ports:
|
||||
- 8080:8080
|
||||
volumes:
|
||||
- ../../../stirling/latest/data:/usr/share/tessdata:rw
|
||||
- ../../../stirling/latest/config:/configs:rw
|
||||
- ../../../stirling/latest/logs:/logs:rw
|
||||
environment:
|
||||
DISABLE_ADDITIONAL_FEATURES: "false"
|
||||
SECURITY_ENABLELOGIN: "false"
|
||||
PROCESS_EXECUTOR_AUTO_UNO_SERVER: "true"
|
||||
PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT: "1"
|
||||
PUID: 1002
|
||||
PGID: 1002
|
||||
UMASK: "022"
|
||||
SYSTEM_DEFAULTLOCALE: en-US
|
||||
UI_APPNAME: Stirling-PDF
|
||||
UI_HOMEDESCRIPTION: Demo site for Stirling-PDF Latest with Security
|
||||
UI_APPNAMENAVBAR: Stirling-PDF Latest
|
||||
SYSTEM_MAXFILESIZE: "100"
|
||||
METRICS_ENABLED: "true"
|
||||
SYSTEM_GOOGLEVISIBILITY: "true"
|
||||
SHOW_SURVEY: "true"
|
||||
restart: on-failure:5
|
||||
@@ -119,6 +119,11 @@ All modes support standard Stirling-PDF environment variables:
|
||||
- `SYSTEM_MAXFILESIZE` - Max upload size (MB)
|
||||
- `TESSERACT_LANGS` - Comma-separated OCR language codes
|
||||
- `JAVA_CUSTOM_OPTS` - Additional JVM options
|
||||
- `PROCESS_EXECUTOR_AUTO_UNO_SERVER` - Overrides `processExecutor.autoUnoServer` (true or false)
|
||||
- `PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT` - Overrides `processExecutor.sessionLimit.libreOfficeSessionLimit`
|
||||
- `UNO_SERVER_AUTO` - Legacy alias for `processExecutor.autoUnoServer`
|
||||
- `UNO_SERVER_COUNT` - Legacy alias for `processExecutor.sessionLimit.libreOfficeSessionLimit`
|
||||
- `UNO_SERVER_HEALTH_INTERVAL` - Seconds between unoserver PID checks (default: 30)
|
||||
|
||||
See full configuration docs at: https://docs.stirlingpdf.com
|
||||
|
||||
|
||||
+205
-10
@@ -30,14 +30,14 @@ setup_ocr() {
|
||||
# The cp -rn above won't overwrite user files, just adds missing system files.
|
||||
|
||||
# Install additional languages if specified
|
||||
if [[ -n "$TESSERACT_LANGS" ]]; then
|
||||
if [ -n "$TESSERACT_LANGS" ]; then
|
||||
SPACE_SEPARATED_LANGS=$(echo $TESSERACT_LANGS | tr ',' ' ')
|
||||
pattern='^[a-zA-Z]{2,4}(_[a-zA-Z]{2,4})?$'
|
||||
for LANG in $SPACE_SEPARATED_LANGS; do
|
||||
if [[ $LANG =~ $pattern ]]; then
|
||||
echo "Installing tesseract language: $LANG"
|
||||
apk add --no-cache "tesseract-ocr-data-$LANG" 2>/dev/null || true
|
||||
fi
|
||||
case "$LANG" in
|
||||
[a-zA-Z][a-zA-Z]|[a-zA-Z][a-zA-Z][a-zA-Z]|[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]|[a-zA-Z][a-zA-Z]_[a-zA-Z][a-zA-Z]|[a-zA-Z][a-zA-Z][a-zA-Z]_[a-zA-Z][a-zA-Z][a-zA-Z]|[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z]_[a-zA-Z][a-zA-Z][a-zA-Z][a-zA-Z])
|
||||
apk add --no-cache "tesseract-ocr-data-$LANG" 2>/dev/null || true
|
||||
;;
|
||||
esac
|
||||
done
|
||||
fi
|
||||
|
||||
@@ -100,6 +100,201 @@ run_as_user() {
|
||||
fi
|
||||
}
|
||||
|
||||
run_with_timeout() {
|
||||
local secs=$1; shift
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
timeout "${secs}s" "$@"
|
||||
else
|
||||
"$@"
|
||||
fi
|
||||
}
|
||||
|
||||
run_as_user_with_timeout() {
|
||||
local secs=$1; shift
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
run_as_user timeout "${secs}s" "$@"
|
||||
else
|
||||
run_as_user "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
tcp_port_check() {
|
||||
local host=$1
|
||||
local port=$2
|
||||
local timeout_secs=${3:-5}
|
||||
|
||||
# Try nc first (most portable)
|
||||
if command -v nc >/dev/null 2>&1; then
|
||||
run_with_timeout "$timeout_secs" nc -z "$host" "$port" 2>/dev/null
|
||||
return $?
|
||||
fi
|
||||
|
||||
# Fallback to /dev/tcp (bash-specific)
|
||||
if [ -n "${BASH_VERSION:-}" ] && command -v bash >/dev/null 2>&1; then
|
||||
run_with_timeout "$timeout_secs" bash -c "exec 3<>/dev/tcp/${host}/${port}" 2>/dev/null
|
||||
local result=$?
|
||||
exec 3>&- 2>/dev/null || true
|
||||
return $result
|
||||
fi
|
||||
|
||||
# No TCP check method available
|
||||
return 2
|
||||
}
|
||||
|
||||
CONFIG_FILE=${CONFIG_FILE:-/configs/settings.yml}
|
||||
UNOSERVER_PIDS=()
|
||||
UNOSERVER_PORTS=()
|
||||
UNOSERVER_UNO_PORTS=()
|
||||
|
||||
read_setting_value() {
|
||||
local key=$1
|
||||
if [ ! -f "$CONFIG_FILE" ]; then
|
||||
return
|
||||
fi
|
||||
awk -F: -v key="$key" '
|
||||
$1 ~ "^[[:space:]]*"key"[[:space:]]*$" {
|
||||
val=$2
|
||||
sub(/#.*/, "", val)
|
||||
gsub(/^[[:space:]]+|[[:space:]]+$/, "", val)
|
||||
gsub(/^["'"'"']|["'"'"']$/, "", val)
|
||||
print val
|
||||
exit
|
||||
}
|
||||
' "$CONFIG_FILE"
|
||||
}
|
||||
|
||||
get_unoserver_auto() {
|
||||
if [ -n "${PROCESS_EXECUTOR_AUTO_UNO_SERVER:-}" ]; then
|
||||
echo "$PROCESS_EXECUTOR_AUTO_UNO_SERVER"
|
||||
return
|
||||
fi
|
||||
if [ -n "${UNO_SERVER_AUTO:-}" ]; then
|
||||
echo "$UNO_SERVER_AUTO"
|
||||
return
|
||||
fi
|
||||
read_setting_value "autoUnoServer"
|
||||
}
|
||||
|
||||
get_unoserver_count() {
|
||||
if [ -n "${PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT:-}" ]; then
|
||||
echo "$PROCESS_EXECUTOR_SESSION_LIMIT_LIBRE_OFFICE_SESSION_LIMIT"
|
||||
return
|
||||
fi
|
||||
if [ -n "${UNO_SERVER_COUNT:-}" ]; then
|
||||
echo "$UNO_SERVER_COUNT"
|
||||
return
|
||||
fi
|
||||
read_setting_value "libreOfficeSessionLimit"
|
||||
}
|
||||
|
||||
start_unoserver_instance() {
|
||||
local port=$1
|
||||
local uno_port=$2
|
||||
run_as_user /opt/venv/bin/unoserver --port "$port" --interface 127.0.0.1 --uno-port "$uno_port" &
|
||||
LAST_UNOSERVER_PID=$!
|
||||
}
|
||||
|
||||
start_unoserver_watchdog() {
|
||||
local interval=${UNO_SERVER_HEALTH_INTERVAL:-30}
|
||||
case "$interval" in
|
||||
''|*[!0-9]*) interval=30 ;;
|
||||
esac
|
||||
(
|
||||
while true; do
|
||||
local i=0
|
||||
while [ "$i" -lt "${#UNOSERVER_PIDS[@]}" ]; do
|
||||
local pid=${UNOSERVER_PIDS[$i]}
|
||||
local port=${UNOSERVER_PORTS[$i]}
|
||||
local uno_port=${UNOSERVER_UNO_PORTS[$i]}
|
||||
local needs_restart=false
|
||||
|
||||
# Check 1: PID exists
|
||||
if [ -z "$pid" ] || ! kill -0 "$pid" 2>/dev/null; then
|
||||
echo "unoserver PID ${pid} not found for port ${port}"
|
||||
needs_restart=true
|
||||
else
|
||||
# PID exists, now check if server is actually healthy
|
||||
local health_ok=false
|
||||
|
||||
# Check 2A: Health check with unoping (best - checks actual server health)
|
||||
if command -v unoping >/dev/null 2>&1; then
|
||||
if run_as_user_with_timeout 5 unoping --host 127.0.0.1 --port "$port" >/dev/null 2>&1; then
|
||||
health_ok=true
|
||||
else
|
||||
echo "unoserver health check failed (unoping) for port ${port}, trying TCP fallback"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check 2B: Fallback to TCP port check (verifies service is listening)
|
||||
if [ "$health_ok" = false ]; then
|
||||
tcp_port_check "127.0.0.1" "$port" 5
|
||||
local tcp_rc=$?
|
||||
if [ $tcp_rc -eq 0 ]; then
|
||||
health_ok=true
|
||||
elif [ $tcp_rc -eq 2 ]; then
|
||||
echo "No TCP check available; falling back to PID-only for port ${port}"
|
||||
health_ok=true
|
||||
else
|
||||
echo "unoserver TCP check failed for port ${port}"
|
||||
needs_restart=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$needs_restart" = true ]; then
|
||||
echo "Restarting unoserver on 127.0.0.1:${port} (uno-port ${uno_port})"
|
||||
# Kill the old process if it exists
|
||||
if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then
|
||||
kill -TERM "$pid" 2>/dev/null || true
|
||||
sleep 1
|
||||
kill -KILL "$pid" 2>/dev/null || true
|
||||
fi
|
||||
start_unoserver_instance "$port" "$uno_port"
|
||||
UNOSERVER_PIDS[$i]=$LAST_UNOSERVER_PID
|
||||
fi
|
||||
i=$((i + 1))
|
||||
done
|
||||
sleep "$interval"
|
||||
done
|
||||
) &
|
||||
}
|
||||
|
||||
start_unoserver_pool() {
|
||||
local auto
|
||||
auto="$(get_unoserver_auto)"
|
||||
auto="${auto,,}"
|
||||
if [ -z "$auto" ]; then
|
||||
auto="true"
|
||||
fi
|
||||
if [ "$auto" != "true" ]; then
|
||||
echo "Skipping local unoserver pool (autoUnoServer=$auto)"
|
||||
return
|
||||
fi
|
||||
|
||||
local count
|
||||
count="$(get_unoserver_count)"
|
||||
case "$count" in
|
||||
''|*[!0-9]*) count=1 ;;
|
||||
esac
|
||||
if [ "$count" -le 0 ]; then
|
||||
count=1
|
||||
fi
|
||||
|
||||
local i=0
|
||||
while [ "$i" -lt "$count" ]; do
|
||||
local port=$((2003 + (i * 2)))
|
||||
local uno_port=$((2004 + (i * 2)))
|
||||
echo "Starting unoserver on 127.0.0.1:${port} (uno-port ${uno_port})"
|
||||
UNOSERVER_PORTS+=("$port")
|
||||
UNOSERVER_UNO_PORTS+=("$uno_port")
|
||||
start_unoserver_instance "$port" "$uno_port"
|
||||
UNOSERVER_PIDS+=("$LAST_UNOSERVER_PID")
|
||||
i=$((i + 1))
|
||||
done
|
||||
|
||||
start_unoserver_watchdog
|
||||
}
|
||||
|
||||
# Setup OCR and permissions
|
||||
setup_ocr
|
||||
setup_permissions
|
||||
@@ -120,9 +315,8 @@ case "$MODE" in
|
||||
-jar /app.jar" &
|
||||
BACKEND_PID=$!
|
||||
|
||||
# Start unoserver for document conversion
|
||||
run_as_user /opt/venv/bin/unoserver --port 2003 --interface 127.0.0.1 &
|
||||
UNO_PID=$!
|
||||
# Start unoserver pool for document conversion
|
||||
start_unoserver_pool
|
||||
|
||||
# Wait for backend to start
|
||||
sleep 3
|
||||
@@ -165,8 +359,9 @@ case "$MODE" in
|
||||
run_as_user sh -c "java -Dfile.encoding=UTF-8 \
|
||||
-Djava.io.tmpdir=/tmp/stirling-pdf \
|
||||
-Dserver.port=8080 \
|
||||
-jar /app.jar & /opt/venv/bin/unoserver --port 2003 --interface 127.0.0.1" &
|
||||
-jar /app.jar" &
|
||||
BACKEND_PID=$!
|
||||
start_unoserver_pool
|
||||
|
||||
echo "==================================="
|
||||
echo "✓ Backend API available at: http://localhost:8080/api"
|
||||
|
||||
Reference in New Issue
Block a user