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

发布于 2024-10-24 06:23:50 字数 1513 浏览 4 评论 0原文

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

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

那么一切都会正常,例如

git clone git://localhost/My_Project.git

但是当我尝试使用 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>

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

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

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

如果这更多是一个系统管理员问题,我很抱歉,但我认为开发人员可能在这里有一些经验。

更新:如果存储库存在,控制台会报告以下错误:

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

I am trying to set up an internal git server using my OS X desktop (mostly as a test case). Everything works when SSH keys are involved, but I am currently trying to use git-daemon for read-only cloning. If I start up git-daemon in a terminal:

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

then everything works fine, e.g.

git clone git://localhost/My_Project.git

But when I try to set this up using launchd, it refuses all requests. I am using this plist file:

<?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:

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. 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:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

遥远的绿洲 2024-10-31 06:23:50

问题是 git-daemon 在从 launchd 进程继承的 PATH 中的任何目录中都找不到 git 可执行文件。当您从 shell 启动它时它会起作用,因为从 shell 继承的 PATH 包含适当的目录。

通常,Git 命令是通过主 git 命令调用的(例如 git commit,而不是(不再)git-commit)。除此之外,主要的 git 命令将内置的“exec 路径”添加到“子命令”将继承的 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>

其中 /path/to/gitwhich git 在正常 shell 会话中报告的任何内容。

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. It works when you launch it from your shell because the PATH inherited from the shell includes the appropriate directory.

Usually, Git commands are invoked through the main git command (e.g. git commit, not (anymore) 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.

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).

Use the following 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.

睡美人的小仙女 2024-10-31 06:23:50

你没有告诉它运行。尝试取出 OnDemand 并添加以下内容:

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

或者,您可以使用 inetdCompatibility (另请参阅:Sockets)和 git-daemon< /code> 的 --inetd 标志使进程仅在连接时启动。这对您来说可能是一个更好的配置,尽管可能需要做更多的工作。

launchd.plist(5 ) 手册页包含所有详细信息。

You're not telling it to run. Try taking out the OnDemand and adding this:

<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. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文