Created
March 22, 2011 21:35
-
-
Save falsefalse/882129 to your computer and use it in GitHub Desktop.
manage mongrel in development enviroment
This file contains hidden or 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
This file contains hidden or 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
function mongrel() { | |
logfile="log/mongrel.log" | |
pidfile="tmp/pids/mongrel.pid" | |
if [ -f $pidfile ]; then | |
pid=`cat $pidfile` | |
fi | |
case "$1" in | |
start) | |
if [ -f $pidfile ]; then | |
echo "mongrel is running, PID $pid" | |
else | |
ruby script/server -d | |
fi | |
;; | |
stop) | |
if [ -f $pidfile ]; then | |
kill -9 $pid | |
rm $pidfile | |
echo "mongrel with PID $pid was killed." | |
else | |
echo "mongrel is not running" | |
fi | |
;; | |
restart) | |
mongrel stop && mongrel start | |
;; | |
log) | |
if [ -f $logfile ]; then | |
tail -f --lines=80 $logfile | |
fi | |
;; | |
average) | |
if [ -f $logfile ]; then | |
grep "Completed in" $logfile | sed -s "s/Completed in \([0-9]\+\)ms.\+/\1/" > times | |
cat times | awk 'BEGIN {sum = 0} {sum += $1} END {printf("%.2fms (total: %d reqs)\n", sum/NR, NR)}' | |
rm times | |
fi | |
;; | |
esac | |
} | |
# autocomplete | |
# as described here http://www.debian-administration.org/article/An_introduction_to_bash_completion_part_2 | |
_mongrel() | |
{ | |
local cur prev opts | |
COMPREPLY=() | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts="log start stop restart average" | |
if [[ ${cur} == * ]] ; then | |
COMPREPLY=( $(compgen -W "${opts}" ${cur}) ) | |
return 0 | |
fi | |
} | |
complete -F _mongrel mongrel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment