Skip to content

Instantly share code, notes, and snippets.

@bootleq
Created September 1, 2014 02:59
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 bootleq/480ea3740a7b811594a2 to your computer and use it in GitHub Desktop.
Save bootleq/480ea3740a7b811594a2 to your computer and use it in GitHub Desktop.
zsh function to restart Rails server (only support nginx server with passenger or unicorn_rails)
rtouch() {
emulate -L zsh
if [[ -d tmp ]]; then
if which passenger 2>&1 >/dev/null; then
touch tmp/restart.txt && echo 'file touched.'
elif which unicorn_rails 2>&1 >/dev/null; then
if [[ -r tmp/pids/unicorn.pid && -n $(ps h -p `cat tmp/pids/unicorn.pid` | tr -d ' ') ]]; then
kill -USR2 $(cat tmp/pids/unicorn.pid) && echo "process killed."
elif [[ -f config/unicorn.rb ]] && [[ -n $RAILS_ENV ]]; then
bundle exec unicorn_rails -D -E $RAILS_ENV -c config/unicorn.rb && echo "process started."
else
echo "ERROR: no config for unicorn_rails."
fi
else
echo 'ERROR: no "passenger" or "unicorn_rails" available.'
fi
else
echo 'ERROR: "tmp" directory not found.'
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment