NGINX Unit

Mercurial§

使用 Unit 安装并运行 Mercurial 源代码控制系统

  1. 使用 Python 语言模块安装 Unit

  2. 安装 Mercurial 的 核心文件。此处,我们将其安装在 /path/to/app/;在配置中使用真实路径。

  3. (可选)配置 存储库或选择一个现有的存储库,并记下其目录路径。

  4. Unit 使用 WSGI 运行 Python 应用,因此它需要一个 包装器 脚本来发布 Mercurial 存储库。此处,它是 /path/to/app/hgweb.py(注意扩展名);application 可调用项是入口点

    from mercurial.hgweb import hgweb
    
    # path to a repo or a hgweb config file to serve in UTF-8 (see 'hg help hgweb')
    application = hgweb("/path/to/app/repo/or/config/file".encode("utf-8"))
    

    这是一个非常基本的脚本;要对其进行详细说明,请参阅 Mercurial 存储库发布 指南

  5. 运行以下命令,以便 Unit 可以访问 应用程序目录

    # chown -R unit:unit /path/to/app/
    

    注意

    unit:unit 用户组对仅适用于 官方软件包、Docker 镜像 和一些 第三方存储库。否则,帐户名称可能不同;运行 ps aux | grep unitd 命令以确保。

    有关更多详细信息,包括权限,请参阅 安全检查清单

  6. 接下来,为 Unit 准备 Mercurial 配置(对 path 使用真实值)

    {
        "listeners": {
            "*:80": {
                "pass": "applications/hg"
            }
        },
    
        "applications": {
            "hg": {
                "type": "python",
                "path": "/path/to/app/",
                "module": "hgweb"
            }
        }
    }
    
  7. 上传更新的配置。假设上面的 JSON 已添加到 config.json

    # curl -X PUT --data-binary @config.json --unix-socket \
           /path/to/control.unit.sock http://localhost/config/
    

    注意

    控制套接字 路径可能有所不同;运行 unitd -h 或参阅 启动和关闭 了解详情。

    成功更新后,您可以继续照常使用 Mercurial 存储库

    $ hg config --edit
    $ hg clone http://localhost/ project/
    $ cd project/
    $ touch hg_rocks.txt
    $ hg add
    $ hg commit -m 'Official: Mercurial on Unit rocks!'
    $ hg push
    
    Mercurial on Unit - Changeset Screen