Git daemon logging, how to enable it and store the logs into a file, e.g. like /var/log/git.log?

961 Views Asked by At

if you think that this is not the proper section of SE where to post a question like this, tell me where should I put it and I will move it.

Anyway. I have a git daemon set up on my OS X machine which runs under launchd, here is the .plist file inside /Library/LaunchDaemons/:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.git.daemon</string>
        <key>UserName</key>
        <string>git-ro</string>
        <key>GroupName</key>
        <string>git-ro</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/local/bin/git</string>
        <string>daemon</string>             
                <string>--inetd</string>
                <string>--reuseaddr</string>
                <string>--verbose</string>
                <string>--base-path=/Users/git/GitRepositories/</string>
                <string>/Users/git/GitRepositories/</string>
    </array>
        <key>Sockets</key>
        <dict>
            <key>Listeners</key>
            <dict>
        <key>SockServiceName</key>
        <string>git</string>
        <key>SockType</key>
        <string>stream</string>
        <key>SockFamily</key>
        <string>IPv4</string>
            </dict>
        </dict>
        <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <false/>
    </dict>
</dict>
</plist>

Everything works like a charm, but the daemon logs its information into /var/log/system.log. Is there a way to tell it to log its information (stdout, stderr) into a dedicated file, e.g. like /var/log/git.log?

Edit: I have also tried to add the StandardOutPath and StandardErrPath keys to the .plist, but doing so makes launchd unable to start the git daemon for some reasons of which I am not aware of (I see a Service could not initialize: for git daemon in /var/log/system.log):

...
<key>StandardOutPath</key>
<string>/var/log/git.log</string>
<key>StandardErrorPath</key>
<string>/var/log/git.log</string>
...

Edit: I edited the .plist file and the daemon works with this configuration (StandardOutPath, StandardErrorPath seem to give problems, too). Here is the working one:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.git.daemon</string>
        <key>UserName</key>     
        <string>git-ro</string>
        <key>GroupName</key>
        <string>staff</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/local/bin/git</string>
        <string>daemon</string>
                <string>--inetd</string>
                <string>--reuseaddr</string>
                <string>--verbose</string>
                <string>--base-path=/Users/git/GitRepositories/</string>
                <string>/Users/git/GitRepositories/</string>
    </array>
        <key>Sockets</key>
        <dict>
            <key>Listeners</key>
            <dict>
        <key>SockServiceName</key>
        <string>git</string>
        <key>SockType</key>
        <string>stream</string>
        <key>SockFamily</key>
        <string>IPv4</string>
            </dict>
        </dict>
        <key>inetdCompatibility</key>
    <dict>
        <key>Wait</key>
        <false/>
    </dict>
</dict>
</plist>

Now, how can I redirect the daemon's logs into a file like e.g. /var/log/git.log?

1

There are 1 best solutions below

1
On

@VonC pointed out an interesting parameter starting from Git 2.17 (look at its comment).

Anyway, I ended up creating a simple script called /usr/local/bin/git-daemon-launchd and referenced it within my daemon's configuration:

#!/bin/bash

# Git daemon launchd startup command.
GIT_COMMAND="/usr/local/bin/git" # The path to the git command
GIT_RO_USER="git-ro" # The user which has read only access to the repositories.
GIT_REP_BASE_PATH="/Users/git/GitRepositories" # The repositories base path.
GIT_LOG_FILE="/var/log/git.log" # The git daemon log file.

$GIT_COMMAND daemon --reuseaddr --verbose --user=$GIT_RO_USER --base-path=$GIT_REP_BASE_PATH $GIT_REP_BASE_PATH >> $GIT_LOG_FILE 2>&1
# Or if you like to keep the error log separate, uncomment the following lines and comment the previous one (although Git logs to stderr,
# so all the logs will be at $GIT_ERR_LOG_FILE):
#GIT_ERR_LOG_FILE="/var/log/git_err.log" # The error log file
#$GIT_COMMAND daemon --reuseaddr --verbose --user=$GIT_RO_USER --base-path=$GIT_REP_BASE_PATH $GIT_REP_BASE_PATH >> $GIT_LOG_FILE 2>> $GIT_ERR_LOG_FILE

/Library/LaunchDaemons/org.git.daemon.plist configuration:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.git.daemon</string>
        <key>RunAtLoad</key>
        <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/git-daemon-launchd</string>
    </array>
</dict>
</plist>