Making git-daemon Work in Ubuntu
It is surprising, considering all the talk I've been hearing about
the wonders of git, how much one has to dig around the Internet to figure out git-daemon
(which comes with git-core) on Ubuntu (the most popular free Linux
server distribution).
What is git-daemon you may ask? It's a way to make your own remote git repository server into one that allows read-only public access to your projects. It's how you share code with users who haven't given you ssh pubkeys and don't have commit rights. I won't get into how to make your own remote git repo server because that works good and fine through many online tutorials and blog entries much better presented than this one. Public repo access is where I hit a snag, and I thought I'd share some of my discoveries here for those who are googling like mad to get package git-daemon-run to work.
First,
if you've searched around and seen people say "it's so easy, just
install git-daemon-run", and you followed their directions, then you may have already failed. Do an apt-get purge git-daemon-run. For whatever reason (arcane discussion threads can tell
you), simply trying to install apt git-daemon service on Ubuntu breaks. At least, it didn't work for me, and I stopped trying to figure out why a valid connection and url kept giving me "does not appear to be a git repository" in the logs.
You'll basically have to write your own /etc/init.d/git-daemon startup script:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:\
/usr/bin:/usr/lib/git-core
NAME=git-daemon
PIDFILE=/var/run/$NAME.pid
DESC="git daemon"
DAEMON=/usr/lib/git-core/git-daemon
DAEMON_OPTS="--base-path=/home/git/repositories --verbose \
--syslog --detach --pid-file=$PIDFILE --user=git \
--group=nogroup"
test -x $DAEMON || exit 0
[ -r /etc/default/git-daemon ] && . /etc/default/git-daemon
. /lib/lsb/init-functions
start_git() {
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--startas $DAEMON -- $DAEMON_OPTS
}
stop_git() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
rm -f $PIDFILE
}
status_git() {
start-stop-daemon --stop --test --quiet --pidfile $PIDFILE >/dev/null 2>&1
}
case "$1" in
start)
log_begin_msg "Starting $DESC"
start_git
log_end_msg 0
;;
stop)
log_begin_msg "Stopping $DESC"
stop_git
log_end_msg 0
;;
status)
log_begin_msg "Testing $DESC: "
if status_git
then
log_success_msg "Running"
exit 0
else
log_failure_msg "Not running"
exit 1
fi
;;
restart|force-reload)
log_begin_msg "Restarting $DESC"
stop_git
sleep 1
start_git
log_end_msg 0
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}" >&2
exit 1
;;
esac
exit 0
(Here's a pastie link.) Make sure nothing's bound to default port 9418 (from your previous attempts at running git-daemon-run under runsvdir) and then change the script executable and run it:
sudo chmod +x /etc/init.d/git-daemon
sudo invoke-rc.d git-daemon start
Since your Ubuntu server is locked down with ufw (you are firewalling all but essential traffic, right?), don't forget to open the port:
sudo ufw allow proto tcp from any to any port 9418
Assuming you've already pushed a project to your remote server that is running gitosis, and made it accessible with touched file git-daemon-export-ok, And then try from your local machine to do an anonymous git:
git clone git://yourserver.com/pubproj.git
And it should check out your copy of the repo.
