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
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.
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.
精彩评论