2

如果您认为这不是 SE 的适当部分,可以在哪里发布这样的问题,请告诉我应该将其放在哪里,我会移动它。

反正。我git daemon在我的 OS X 机器上设置了一个在 launchd 下运行的设备,这是里面的 .plist 文件/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>

一切都像一个魅力,但守护进程将其信息记录到/var/log/system.log. 有没有办法告诉它将其信息(stdout、stderr)记录到专用文件中,例如/var/log/git.log

编辑:我也尝试将StandardOutPathandStandardErrPath键添加到 .plist,但是这样做会使 launchd 无法启动 git 守护进程,原因我不知道(我在 中看到了Service could not initialize:for git 守护进程/var/log/system.log):

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

编辑:我编辑了 .plist 文件,守护程序使用此配置(StandardOutPath、StandardErrorPath 似乎也有问题)。这是工作的:

<?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>

现在,我怎样才能将守护进程的日志重定向到一个像 eg 的文件中/var/log/git.log

4

1 回答 1

1

@VonC 指出了从 Git 2.17 开始的一个有趣参数(查看它的评论)。

无论如何,我最终创建了一个简单的脚本/usr/local/bin/git-daemon-launchd,在我的守护进程配置中调用并引用了它:

#!/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配置:

<?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>
于 2018-02-25T20:16:31.337 回答