How to Properly Stop git-daemon Service on Debian Linux Systems


3 views

When working with Git on Debian servers, you might encounter git-daemon running unexpectedly. First, verify the process status:

ps aux | grep git-daemon
netstat -tulnp | grep 9418

This will show you the running process and confirm it's listening on the default Git port (9418).

Since there's no standard init script, we need alternative approaches:

Method 1: Using pkill

The quickest way to stop the daemon:

sudo pkill -f git-daemon

Verify it's stopped:

pgrep -fl git-daemon

Method 2: Systemd Service Management (modern Debian)

For newer Debian versions using systemd:

sudo systemctl stop git-daemon.socket
sudo systemctl disable git-daemon.socket

To permanently prevent git-daemon from starting:

For SysVinit Systems

Create a proper init script in /etc/init.d/:

sudo nano /etc/init.d/git-daemon

Add this content:

#!/bin/sh
### BEGIN INIT INFO
# Provides:          git-daemon
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Git daemon
# Description:       Git repository server daemon
### END INIT INFO

case "$1" in
  start)
    git daemon --reuseaddr --base-path=/var/lib/git /var/lib/git
    ;;
  stop)
    pkill -f "git daemon"
    ;;
  *)
    echo "Usage: /etc/init.d/git-daemon {start|stop}"
    exit 1
    ;;
esac

exit 0

Then make it executable:

sudo chmod +x /etc/init.d/git-daemon
sudo update-rc.d git-daemon defaults

Consider using xinetd for on-demand Git service:

sudo apt-get install xinetd
sudo nano /etc/xinetd.d/git

Add this configuration:

service git
{
        disable         = no
        socket_type     = stream
        wait            = no
        user            = nobody
        server          = /usr/bin/git
        server_args     = daemon --inetd --export-all --base-path=/var/lib/git /var/lib/git
        log_on_failure  += USERID
}

Restart xinetd:

sudo service xinetd restart
  • Check logs in /var/log/syslog or journalctl -u git-daemon
  • Verify no cron jobs are restarting the service
  • Inspect .bashrc or profile scripts that might start git-daemon

When running Git on Debian servers, you might encounter an active git-daemon process listening on port 9418 without a standard init script. This commonly occurs when Git was installed from source or through non-standard packages.

First, verify if git-daemon is actually running:

ps aux | grep git-daemon
netstat -tulnp | grep 9418

For immediate termination, use kill:

sudo kill $(pgrep git-daemon)
# Or if multiple instances exist:
sudo pkill git-daemon

On Debian systems using systemd:

sudo systemctl stop git-daemon.socket
sudo systemctl disable git-daemon.socket

For older SysV init systems:

sudo update-rc.d -f git-daemon remove

If git-daemon was started via xinetd:

sudo nano /etc/xinetd.d/git
# Set disable = yes
sudo service xinetd restart

Edit the systemd unit file if exists:

sudo nano /lib/systemd/system/git-daemon.socket
# Add:
[Install]
WantedBy=multi-user.target

After performing these steps, confirm:

sudo systemctl status git-daemon.socket
ss -tulnp | grep 9418

If you don't need git-daemon at all:

sudo apt-get purge git-daemon-run