Monit 检查 git 回购中的更改状态

Monit check status of changes in git repo

我正在使用 Monit 来监视 ubuntu 服务器,并想 运行 测试 git 存储库中的更改。

我读过 (here) "git ls-files" 将是执行此操作的最佳方法,但我不确定如何 运行 执行命令作为 monit 中的测试.他们的文档显示了测试通过后 运行ning exec 命令的示例,但没有显示如何在 exec 上进行测试。

最好的方法是什么?

==========

PS - 我在下面找到了基于@TheCodeKiller 答案的解决方案。这是现在运行良好的最终代码。答案实际上在文档中,但我不认为这是我的解决方案。是here.

内部监控配置(/etc/monit/monitrc):

check program changed_files with path "/path/to/git/directory/monit_alert_changed_files.sh"
    if status != 0 for 3 cycles then alert

然后在该文件中:

#!/bin/bash

# Script to check if there are changes in the current git directory

if [[ `git --git-dir "/path/to/git/directory/.git" --work-tree "/path/to/git/directory/" ls-files -m -o --exclude-standard` ]]; then
  # Changes
  exit 1
else
  # No changes
  exit 0
fi

您可以 运行 使用 检查程序 编写程序或自定义脚本:

check program my_check with path "/path/to/my/script.sh arg1 arg2 arg3"
    if status != 0 for 3 cycles then alert

因此您必须编写自定义脚本来执行此操作,并根据脚本退出代码执行操作。