Skip to content

Instantly share code, notes, and snippets.

@rjaan
Forked from jeremiah/git-daemon
Last active December 30, 2022 13:22
Show Gist options
  • Save rjaan/702b7b79faf34ba3ff2194d0f404760b to your computer and use it in GitHub Desktop.
Save rjaan/702b7b79faf34ba3ff2194d0f404760b to your computer and use it in GitHub Desktop.
systemd-unit for git-daemon

systemd-unit to run git-daemon on Debain-11

git-daemon is an reciept of unit configuration to run git-daemon(1) on Debain-11

I forked this reciept of the unit configuration from @jeremiah and I adopted to run it in debian-11 systems.

In our Debian-11 systems, you must to do next steps to install git-daemon:

1st step. Create the user named 'git' along with its home directory /home/git and its shell /usr/bin/git-shell. Also, I recommend to create the subdirectory /home/git/repos/git-shell-commands in Git's home directory. You must to assign some permissions as below

sudo useradd -m -d /home/git -s /usr/bin/git-shell git &&
sudo -u git mkdir -m 755 -p /home/git/repos/git-shell-commands

2nd step. Verify git-daemon@.service to your local configuration. particularly this line; "ExecStart=-/usr/lib/git-core/git-daemon --inetd --base-path=/home/git/repos --verbose $GITDAEMON_OPTS"

3rd step. Move the git-daemon@.service template and git-daemon.socket files into /usr/lib/systemd/system/.

sudo systemctl enable /lib/systemd/system/git-daemon.socket sudo systemctl start git-daemon.socket

Notice: the conf.d file must be located must be located in there what path was indicated in the variable EnvironmentFile of the file git-daemon@.service. In debian, config files of system unit should placed in directory '/usr/lib/systemd/.d' where 'unit-service' means its name as like for git-daemon .

About git-daemon is a really simple server for Git repositories. This server listens on port "DEFAULT_GIT_PORT" aka 9418. It waits for a connection asking for a service, and will serve that service if it is enabled.

# conf.d file for git-daemon
#
# Please check man 1 git-daemon for more information about the options
# git-daemon accepts. You MUST edit this to include your repositories you wish
# to serve.
#
# Some of the meaningful options are:
# --syslog --- Enables syslog logging
# --verbose --- Enables verbose logging
# --export-all --- Exports all repositories
# --port=XXXX --- Starts in port XXXX instead of 9418
#
#GITDAEMON_OPTS="--syslog --base-path=/home/git/repos --export-all"
GITDAEMON_OPTS="--syslog --base-path=/home/git/repos --export-all --enable=receive-pack --reuseaddr --informative-errors"
# To run an anonymous git safely, the following user should be able to only
# read your Git repositories. It should not be able to write to anywhere on
# your system, esp. not the repositories.
GIT_USER="git"
GIT_GROUP="git"
[Unit]
Description=Git Activation Socket
[Socket]
ListenStream=9418
Accept=true
[Install]
WantedBy=sockets.target
[Unit]
Description=Git Repositories Server Daemon
Documentation=man:git-daemon(1)
[Service]
User=git
Group=git
EnvironmentFile=/usr/lib/systemd/git-daemon.conf/git-daemon
# Ignore non-zero exit status, access error makes git-daemon return them
ExecStart=-/usr/lib/git-core/git-daemon --inetd --base-path=/home/git/repos --verbose $GITDAEMON_OPTS
StandardInput=socket
StandardOutput=inherit
StandardError=journal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment