Git 从 cron 启动时返回错误

Git 从 cron 启动时返回错误

我的 ubuntucron运行一个 PHP 脚本来www-data通过执行来收集统计数据git diff --shortstat,它已经运行了一个月左右,但是,从 2 天前开始,没有返回任何结果。

经过一番调查,我设法在 CLI 中复制了该问题。如果我运行git diff --shortstat,输出是正确的,但是,运行时sudo -u www-data git diff --shortstat会出现错误:

warning: Not a git repository. Use --no-index to compare two paths outside a working tree
...

strace对这两个命令都进行了测试,发现以下不同。无论出于什么原因,失败的命令决定不读取.git/commondir

## Not working, geteuid() = 33 due to running `www-data`

newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/commondir", 0x7fffe58445a0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/objects", X_OK) = 0
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/refs", X_OK) = 0
newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake", {st_mode=S_IFDIR|0770, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
geteuid()                               = 33
access("/etc/gitconfig", R_OK)          = -1 ENOENT (No such file or directory)
access("/var/www/.config/git/config", R_OK) = -1 ENOENT (No such file or directory)
access("/var/www/.gitconfig", R_OK)     = -1 ENOENT (No such file or directory)
access("/etc/gitconfig", R_OK)          = -1 ENOENT (No such file or directory)
access("/var/www/.config/git/config", R_OK) = -1 ENOENT (No such file or directory)
access("/var/www/.gitconfig", R_OK)     = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
newfstatat(3, "", {st_mode=S_IFREG|0644, st_size=2996, ...}, AT_EMPTY_PATH) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2996
read(3, "", 4096)                       = 0
close(3)                                = 0


## Working, geteuid() = 0 due to running as `root`

newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/commondir", 0x7ffde3edb890, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/objects", X_OK) = 0
access("/media/sf_www/stage/package-repo/packages/bilogic/pmake/.git/refs", X_OK) = 0
newfstatat(AT_FDCWD, "/media/sf_www/stage/package-repo/packages/bilogic/pmake", {st_mode=S_IFDIR|0770, st_size=4096, ...}, AT_SYMLINK_NOFOLLOW) = 0
geteuid()                               = 0
newfstatat(AT_FDCWD, ".git/commondir", 0x7ffde3edb9a0, AT_SYMLINK_NOFOLLOW) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, ".git/config", O_RDONLY) = 3
newfstatat(3, "", {st_mode=S_IFREG|0770, st_size=285, ...}, AT_EMPTY_PATH) = 0
newfstatat(3, "", {st_mode=S_IFREG|0770, st_size=285, ...}, AT_EMPTY_PATH) = 0
read(3, "[core]\n\trepositoryformatversion "..., 8192) = 285
read(3, "", 8192)                       = 0
close(3)                                = 0

进一步了解一下,这些 git 存储库位于 VirtualBox 共享文件夹中。它的所有者和组是root:vboxsf,并且www-data是该组的成员vboxsf。我不记得触碰过系统上的任何权限,因此令人费解的是它过去为何能正常工作。

我也进行了一些谷歌搜索,建议修改sudoers.d,但没有帮助,它仍然是Not a git repository。 知道是什么原因导致此问题吗?

相关内容