使用 launchd 在 OS X 上启动 git-daemon
我正在尝试使用我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是 git-daemon 在从 launchd 进程继承的 PATH 中的任何目录中都找不到 git 可执行文件。当您从 shell 启动它时它会起作用,因为从 shell 继承的 PATH 包含适当的目录。
通常,Git 命令是通过主 git 命令调用的(例如
git commit
,而不是(不再)git-commit
)。除此之外,主要的 git 命令将内置的“exec 路径”添加到“子命令”将继承的 PATH 环境变量中。您的 launchd 配置直接调用“内部”程序 - git-daemon - 而不是让普通的顶级程序调用它(在扩展 PATH 后,它将继承)。
使用以下 ProgramArguments :
其中
/path/to/git
是which 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:
where
/path/to/git
is whateverwhich git
reports in your normal shell session.你没有告诉它运行。尝试取出
OnDemand
并添加以下内容:或者,您可以使用
inetdCompatibility
(另请参阅:Sockets
)和git-daemon< /code> 的
--inetd
标志使进程仅在连接时启动。这对您来说可能是一个更好的配置,尽管可能需要做更多的工作。launchd.plist(5 ) 手册页包含所有详细信息。
You're not telling it to run. Try taking out the
OnDemand
and adding this:Alternatively, you can use
inetdCompatibility
(see also:Sockets
) andgit-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.