66 lines
1.7 KiB
Bash
Executable File
66 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Persistent launcher for proxy_pool.py — restarts it if it dies.
|
|
# Usage:
|
|
# ./proxy_pool_daemon.sh start # start in background (nohup, survives logout)
|
|
# ./proxy_pool_daemon.sh stop # stop the daemon
|
|
# ./proxy_pool_daemon.sh restart # restart
|
|
# ./proxy_pool_daemon.sh status # show status + best proxies
|
|
# ./proxy_pool_daemon.sh logs # tail the log
|
|
set -u
|
|
cd "$(dirname "$0")"
|
|
PIDFILE="results/proxies/pool.pid"
|
|
LOG="results/proxies/proxy_pool.log"
|
|
mkdir -p results/proxies
|
|
|
|
is_running() {
|
|
[ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE")" 2>/dev/null
|
|
}
|
|
|
|
start() {
|
|
if is_running; then
|
|
echo "already running (pid $(cat "$PIDFILE"))"; return 0
|
|
fi
|
|
echo "starting proxy pool daemon..."
|
|
# outer loop: respawn python if it exits
|
|
nohup bash -c '
|
|
while true; do
|
|
python3 proxy_pool.py --workers 400
|
|
echo "[daemon] proxy_pool exited, restarting in 10s..." >> "'"$LOG"'"
|
|
sleep 10
|
|
done
|
|
' >>"$LOG" 2>&1 &
|
|
echo $! > "$PIDFILE"
|
|
sleep 1
|
|
if is_running; then echo "started (pid $(cat "$PIDFILE")) -> $LOG"
|
|
else echo "failed to start"; fi
|
|
}
|
|
|
|
stop() {
|
|
if is_running; then
|
|
pid=$(cat "$PIDFILE")
|
|
echo "stopping pid $pid..."
|
|
kill "$pid" 2>/dev/null
|
|
sleep 1
|
|
kill -9 "$pid" 2>/dev/null
|
|
rm -f "$PIDFILE"
|
|
echo "stopped"
|
|
else
|
|
echo "not running"
|
|
rm -f "$PIDFILE"
|
|
fi
|
|
}
|
|
|
|
status() {
|
|
if is_running; then echo "daemon running (pid $(cat "$PIDFILE"))"; else echo "daemon NOT running"; fi
|
|
python3 proxy_pool.py --status
|
|
}
|
|
|
|
case "${1:-status}" in
|
|
start) start ;;
|
|
stop) stop ;;
|
|
restart) stop; start ;;
|
|
status) status ;;
|
|
logs) tail -n 40 -f "$LOG" ;;
|
|
*) echo "usage: $0 {start|stop|restart|status|logs}"; exit 1 ;;
|
|
esac
|