Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions aio/s6-rc.d/postgres/finish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/command/with-contenv bash
set -eu

STATE_DIR="/run/postgres"
STATE_DIR="/run/service/postgres"
COUNT_FILE="$STATE_DIR/restart-count"
MAX_RESTARTS="${MAX_RESTARTS:-3}"

Expand All @@ -12,12 +12,15 @@ count=$(cat "$COUNT_FILE" 2>/dev/null || echo 0)
count=$((count+1))
echo -n "$count" > "$COUNT_FILE"

# Record last restart timestamp
date +%s > "$STATE_DIR/last-restart"

echo "[postgres] crash count: $count/${MAX_RESTARTS}"

if [ "$count" -ge "$MAX_RESTARTS" ]; then
echo "[postgres] too many failures, terminating supervision tree"
# Ask s6-svscan to exit; this will stop the container
exec /command/s6-svscanctl -t /run/service
exec /command/s6-svscanctl -t /run/service
fi

exit 0
7 changes: 5 additions & 2 deletions aio/s6-rc.d/price-aggregator/finish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/command/with-contenv bash
set -eu

STATE_DIR="/run/price-aggregator"
STATE_DIR="/run/service/price-aggregator"
COUNT_FILE="$STATE_DIR/restart-count"
MAX_RESTARTS="${MAX_RESTARTS:-3}"

Expand All @@ -14,12 +14,15 @@ count=$(cat "$COUNT_FILE" 2>/dev/null || echo 0)
count=$((count+1))
echo "$count" > "$COUNT_FILE"

# Record last restart timestamp
date +%s > "$STATE_DIR/last-restart"

echo "[price-aggregator] crash count: $count/${MAX_RESTARTS}"

if [ "$count" -ge "$MAX_RESTARTS" ]; then
echo "[price-aggregator] too many failures, terminating supervision tree"
# Ask s6-svscan to exit; this will stop the container
exec /command/s6-svscanctl -t /run/service
exec /command/s6-svscanctl -t /run/service
fi

exit 0
2 changes: 2 additions & 0 deletions aio/s6-rc.d/price-aggregator/run
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ fi
mkdir -p /var/log/price-aggregator
exec > >(s6-log n10 s10485760 /var/log/price-aggregator) 2>&1

export PROCESS_METRICS_TTL_SECONDS=259200

exec node dist/main
Empty file.
22 changes: 22 additions & 0 deletions aio/s6-rc.d/process-metrics/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/command/with-contenv bash
set -eu

STATE_DIR="/run/process-metrics"
COUNT_FILE="$STATE_DIR/restart-count"
MAX_RESTARTS="${MAX_RESTARTS:-3}"

mkdir -p "$STATE_DIR"

count=$(cat "$COUNT_FILE" 2>/dev/null || echo 0)
count=$((count+1))
echo "$count" > "$COUNT_FILE"
date +%s > "$STATE_DIR/last-restart"

echo "[process-metrics] crash count: $count/${MAX_RESTARTS}"

if [ "$count" -ge "$MAX_RESTARTS" ]; then
echo "[process-metrics] too many failures, terminating supervision tree"
exec /command/s6-svscanctl -t /run/service
fi

exit 0
33 changes: 33 additions & 0 deletions aio/s6-rc.d/process-metrics/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/command/with-contenv bash
set -euo pipefail

echo "[process-metrics] Starting exporter..."

GLOBAL_CONFIG_JSON_PATH="/sp/configurations/configuration.json"

mkdir -p /etc/process-metrics
CONFIG_FILE_PATH=/etc/process-metrics/config.json
if [ -f "$GLOBAL_CONFIG_JSON_PATH" ]; then
if ! jq -r '.solution.priceAggregatorConfig.metricsPush' "$GLOBAL_CONFIG_JSON_PATH" > "$CONFIG_FILE_PATH" 2>/dev/null; then
echo "[process-metrics] WARN: failed to extract priceAggregatorConfig.metricsPush from $GLOBAL_CONFIG_JSON_PATH" >&2
fi
else
echo "[process-metrics] WARN: global config not found at $GLOBAL_CONFIG_JSON_PATH; using existing $CONFIG_FILE_PATH if present" >&2
fi

# Force jobName and groupingLabels.service to "process-metrics"
if [ -f "$CONFIG_FILE_PATH" ]; then
TMP_FILE="$(mktemp)"
if ! jq '.jobName = "process-metrics" | .groupingLabels.service = "process-metrics"' "$CONFIG_FILE_PATH" > "$TMP_FILE" 2>/dev/null; then
echo "[process-metrics] WARN: failed to rewrite jobName/groupingLabels.service in $CONFIG_FILE_PATH" >&2
rm -f "$TMP_FILE"
else
mv "$TMP_FILE" "$CONFIG_FILE_PATH"
fi
fi

# Route stdout/stderr through s6-log with rotation
mkdir -p /var/log/process-metrics
exec > >(s6-log n10 s10485760 /var/log/process-metrics) 2>&1

exec node /scripts/process-metrics-exporter/index.js
1 change: 1 addition & 0 deletions aio/s6-rc.d/process-metrics/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
3 changes: 2 additions & 1 deletion scripts/bash/entrypoint-allinone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,15 @@ set -eu
# Fixed service name using node index from generator time
SERVICE_NAME="chainlink-node-${i}"

STATE_DIR="/run/\${SERVICE_NAME}"
STATE_DIR="/run/service/\${SERVICE_NAME}"
COUNT_FILE="\${STATE_DIR}/restart-count"
MAX_RESTARTS="\${MAX_RESTARTS:-3}"

mkdir -p "\$STATE_DIR"
count=\$(cat "\$COUNT_FILE" 2>/dev/null || echo 0)
count=\$((count+1))
echo "\$count" > "\$COUNT_FILE"
date +%s > "\$STATE_DIR/last-restart"

echo "[\${SERVICE_NAME}] crash count: \$count/\${MAX_RESTARTS}"

Expand Down
Loading
Loading