From 812ce4d302f37acd368dd5c39e5c9b34d8e6e6cd Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 15 Nov 2022 00:02:44 +0100 Subject: gitolite: add git-fsck script --- roles/gitolite/base/templates/git-fsck.sh.j2 | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 roles/gitolite/base/templates/git-fsck.sh.j2 (limited to 'roles/gitolite/base/templates/git-fsck.sh.j2') diff --git a/roles/gitolite/base/templates/git-fsck.sh.j2 b/roles/gitolite/base/templates/git-fsck.sh.j2 new file mode 100644 index 00000000..05ac6bfb --- /dev/null +++ b/roles/gitolite/base/templates/git-fsck.sh.j2 @@ -0,0 +1,39 @@ +#!/bin/bash + +INST="$1" +if [ -z "$1" ]; then + echo "Usage: $0 " + exit 1 +fi + +REPOS_D="{{ gitolite_base_path }}/$INST/repositories" +if [ ! -d "$REPOS_D" ]; then + echo "instance $INST not found." + exit 2 +fi + +repos=$(find $REPOS_D -type d -name '*.git') + +declare -A results +for repo in $repos; do + echo "*** $repo ***" + git --bare --git-dir "$repo" fsck --full --strict --root + results[$repo]=$? + echo "" +done + +if [ -d "/var/lib/prometheus-node-exporter/textfile-collector/" ]; then + echo "reporting results to prometheus" + { + echo "# HELP git_fsck_run Last time git-fsck has been run." + echo "# TYPE git_fsck_run gauge" + echo "git_fsck_run{gitolite_instance=\"$INST\"} $(date +"%s")" + echo "" + echo "# HELP git_fsck_failed Result of git-fsck (0 means OK)." + echo "# TYPE git_fsck_failed gauge" + for repo in "${!results[@]}"; do + repo_name=$(realpath --relative-to "$REPOS_D" "$repo") + echo "git_fsck_failed{repository=\"$repo_name\",gitolite_instance=\"$INST\"} ${results[$repo]}" + done + } | sponge "/var/lib/prometheus-node-exporter/textfile-collector/git-fsck-$INST.prom" +fi -- cgit v1.2.3