deploy.rb revision 1d1e50759ebe381f296f9cfbec532aea24af0874
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainenrequire 'bundler/capistrano'
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen# RVM
5ab2ee0b9b7ad3867fcfd2a31fda0790370fbbbdTimo Sirainen$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainenrequire 'rvm/capistrano'
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenset :rvm_ruby_string, '1.9.3@ontohub'
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
0371406d952fe51367c7be91703e5634b7d9d225Timo Sirainenhostname = 'ontohub.orgizm.net'
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
06b0c3be9905099038964b068216bbed155701deTimo Sirainenset :application, 'ontohub'
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenset :scm, :git
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenset :repository, "git@github.com:digineo/#{application}.git"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenset :deploy_to, "/srv/http/#{hostname}"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
06b0c3be9905099038964b068216bbed155701deTimo Sirainenset :user, application
06b0c3be9905099038964b068216bbed155701deTimo Sirainenset :use_sudo, false
06b0c3be9905099038964b068216bbed155701deTimo Sirainenset :deploy_via, :remote_cache
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainenrole :app, hostname
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainenrole :web, hostname
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainenrole :db, hostname, :primary => true
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainennamespace :deploy do
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen desc "Restart Application"
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen task :restart, :roles => :app, :except => { :no_release => true } do
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen run "touch #{current_path}/tmp/restart.txt"
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen end
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen desc "Symlink newrelic configuration"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen task :symlink_newrelic, :roles => :app, :except => { :no_release => true } do
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen run "ln -nfs #{shared_path}/config/newrelic.yml #{current_path}/config/"
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen end
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenend
57ca8cc86193103127066c724815e7e7a24926dbTimo Sirainen
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainennamespace :resque do
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen def rake_command(cmd)
8d80659e504ffb34bb0c6a633184fece35751b18Timo Sirainen run "cd #{current_path} && bundle exec rake #{cmd}", :env => { :RAILS_ENV => rails_env }
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen end
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen desc "Stop resque"
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen task :stop do
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen rake_command 'resque:stop'
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen end
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainenend
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen# https://makandracards.com/makandra/1431-resque-+-god-+-capistrano
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainennamespace :god do
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen def god_is_running
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen !capture("#{god_command} status >/dev/null 2>/dev/null || echo 'not running'").start_with?('not running')
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen end
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen def god_command
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen "cd #{current_path}; bundle exec god"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen end
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen desc "Start god"
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen task :start do
6bca3405636e3ec95724350c3a10d6fcb737782aTimo Sirainen run "#{god_command} -c config/god/app.rb", :env => environment = { :RAILS_ENV => rails_env }
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen end
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen desc "Stop god"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen task :stop do
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen if god_is_running
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen run "#{god_command} terminate"
6c2c5f20760b06bfb4a40b0ee2ef5ab016bc41f0Timo Sirainen end
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen end
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen
dc9de21d4375faeedbe5b7e941502ac578650da9Timo Sirainen desc "Test if god is running"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainen task :status do
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainen puts god_is_running ? "God is running" : "God is NOT running"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainen end
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainenend
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainen
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainenbefore "deploy:update", "god:stop"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainenbefore "deploy:update", "resque:stop"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainenafter "deploy:update", "god:start"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainenafter "deploy:update", "deploy:symlink_newrelic"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainenafter :deploy, "deploy:cleanup"
7d075009a641d88a45940238676883a8eaf1507bTimo Sirainen
bfdf0fd7b6186f64cbdcbf1cb2bf9c42a9007b77Timo Sirainen