-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_update.sh
More file actions
executable file
·36 lines (29 loc) · 1.01 KB
/
proxy_update.sh
File metadata and controls
executable file
·36 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
set -euo pipefail
APP_DIR="/opt/sifteroxy" # Directory where sifteroxy.py is located
PYTHON="/usr/bin/python3" # Use venv/bin/python if using virtual environment
OUT_TXT="$APP_DIR/proxies_alive.txt"
METRICS_DIR="$APP_DIR/metrics"
LOG_DIR="$APP_DIR/logs"
LOCK_FILE="$APP_DIR/.proxy_update.lock"
mkdir -p "$METRICS_DIR" "$LOG_DIR"
# Prevent concurrent runs (second run exits silently)
exec 9>"$LOCK_FILE"
flock -n 9 || exit 0
TS="$(date +'%Y%m%d-%H%M%S')"
METRICS_JSON="$METRICS_DIR/metrics-$TS.json"
LOG_FILE="$LOG_DIR/run-$TS.log"
cd "$APP_DIR"
"$PYTHON" sifteroxy.py \
--timeout 5 \
--concurrency 128 \
--test-url "https://httpbin.org/ip" \
--out "$OUT_TXT" \
--metrics "$METRICS_JSON" \
--log-level INFO \
> "$LOG_FILE" 2>&1
# Create symlink to latest metrics
ln -sfn "$METRICS_JSON" "$METRICS_DIR/latest.json"
# Clean up old logs and metrics (older than 7 days)
find "$LOG_DIR" -type f -mtime +7 -delete || true
find "$METRICS_DIR" -type f -name 'metrics-*.json' -mtime +7 -delete || true