Skip to content

Commit 3094824

Browse files
authored
Merge pull request #843 from Buzut/master
Update to add systemd daemon exemple
2 parents 182a57e + 26c829e commit 3094824

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

book/04-git-server/sections/git-daemon.asc

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,40 @@ $ git daemon --reuseaddr --base-path=/srv/git/ /srv/git/
2020
If you're running a firewall, you'll also need to punch a hole in it at port 9418 on the box you're setting this up on.
2121

2222
You can daemonize this process a number of ways, depending on the operating system you're running.
23-
On an Ubuntu machine, you can use an Upstart script.
23+
24+
Since `systemd` is the most common init system among modern Linux distributions, you can use it for that purpose.
25+
Simply place a file in `/etc/systemd/system/git-daemon.service` with these contents:
26+
27+
[source,console]
28+
----
29+
[Unit]
30+
Description=Start Git Daemon
31+
32+
[Service]
33+
ExecStart=git daemon --reuseaddr --base-path=/srv/git/ /srv/git/
34+
35+
Restart=always
36+
RestartSec=500ms
37+
38+
StandardOutput=syslog
39+
StandardError=syslog
40+
SyslogIdentifier=git-daemon
41+
42+
User=git
43+
Group=git
44+
45+
[Install]
46+
WantedBy=multi-user.target
47+
----
48+
49+
You might have noticed that Git daemon is started here with `git` as both group and user.
50+
51+
Modify it to fit your needs and make sure provided user exists on the system.
52+
53+
Finally, you'll run `systemctl enable git-daemon` to automatically start the service on boot, and the usual service commands like `service start` and `service stop` are instantly available.
54+
55+
Until LTS 14.04, Ubuntu used upstart service unit configuration.
56+
Therefore, on Ubuntu <= 14.04 you can use an Upstart script.
2457
So, in the following file
2558

2659
[source,console]

0 commit comments

Comments
 (0)