简体   繁体   English

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

[英]Starting git-daemon on OS X using launchd

I am trying to set up an internal git server using my OS X desktop (mostly as a test case). 我正在尝试使用我的OS X桌面设置内部git服务器(主要作为测试用例)。 Everything works when SSH keys are involved, but I am currently trying to use git-daemon for read-only cloning. 当涉及SSH密钥时,一切正常,但我目前正在尝试使用git-daemon进行只读克隆。 If I start up git-daemon in a terminal: 如果我在终端中启动git-daemon:

sudo -u git git-daemon --basepath=/Users/git/repos/ --export-all

then everything works fine, eg 然后一切正常,例如

git clone git://localhost/My_Project.git

But when I try to set this up using launchd, it refuses all requests. 但是当我尝试使用launchd进行设置时,它会拒绝所有请求。 I am using this plist file: 我正在使用这个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>

And receive the following error if I attempt to clone My_Project: 如果我尝试克隆My_Project,则会收到以下错误:

Cloning into My_Project...
fatal: The remote end hung up unexpectedly

The frustrating thing is that I believe this used to work, so the problem may have less to do with my plist file or use of launchd, and more to do any network settings that may have changed. 令人沮丧的是,我相信这曾经有用,所以问题可能与我的plist文件或者launchd的使用关系不大,而且更多的是做任何可能已经改变的网络设置。 Any advice would be greatly appreciated. 任何建议将不胜感激。

Apologies if this is more of a sysadmin question, but I figured that developers might have some experience here. 抱歉,如果这更像是一个系统管理员问题,但我认为开发人员可能会有一些经验。

Update: The Console reports the following error if the repo exists: 更新:如果存在repo,控制台将报告以下错误:

git[431]
error: cannot run upload-pack: No such file or directory

The problem is that git-daemon can not find the git executable in any of the directories in the PATH that it inherited from launchd process. 问题是git-daemon无法在从launchd进程继承的PATH中的任何目录中找到git可执行文件。 It works when you launch it from your shell because the PATH inherited from the shell includes the appropriate directory. 它从shell启动时有效,因为从shell继承的PATH包含相应的目录。

Usually, Git commands are invoked through the main git command (eg git commit , not (anymore) git-commit ). 通常,Git命令是通过main git命令调用的(例如git commit ,而不是(不再) git-commit )。 Among other things, the main git command adds the built-in “exec path” to the PATH environment variable that the “sub-commands” will inherit. 除此之外,main git命令将内置的“exec path”添加到“子命令”将继承的PATH环境变量中。

Your launchd configuration directly invokes an “internal” program — git-daemon — instead of letting the normal top-level program call it (after extending the PATH it will inherit). 你的launchd配置直接调用一个“内部”程序 - git-daemon - 而不是让普通的顶级程序调用它(在扩展它将继承的PATH之后)。

Use the following ProgramArguments : 使用以下ProgramArguments

        <array>
                <string>/path/to/git</string>
                <string>daemon</string>
                <string>--base-path=/Users/git/repos/</string>
                <string>--export-all</string>
        </array>

where /path/to/git is whatever which git reports in your normal shell session. 其中/path/to/git是正常shell会话中which git报告的内容。

You're not telling it to run. 你没告诉它要跑。 Try taking out the OnDemand and adding this: 尝试取出OnDemand并添加:

<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>

Alternatively, you can use inetdCompatibility (see also: Sockets ) and git-daemon 's --inetd flag to make the process only start on connection. 或者,您可以使用inetdCompatibility (另请参阅: Sockets )和git-daemon--inetd标志,以使进程仅在连接时启动。 That would likely be a better configuration for you, though perhaps a bit more work to get going. 这对你来说可能是一个更好的配置,尽管可能需要更多的工作才能开始。

The launchd.plist(5) man page has all the details. launchd.plist(5)手册页包含所有详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM