Skip to content

Instantly share code, notes, and snippets.

@shoken0x
Last active June 9, 2016 06:55
Show Gist options
  • Save shoken0x/118c5ec8eaf658c7e6b6e9a882170a3b to your computer and use it in GitHub Desktop.
Save shoken0x/118c5ec8eaf658c7e6b6e9a882170a3b to your computer and use it in GitHub Desktop.
Github Webhook Server for deploy
# rails_restart.sh is simple shell program. you can get somewhere.
require 'webrick'
require 'json'
server = WEBrick::HTTPServer.new(Port: 8000, ServerType: WEBrick::Daemon)
server.mount_proc '/' do |req, res|
req_json = JSON.parse(req.body)
if req_json["ref"] == "refs/heads/master"
system "cd /path_to_rails_project && git pull && bundle exec rake assets:precompile RAILS_ENV=production && bundle install && rails_restart.sh"
end
end
trap 'INT' do server.shutdown end
server.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment