Here is a quick alias to restart a rails server only when necessary. This would be great for a crontab or other recurring job.
Copy/pasta ALL the aliases from coderwall!
alias .restart="git status | grep 'nothing to commit' && git fetch origin && git diff HEAD..origin/master | grep '' -c | grep 0 -xvc && git pull && bundle install && touch tmp/restart.txt && echo \"\nComplete\n========\n\" || echo \"\nNo Work Needed\n==============\""
Amazing! How does it work?
First it checks to make sure the working directory is clean, we don't want to do any pulls/merges when somebody is working on the staging server.
git status | grep 'nothing to commit'
Next, it fetches origin, and checks if there are actually any chances that require a server restart.
git fetch origin && git diff HEAD..origin/master | grep '' -c | grep 0 -xvc
Lastly, a pull, bundle install, and restart the server.
git pull && bundle install && touch tmp/restart.txt
I also added some ending messages to tell us if this completed successfully or no work was needed.
echo "\nComplete\n========\n" || echo "\nNo Work Needed\n=============="