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
2 changes: 1 addition & 1 deletion .github/workflows/comprehensive-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Comprehensive Tests

on:
push:
branches: [master, develop]
branches: [master]
pull_request:
branches: [master, develop]

Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ COPY ./requirements.txt .
# apk repository
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

# timezone
RUN apk add -U tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && apk del tzdata
# timezone and init process
RUN apk add -U tzdata tini && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
apk del tzdata

# runtime environment
RUN apk add musl-dev gcc libxml2-dev libxslt-dev && \
Expand All @@ -21,4 +23,4 @@ COPY . .

EXPOSE 5010

ENTRYPOINT [ "sh", "start.sh" ]
ENTRYPOINT ["tini", "--", "bash", "proxy_pool.sh", "start", "--fg"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ ProxyPool 爬虫代理IP池
* git clone

```bash
git clone git@github.com:jhao104/proxy_pool.git
git clone https://github.com/jhao104/proxy_pool.git
```

* releases
Expand Down Expand Up @@ -238,7 +238,7 @@ PROXY_FETCHER = [

  这里感谢以下contributor的无私奉献:

  [@kangnwh](https://github.com/kangnwh) | [@bobobo80](https://github.com/bobobo80) | [@halleywj](https://github.com/halleywj) | [@newlyedward](https://github.com/newlyedward) | [@wang-ye](https://github.com/wang-ye) | [@gladmo](https://github.com/gladmo) | [@bernieyangmh](https://github.com/bernieyangmh) | [@PythonYXY](https://github.com/PythonYXY) | [@zuijiawoniu](https://github.com/zuijiawoniu) | [@netAir](https://github.com/netAir) | [@scil](https://github.com/scil) | [@tangrela](https://github.com/tangrela) | [@highroom](https://github.com/highroom) | [@luocaodan](https://github.com/luocaodan) | [@vc5](https://github.com/vc5) | [@1again](https://github.com/1again) | [@obaiyan](https://github.com/obaiyan) | [@zsbh](https://github.com/zsbh) | [@jiannanya](https://github.com/jiannanya) | [@Jerry12228](https://github.com/Jerry12228)
  [@kangnwh](https://github.com/kangnwh) | [@bobobo80](https://github.com/bobobo80) | [@halleywj](https://github.com/halleywj) | [@newlyedward](https://github.com/newlyedward) | [@wang-ye](https://github.com/wang-ye) | [@gladmo](https://github.com/gladmo) | [@bernieyangmh](https://github.com/bernieyangmh) | [@PythonYXY](https://github.com/PythonYXY) | [@zuijiawoniu](https://github.com/zuijiawoniu) | [@netAir](https://github.com/netAir) | [@scil](https://github.com/scil) | [@tangrela](https://github.com/tangrela) | [@highroom](https://github.com/highroom) | [@luocaodan](https://github.com/luocaodan) | [@vc5](https://github.com/vc5) | [@1again](https://github.com/1again) | [@obaiyan](https://github.com/obaiyan) | [@zsbh](https://github.com/zsbh) | [@jiannanya](https://github.com/jiannanya) | [@Jerry12228](https://github.com/Jerry12228) | [@zeyudada](https://github.com/zeyudada)


### Release Notes
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Python爬虫代理IP池

.. code-block:: console

$ git clone git@github.com:jhao104/proxy_pool.git
$ git clone https://github.com/jhao104/proxy_pool.git

* 安装依赖

Expand Down
163 changes: 163 additions & 0 deletions docs/user/how_to_manage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
.. how_to_manage

服务管理
--------

``proxy_pool.sh`` 是项目的服务管理脚本, 提供统一的命令行接口来启动、停止和管理服务。

基本用法
>>>>>>>>>

.. code-block:: console

$ ./proxy_pool.sh <command> [options]

可用命令
>>>>>>>>>

start - 启动服务
^^^^^^^^^^^^^^^^

启动所有服务(调度程序和API服务)。

.. code-block:: console

# 后台启动(默认)
$ ./proxy_pool.sh start

# 前台启动(适用于容器环境)
$ ./proxy_pool.sh start --fg

后台模式下, 服务会在后台运行, 并生成 ``proxy_pool.pid`` 文件记录进程ID。

前台模式下, 服务在当前终端运行, 按 ``Ctrl+C`` 可停止服务。

stop - 停止服务
^^^^^^^^^^^^^^^^

停止所有正在运行的服务。

.. code-block:: console

$ ./proxy_pool.sh stop

脚本会读取 ``proxy_pool.pid`` 文件, 向所有子进程发送终止信号。

restart - 重启服务
^^^^^^^^^^^^^^^^^^^

重启所有服务。

.. code-block:: console

# 后台重启
$ ./proxy_pool.sh restart

# 前台重启
$ ./proxy_pool.sh restart --fg

status - 查看状态
^^^^^^^^^^^^^^^^^^

查看当前服务运行状态。

.. code-block:: console

$ ./proxy_pool.sh status

输出示例::

[INFO] Services: 2 running, 0 dead
PID 12345: running
PID 12346: running

环境变量
>>>>>>>>>

PYTHON
^^^^^^

指定Python解释器路径, 默认为 ``python``。

.. code-block:: console

$ PYTHON=python3 ./proxy_pool.sh start

PID 文件
>>>>>>>>

服务启动后会在项目根目录生成 ``proxy_pool.pid`` 文件, 记录所有子进程的PID。

该文件用于:

- ``stop`` 命令识别需要终止的进程
- ``status`` 命令检查进程状态
- 防止重复启动

``stop`` 命令执行后会自动删除该文件。

Docker 环境
>>>>>>>>>>>>

在Docker环境中, 建议使用前台模式:

.. code-block:: dockerfile

ENTRYPOINT ["tini", "--", "bash", "proxy_pool.sh", "start", "--fg"]

``docker-compose.yml`` 示例:

.. code-block:: yaml

version: '2'
services:
proxy_pool:
build: .
container_name: proxy_pool
ports:
- "5010:5010"
links:
- proxy_redis
environment:
DB_CONN: "redis://@proxy_redis:6379/0"
proxy_redis:
image: "redis"
container_name: proxy_redis

故障排除
>>>>>>>>>

服务启动失败
^^^^^^^^^^^^^

检查日志输出, 确认配置是否正确:

.. code-block:: console

# 前台启动查看详细日志
$ ./proxy_pool.sh start --fg

端口被占用
^^^^^^^^^^^

如果API端口被占用, 修改 ``setting.py`` 中的 ``PORT`` 配置:

.. code-block:: python

PORT = 5010 # 修改为其他端口

无法停止服务
^^^^^^^^^^^^^

如果 ``stop`` 命令无法停止服务, 可手动终止:

.. code-block:: console

# 查看PID文件
$ cat proxy_pool.pid

# 手动终止进程
$ kill <PID>

# 删除PID文件
$ rm proxy_pool.pid
31 changes: 28 additions & 3 deletions docs/user/how_to_run.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

.. code-block:: console

$ git clone git@github.com:jhao104/proxy_pool.git
$ git clone https://github.com/jhao104/proxy_pool.git

或者下载特定的 ``release`` 版本:

Expand Down Expand Up @@ -58,10 +58,35 @@
启动项目
>>>>>>>>>

如果已配置好运行环境, 具备运行条件, 可以通过 ``proxyPool.py`` 启动. ``proxyPool.py`` 是项目的CLI入口.
如果已配置好运行环境, 具备运行条件, 可以通过 ``proxyPool.py`` 或 ``proxy_pool.sh`` 启动.

完整程序包含两部份: ``schedule`` 调度程序和 ``server`` API服务, 调度程序负责采集和验证代理, API服务提供代理服务HTTP接口.

通过命令行程序分别启动调度程序和API服务:
方式一: 使用 ``proxy_pool.sh`` (推荐)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``proxy_pool.sh`` 提供统一的服务管理接口, 支持后台运行和进程管理:

.. code-block:: console

# 后台启动所有服务
$ ./proxy_pool.sh start

# 前台启动(容器环境)
$ ./proxy_pool.sh start --fg

# 停止服务
$ ./proxy_pool.sh stop

# 查看状态
$ ./proxy_pool.sh status

更多用法请参考 :doc:`/user/how_to_manage`

方式二: 使用 ``proxyPool.py``
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``proxyPool.py`` 是项目的Python CLI入口, 可以分别启动调度程序和API服务:

.. code-block:: console

Expand Down
1 change: 1 addition & 0 deletions docs/user/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
:maxdepth: 2

how_to_run
how_to_manage
how_to_use
how_to_config
Loading
Loading