Skip to content

Instantly share code, notes, and snippets.

@pivaldi
Created September 14, 2017 10:18
Show Gist options
  • Save pivaldi/761ab4cc51819936152657143bfe77cc to your computer and use it in GitHub Desktop.
Save pivaldi/761ab4cc51819936152657143bfe77cc to your computer and use it in GitHub Desktop.
How to run and monitor gitwatch with monit
#!/bin/bash
## Run gitwatch as a daemon
# $1 is the repository to monitor
# $2 is the stop/start command
# Exemple gitwatchd.sh /etc/ start
##################################
ESCAPE_1=$(printf '%q' "$1")
ESCAPE_1="${ESCAPE_1//\//}"
PID_FILE="/var/run/gitwatchd_${ESCAPE_1}.pid"
case $2 in
start)
/bin/bash -c "/usr/local/bin/gitwatch.sh $1" > /dev/null 2>&1 &
echo $! > "$PID_FILE"
;;
stop)
kill $(cat $PID_FILE) ;;
*)
echo "Usage: $0 <directory> {start|stop}" ;;
esac
exit 0
check process gitwatch with pidfile "/var/run/gitwatchd_etc.pid"
if does not exist then restart
if 2 restarts within 2 cycles then unmonitor
if cpu usage > 95% for 2 cycles then restart
start program = "/usr/local/bin/gitwatchd.sh /etc/ start"
stop program = "/usr/local/bin/gitwatchd.sh /etc/ stop"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment