You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

124 lines
4.8 KiB

#!/bin/bash
# Run Orly relay using docker run (alternative to docker-compose)
# Optimized for large dataset imports (20GB+) with memory-conscious settings
#
# Memory optimizations applied:
# - Reduced cache sizes (block: 256MB, index: 128MB)
# - Lower serial caches (pubkeys: 50k, event IDs: 250k)
# - Explicit rate limit target (1500MB) to prevent auto-detection issues
# - Fixed emergency thresholds (1.167/0.833 instead of 4.0/3.0)
# - Query result limit (256) to prevent unbounded memory usage
# - Reduced max connections (500 instead of 1000)
set -e
CONTAINER_NAME="orly-relay"
# Auto-detect version or use default
# Try multiple methods to detect version
VERSION=""
if command -v git &> /dev/null && [ -d .git ]; then
VERSION=$(git describe --tags --abbrev=0 2>/dev/null | sed 's/^v//' || echo "")
fi
if [ -z "$VERSION" ] && [ -f pkg/version/version ]; then
VERSION=$(cat pkg/version/version 2>/dev/null | tr -d ' \n' | sed 's/^v//' || echo "")
fi
# Fallback to default if still empty
if [ -z "$VERSION" ]; then
VERSION="0.58.10"
fi
# Ensure version starts with 'v'
if [[ ! "$VERSION" =~ ^v ]]; then
VERSION="v${VERSION}"
fi
IMAGE="silberengel/next-orly:${VERSION}"
# Data directory on host filesystem (change this to your desired path)
# Using bind mount instead of volume for better performance with large datasets
DATA_DIR="${ORLY_DATA_DIR:-/var/lib/orly}"
# Create data directory if it doesn't exist
mkdir -p "${DATA_DIR}"
# Set ownership to UID 1000 (orly user in container) and permissions
chown -R 1000:1000 "${DATA_DIR}" 2>/dev/null || {
echo "Warning: Could not set ownership of ${DATA_DIR} to UID 1000"
echo "You may need to run: sudo chown -R 1000:1000 ${DATA_DIR}"
}
chmod 755 "${DATA_DIR}"
# Pull the latest image
echo "Pulling ${IMAGE}..."
docker pull ${IMAGE}
# Check if container already exists
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo "Container ${CONTAINER_NAME} already exists."
echo "Removing existing container..."
docker rm -f ${CONTAINER_NAME} 2>/dev/null || true
fi
# Run the container
echo "Starting ${CONTAINER_NAME}..."
docker run -d \
--name ${CONTAINER_NAME} \
--restart always \
-p 0.0.0.0:3334:3334 \
-p 0.0.0.0:7777:7777 \
-v "${DATA_DIR}:/data" \
--memory=4096m \
--cpus="2.0" \
--oom-kill-disable=false \
--health-cmd="curl -f http://localhost:7777/ || exit 1" \
--health-interval=10s \
--health-timeout=5s \
--health-start-period=20s \
--health-retries=3 \
-e ORLY_DATA_DIR=/data \
-e ORLY_LISTEN=0.0.0.0 \
-e ORLY_PORT=7777 \
-e ORLY_LOG_LEVEL=Warn \
-e NOSTR_PRIVATE_KEY="${NOSTR_PRIVATE_KEY:-}" \
-e ORLY_ADMINS=npub1m4ny6hjqzepn4rxknuq94c2gpqzr29ufkkw7ttcxyak7v43n6vvsajc2jl,npub1v30tsz9vw6ylpz63g0a702nj3xa26t3m7p5us8f2y2sd8v6cnsvq465zjx,npub12umrfdjgvdxt45g0y3ghwcyfagssjrv5qlm3t6pu2aa5vydwdmwq8q0z04,npub18cddpua960qjy3wmw7y9gmzr4h3ajlrwq3k9jnmqzlxke4qkg6gqeyaztw \
-e ORLY_OWNERS=npub1m4ny6hjqzepn4rxknuq94c2gpqzr29ufkkw7ttcxyak7v43n6vvsajc2jl,npub1v30tsz9vw6ylpz63g0a702nj3xa26t3m7p5us8f2y2sd8v6cnsvq465zjx,npub12umrfdjgvdxt45g0y3ghwcyfagssjrv5qlm3t6pu2aa5vydwdmwq8q0z04,npub18cddpua960qjy3wmw7y9gmzr4h3ajlrwq3k9jnmqzlxke4qkg6gqeyaztw \
-e ORLY_ACL_MODE=follows \
-e ORLY_SPIDER_MODE=follows \
-e ORLY_RELAY_URL=wss://orly-relay.imwald.eu \
-e ORLY_SPROCKET_ENABLED=false \
-e ORLY_DB_LOG_LEVEL=error \
-e ORLY_DB_BLOCK_CACHE_MB=256 \
-e ORLY_DB_INDEX_CACHE_MB=128 \
-e ORLY_SERIAL_CACHE_PUBKEYS=50000 \
-e ORLY_SERIAL_CACHE_EVENT_IDS=250000 \
-e ORLY_DB_ZSTD_LEVEL=9 \
-e ORLY_GC_ENABLED=true \
-e ORLY_GC_BATCH_SIZE=5000 \
-e ORLY_MAX_STORAGE_BYTES=107374182400 \
-e ORLY_BOOTSTRAP_RELAYS=wss://profiles.nostr1.com,wss://purplepag.es,wss://relay.nostr.band,wss://relay.damus.io \
-e ORLY_SUBSCRIPTION_ENABLED=false \
-e ORLY_MONTHLY_PRICE_SAT=0 \
-e ORLY_MAX_CONNECTIONS=500 \
-e ORLY_MAX_EVENT_SIZE=65536 \
-e ORLY_MAX_SUBSCRIPTIONS=20 \
-e ORLY_QUERY_RESULT_LIMIT=256 \
-e ORLY_WEB_DISABLE=false \
-e ORLY_WEB_DEV_PROXY_URL="" \
-e ORLY_RATE_LIMIT_ENABLED=true \
-e ORLY_RATE_LIMIT_TARGET_MB=1500 \
-e ORLY_RATE_LIMIT_WRITE_TARGET=0.70 \
-e ORLY_RATE_LIMIT_WRITE_KP=1.0 \
-e ORLY_RATE_LIMIT_WRITE_KI=0.2 \
-e ORLY_RATE_LIMIT_MAX_WRITE_MS=2000 \
-e ORLY_RATE_LIMIT_EMERGENCY_THRESHOLD=1.167 \
-e ORLY_RATE_LIMIT_RECOVERY_THRESHOLD=0.833 \
-e ORLY_RATE_LIMIT_EMERGENCY_MAX_MS=5000 \
${IMAGE}
echo ""
echo "Container started!"
echo "Data directory: ${DATA_DIR}"
echo "View logs: docker logs -f ${CONTAINER_NAME}"
echo "Stop: docker stop ${CONTAINER_NAME}"
echo "Start: docker start ${CONTAINER_NAME}"
echo "Remove: docker rm -f ${CONTAINER_NAME}"
echo ""
echo "For large imports (20GB+), use the web UI or API:"
echo " curl -X POST -F 'file=@your-events.jsonl' http://localhost:7777/api/import"