I'm setting up a shared development server for a Ruby on Rails project.
Is there a good way to set it up to restart, or reload the code every time someone pushes a commit to the master branch (for example)? I don't care about setting up gems etc every time, à la Heroku - I just want to run the new code.
If there are any problems, I can go in and restart the server manually - I just don't want to do it every time.
In the post-receive hook, you'll most likely need to grep for the Ruby PID, kill that process and then restart the Rails server.
Git Hooks is what you're looking for.
Using these, you can run custom commands based on certain conditions.
Create a file named post-commit
under your .git/hooks
folder like so:
#!/bin/sh
exec rake deploy
and in your Rakefile,
task :deploy do
pid = IO.open("ps").grep(/script\/rails/) { |x| x.split(" ").first }.first
sh "kill -9 #{pid}"
sh "rails s"
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.