Files
apps/signoz/install-signoz.sh
2026-03-26 17:12:37 +05:30

79 lines
2.4 KiB
Bash

#!/bin/bash
APP_NAME="signoz"
APP_DIR="/var/excloud/apps"
SCRIPT_DIR="/var/excloud/scripts"
POSTGRES_DSN="postgres://postgres:your_password@localhost:5432/signoz?sslmode=disable"
mkdir -p "${APP_DIR}"
mkdir -p "${SCRIPT_DIR}"
DOMAIN="${1}"
if [ -z "$DOMAIN" ]; then
echo "Error: URL argument is required. Example:" >&2
echo "install-signoz.sh sub.example.com" >&2
exit 1
fi
JWT_SECRET=$(openssl rand -hex 16 | cut -c-32)
if [ -f "${APP_DIR}/jwt-secret" ]; then
JWT_SECRET=$(cat ${APP_DIR}/jwt-secret)
else
echo $JWT_SECRET > ${APP_DIR}/jwt-secret
fi
SIGNOZ_DIR="${APP_DIR}/signoz"
COMPOSE_FILE="${SIGNOZ_DIR}/deploy/docker/docker-compose.yaml"
OTEL_SERVICE_PATH='.services["otel-collector"].ports'
SIGNOZ_SERVICE_PATH=".services.signoz.ports"
apt-get install -y caddy yq
if git -C ${SIGNOZ_DIR} rev-parse 2>/dev/null; then
echo "Git repo exists"
else
git clone -b main https://github.com/SigNoz/signoz.git ${SIGNOZ_DIR}
fi
cd ${SIGNOZ_DIR}/deploy/docker
set_port() {
local port_pair="$1"
local service_path="$2"
local port_num="${port_pair##*:}"
if yq "${service_path}[] | select(. == ${port_num} or (type == \"string\" and test(\"${port_num}:${port_num}\")))" "$COMPOSE_FILE" | grep -q .; then
yq -yi "(${service_path}[] | select(. == ${port_num} or (type == \"string\" and test(\"${port_num}:${port_num}\")))) = \"${port_pair}\"" "$COMPOSE_FILE"
echo "Replaced: ${port_pair}"
else
yq -yi "${service_path} += [\"${port_pair}\"]" "$COMPOSE_FILE"
echo "Added: ${port_pair}"
fi
}
set_env() {
local key="$1"
local value="$2"
local service_path="$3"
local env_pair="${key}=${value}"
if yq "${service_path}" "$COMPOSE_FILE" | grep -q "${key}="; then
yq -yi "(${service_path}[] | select(type == \"string\" and test(\"^${key}=\"))) = \"${env_pair}\"" "$COMPOSE_FILE"
echo "Replaced: ${env_pair}"
else
yq -yi "${service_path} += [\"${env_pair}\"]" "$COMPOSE_FILE"
echo "Added: ${env_pair}"
fi
}
set_port "127.0.0.1:44317:4317" "$OTEL_SERVICE_PATH"
set_port "127.0.0.1:44318:4318" "$OTEL_SERVICE_PATH"
set_port "127.0.0.1:8080:8080" "$SIGNOZ_SERVICE_PATH"
set_env "SIGNOZ_TOKENIZER_JWT_SECRET" "${JWT_SECRET}" ".services.signoz.environment"
set_env "SIGNOZ_SQLSTORE_PROVIDER" "${JWT_SECRET}" ".services.signoz.environment"
set_env "SIGNOZ_SQLSTORE_POSTGRES_DSN" "${POSTGRES_DSN}" ".services.signoz.environment"
bash "${SCRIPT_DIR}/domain-signoz.sh" "${DOMAIN}"