Execute a rake task on a remote server

The physical architecture of the production environment includes several machines doing different jobs (rake tasks), all of them over the same database.

One of the jobs would do a large UPDATE over a table that usually returns a postgres deadlock if the other jobs are running.

I already have a rake task to gracefully stop the other jobs, but I can only execute it from the local machines.

What I want to achieve is:

task :big_update => :environment do
  stop_tasks_on_another_servers

  # do the SQL UPDATE
  ...
end

where the stop_tasks_on_another_servers should execute a rake task on the other servers.

My best try was to use the https://github.com/capistrano/sshkit gem. The same that Capistrano uses it, but I'm still missing a step here. I'm trying the following on a rails console in the production machine:

require 'sshkit/dsl'
hosts = ['machine1', 'machine2']

on hosts do
  within "/home/me/project/current" do
    with rails_env: :production do
      rake "stop_tasks"
    end
  end
end

But it returns:

INFO [70a0610a] Running /usr/bin/env rake stop_tasks on machine1
SSHKit::Command::Failed: rake stdout: Nothing written

What am I missing or is there an easier way to execute remote tasks?


Check out Rake Remote Task. Here is a snippet to show you how it works:

require 'rake/remote_task'

set :domain, 'abc.example.com'

remote_task :foo do
  run "ls"
end

I've had success using this approach:

http://gistflow.com/posts/372-execute-rake-task-on-remote-server-with-capistrano

链接地址: http://www.djcxy.com/p/17904.html

上一篇: JavaFX视频不能播放

下一篇: 在远程服务器上执行rake任务