Last active
December 21, 2015 02:48
-
-
Save gdhaworth/6237137 to your computer and use it in GitHub Desktop.
A quick script to help run the Mercurial AutoSync Extension (bitbucket.org/obensonne/hg-autosync/wiki/Home) in daemon mode. This is useful for situations where someone wants to manage AutoSync's lifecycle, including stopping the service; an example might be within a virtualenv's activate script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
_echo_usage_and_abort() { | |
echo "Usage: $0 {start|stop} [interval]" | |
exit 1 | |
} | |
if [[ ! -d '.hg' ]]; then | |
cat <<EOM | |
This directory does not appear to be a mercurial repository. Try running this | |
script within the repository root (containing the .hg directory). | |
EOM | |
exit 3 | |
fi | |
if [[ -z "$1" ]]; then | |
_echo_usage_and_abort | |
fi | |
PID_FILE='.hg/mq-autosync.pid' | |
AUTOSYNC_ARGS="$AUTOSYNC_ARGS -AD --mq --pid-file $PID_FILE" | |
if [[ ! -z $2 ]]; then | |
AUTOSYNC_ARGS="$AUTOSYNC_ARGS -i $2" | |
fi | |
_kill_autosync() { | |
if [[ -f $PID_FILE ]]; then | |
PID=`cat $PID_FILE` | |
if ps -l $PID > /dev/null 2>&1 ; then | |
echo "Killing autosync, pid: $PID" | |
kill `cat $PID_FILE` | |
fi | |
rm -f $PID_FILE | |
fi | |
} | |
_start() { | |
_kill_autosync | |
hg autosync $AUTOSYNC_ARGS | |
} | |
_stop() { | |
if [[ ! -f $PID_FILE ]]; then | |
echo 'PID file does not exist, is autosync running?' | |
exit 2 | |
fi | |
_kill_autosync | |
} | |
case $1 in | |
start) | |
_start | |
;; | |
stop) | |
_stop | |
;; | |
*) | |
_echo_usage_and_abort | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment