| #!/usr/bin/env bash |
| set -euo pipefail |
|
|
| |
| |
| |
| |
| |
| |
|
|
| DBOPS_ROOT=${DBOPS_ROOT:-/data/adaptai/platform/dbops} |
| SECRETS_DIR=${SECRETS_DIR:-/data/adaptai/secrets/dataops} |
| START_GREMLIN=${START_GREMLIN:-1} |
| JANUS_BACKEND=${JANUS_BACKEND:-scylla} |
|
|
| PROPS_SRC="$DBOPS_ROOT/configs/janusgraph/janusgraph-cql.properties" |
| RUN_DIR="$DBOPS_ROOT/run/janusgraph" |
| PROPS_OUT="$RUN_DIR/janusgraph-cql.runtime.properties" |
| GREMLIN_SRC="$DBOPS_ROOT/configs/janusgraph/gremlin-server.yaml" |
| GREMLIN_OUT="$RUN_DIR/gremlin-server.runtime.yaml" |
| JANUS_BIN="$DBOPS_ROOT/binaries/janusgraph/bin/janusgraph-server.sh" |
|
|
| mkdir -p "$RUN_DIR" |
|
|
| |
| if [ -f "$DBOPS_ROOT/.env" ]; then |
| |
| export $(grep -E '^[A-Z0-9_]+=' "$DBOPS_ROOT/.env" | xargs -d'\n' || true) |
| fi |
| if [ -f "$SECRETS_DIR/.env" ]; then |
| |
| export $(grep -E '^(SCYLLA_USER|SCYLLA_PASS)=' "$SECRETS_DIR/.env" | xargs -d'\n' || true) |
| fi |
|
|
| |
| if [ "$JANUS_BACKEND" = "inmemory" ]; then |
| cat > "$PROPS_OUT" <<'CONF' |
| storage.backend=inmemory |
| CONF |
| else |
| cp "$PROPS_SRC" "$PROPS_OUT" |
| |
| : "${SCYLLA_HOSTS:=scylla.dbops.local:17542}" |
| |
| if [ -n "${SCYLLA_HOSTS:-}" ]; then |
| sed -i "s#^storage.hostname=.*#storage.hostname=${SCYLLA_HOSTS}#" "$PROPS_OUT" |
| fi |
| if [ -n "${SCYLLA_DC:-}" ]; then |
| sed -i "s#^storage.cql.local-datacenter=.*#storage.cql.local-datacenter=${SCYLLA_DC}#" "$PROPS_OUT" |
| fi |
| |
| if [ -n "${SCYLLA_USER:-}" ]; then |
| sed -i "s#\${SCYLLA_USER}#${SCYLLA_USER}#g" "$PROPS_OUT" |
| else |
| sed -i "/^storage.username=/d" "$PROPS_OUT" |
| fi |
| if [ -n "${SCYLLA_PASS:-}" ]; then |
| sed -i "s#\${SCYLLA_PASS}#${SCYLLA_PASS}#g" "$PROPS_OUT" |
| else |
| sed -i "/^storage.password=/d" "$PROPS_OUT" |
| fi |
| |
| TRUSTSTORE="$SECRETS_DIR/ca.pem" |
| if [ -f "$TRUSTSTORE" ]; then |
| sed -i "s#^storage.cql.ssl.enabled=.*#storage.cql.ssl.enabled=true#" "$PROPS_OUT" |
| sed -i "s#^storage.cql.ssl.truststore=.*#storage.cql.ssl.truststore=$TRUSTSTORE#" "$PROPS_OUT" |
| else |
| sed -i "s#^storage.cql.ssl.enabled=.*#storage.cql.ssl.enabled=false#" "$PROPS_OUT" |
| sed -i "/^storage.cql.ssl.truststore=/d" "$PROPS_OUT" |
| fi |
| fi |
|
|
| |
| cp "$GREMLIN_SRC" "$GREMLIN_OUT" |
| awk -v repl="graphs:\n graph: $PROPS_OUT" ' |
| BEGIN{inblock=0} |
| /^graphs:/ {print repl; inblock=1; next} |
| inblock && /^scriptEngines:/ {print; inblock=0; next} |
| inblock {next} |
| {print} |
| ' "$GREMLIN_OUT" > "$GREMLIN_OUT.tmp" && mv "$GREMLIN_OUT.tmp" "$GREMLIN_OUT" |
| |
| sed -i '/^scripts:/d' "$GREMLIN_OUT" |
|
|
| echo "Rendered properties -> $PROPS_OUT" |
| echo "Gremlin config -> $GREMLIN_OUT" |
|
|
| if [ "$START_GREMLIN" = "1" ]; then |
| if [ ! -x "$JANUS_BIN" ]; then |
| echo "JanusGraph binary not found: $JANUS_BIN" >&2 |
| echo "Attempting to download JanusGraph 1.1.0 (full)..." >&2 |
| TMPDIR=$(mktemp -d) |
| pushd "$TMPDIR" >/dev/null |
| curl -fsSL -o janusgraph.zip https://github.com/JanusGraph/janusgraph/releases/download/v1.1.0/janusgraph-full-1.1.0.zip |
| mkdir -p janus_tmp && unzip -q janusgraph.zip -d janus_tmp |
| JDIR=$(find janus_tmp -maxdepth 1 -type d -name "janusgraph-*" | head -n1) |
| if [ -z "$JDIR" ]; then |
| echo "Failed to fetch JanusGraph distribution" >&2 |
| exit 2 |
| fi |
| mkdir -p "$DBOPS_ROOT/binaries/janusgraph" |
| cp -r "$JDIR"/* "$DBOPS_ROOT/binaries/janusgraph/" |
| chmod +x "$DBOPS_ROOT/binaries/janusgraph/bin/janusgraph-server.sh" |
| JANUS_BIN="$DBOPS_ROOT/binaries/janusgraph/bin/janusgraph-server.sh" |
| popd >/dev/null |
| rm -rf "$TMPDIR" |
| fi |
| |
| CMD=start |
| if [ "${JG_FOREGROUND:-0}" = "1" ] || [ -n "${SUPERVISOR_ENABLED:-}" ] || [ -n "${SUPERVISOR_PROCESS_NAME:-}" ]; then |
| |
| CMD=console |
| exec "$JANUS_BIN" "$CMD" "$GREMLIN_OUT" |
| fi |
| exec "$JANUS_BIN" "$CMD" "$GREMLIN_OUT" |
| fi |
|
|
| exit 0 |
|
|