Created
September 1, 2014 02:59
-
-
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)
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
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