Skip to content

Instantly share code, notes, and snippets.

@funny-falcon
Created March 7, 2012 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save funny-falcon/1994439 to your computer and use it in GitHub Desktop.
Save funny-falcon/1994439 to your computer and use it in GitHub Desktop.
rainbows restart with inotifywait
export NGINX_DIR=../nginx
export LOG_DIR=$NGINX_DIR/log
export SOCK_DIR=$NGINX_DIR/socks
export APP=`basename "$(realpath "$(dirname "$0")")"`
PID_FILE=$SOCK_DIR/$APP.pid
if [ -e "$PID_FILE" ] ; then
PID=`cat $PID_FILE`
if [ -n `ps aux | awk '/rainbows/ && /$PID/ && !/awk/ {print $0}'` ] ; then
echo "Action: " $@
if [ -n "$1" ] && [ "$1" != "kill" ] ; then
case $2 in
*.sw[op]) exit ;;
esac
kill -HUP $PID
exit
else
kill $PID
sleep 1
fi
fi
fi
if [ -n "$1" ] ; then
exit
fi
rainbows -c serv_conf.rb -D
inotifywait -r -m . -e CREATE -e MODIFY -e DELETE |
grep -v -P '(.sw[op]|~|\s\d+)$' --line-buffered |
while read dir act file ; do
echo "LINE: $dir $act $file"
case $dir in
*/)
$0 $act "$dir$file"
;;
esac
done
$0 kill
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment