使用launchd在OS X上启动git-daemon

mar*_*ard 4 git macos launchd git-daemon

我正在尝试使用我的OS X桌面设置内部git服务器(主要作为测试用例).当涉及SSH密钥时,一切正常,但我目前正在尝试使用git-daemon进行只读克隆.如果我在终端中启动git-daemon:

sudo -u git git-daemon --basepath=/Users/git/repos/ --export-all
Run Code Online (Sandbox Code Playgroud)

然后一切正常,例如

git clone git://localhost/My_Project.git
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用launchd进行设置时,它会拒绝所有请求.我正在使用这个plist文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>git</string>
        <key>UserName</key>
        <string>git</string>
        <key>OnDemand</key>
        <false/>
        <key>ProgramArguments</key>
        <array>
                <string>/path/to/git-daemon</string>
                <string>--base-path=/Users/git/repos/</string>
                <string>--export-all</string>
        </array>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)

如果我尝试克隆My_Project,则会收到以下错误:

Cloning into My_Project...
fatal: The remote end hung up unexpectedly
Run Code Online (Sandbox Code Playgroud)

令人沮丧的是,我相信这曾经有用,所以问题可能与我的plist文件或者launchd的使用关系不大,而且更多的是做任何可能已经改变的网络设置.任何建议将不胜感激.

抱歉,如果这更像是一个系统管理员问题,但我认为开发人员可能会有一些经验.

更新:如果存在repo,控制台将报告以下错误:

git[431]
error: cannot run upload-pack: No such file or directory
Run Code Online (Sandbox Code Playgroud)

Chr*_*sen 6

问题是git-daemon无法在从launchd进程继承的PATH中的任何目录中找到git可执行文件.它从shell启动时有效,因为从shell继承的PATH包含相应的目录.

通常,通过main git命令调用Git命令(例如git commit,不再(不再)git-commit).除此之外,main git命令将内置的"exec path"添加到"子命令"将继承的PATH环境变量中.

你的launchd配置直接调用一个"内部"程序 - git-daemon - 而不是让普通的顶级程序调用它(在扩展它将继承的PATH之后).

使用以下ProgramArguments:

        <array>
                <string>/path/to/git</string>
                <string>daemon</string>
                <string>--base-path=/Users/git/repos/</string>
                <string>--export-all</string>
        </array>
Run Code Online (Sandbox Code Playgroud)

哪里/path/to/git是什么which git在你的正常shell会话报告.