fix: preserve verified analytics coverage across releases

This commit is contained in:
hectorzhao
2026-09-01 10:43:14 +08:00
parent 6f1cf41043
commit 9fa1964dec
+8 -2
View File
@@ -107,11 +107,17 @@ install -m 0644 "$new/infra/server-b/s58/systemd/lisglosips.target" /etc/systemd
systemctl daemon-reload
systemctl enable --now lisglosips-caller-analytics-redis.service
encoded_redis_password=$(/usr/bin/node -e 'console.log(encodeURIComponent(process.argv[1]))' "$analytics_redis_password")
if grep -q 'CRA_INSTRUMENTATION_VERSION=3' "$source_cfg" && grep -q '^ANALYTICS_CAPTURE_SINCE=' /etc/lisglosips/caller-analytics.env; then
analytics_capture_since=$(sed -n 's/^ANALYTICS_CAPTURE_SINCE=//p' /etc/lisglosips/caller-analytics.env | head -n 1)
else
analytics_capture_since=$(date -u +%Y-%m-%dT%H:%M:%SZ)
fi
[[ "$analytics_capture_since" =~ ^20[0-9]{2}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$ ]]
grep '^DATABASE_URL=' /etc/lisglosips/cdr-worker.env > /etc/lisglosips/caller-analytics.env.new
printf '%s\n' "REDIS_URL=redis://:$encoded_redis_password@127.0.0.1:6381/0" 'LISGLOSIPS_ENTRYPOINT=apps/worker-cdr/dist/analytics-main.js' 'LISGLOSIPS_SERVICE_NAME=caller-analytics' 'ANALYTICS_STREAM_MAXLEN=1000000' "ANALYTICS_CAPTURE_SINCE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> /etc/lisglosips/caller-analytics.env.new
printf '%s\n' "REDIS_URL=redis://:$encoded_redis_password@127.0.0.1:6381/0" 'LISGLOSIPS_ENTRYPOINT=apps/worker-cdr/dist/analytics-main.js' 'LISGLOSIPS_SERVICE_NAME=caller-analytics' 'ANALYTICS_STREAM_MAXLEN=1000000' "ANALYTICS_CAPTURE_SINCE=$analytics_capture_since" >> /etc/lisglosips/caller-analytics.env.new
install -o root -g lisglosips -m 0640 /etc/lisglosips/caller-analytics.env.new /etc/lisglosips/caller-analytics.env
rm -f /etc/lisglosips/caller-analytics.env.new
unset analytics_redis_password encoded_redis_password
unset analytics_redis_password encoded_redis_password analytics_capture_since
chown -R root:lisglosips "$new/apps/api/dist" "$new/apps/worker-cdr/dist" "$new/packages/database/dist" "$new/packages/auth/dist" "$new/public" "$new/scripts" "$new/infra/server-b/caller-analytics"
chmod -R u=rwX,g=rX,o= "$new/apps/api/dist" "$new/apps/worker-cdr/dist" "$new/packages/database/dist" "$new/packages/auth/dist" "$new/public" "$new/scripts" "$new/infra/server-b/caller-analytics"
systemctl restart rsyslog