class SimpleWorker::SshWorker
where 'opts' is a Hash of options:
:user => String name of user on remote host (default: `whoami`) :host => String name of remote host (default: `hostname`) :port => String port to connect on the remote host (default: 22) :cmd => String bash string to execute on the remote host in the users login shell, in the remote 'dirname', and with the JOBID environment variable set to the current jobid, (default: `bundle install; rake;`) :dirname => String remote directory in the users home directory (default: dynamic jobid)
Attributes
cmd[R]
dirname[R]
host[R]
port[R]
user[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/simpleworker/ssh_worker.rb, line 18 def initialize(opts = {}) @user = opts[:user] || `whoami`.strip @host = opts[:host] || `hostname`.strip @port = opts[:port] || '22' @cmd = opts[:cmd] || 'bundle install; rake;' @dirname = opts[:dirname] end
Public Instance Methods
on_start(jobid)
click to toggle source
Destructive rsync to remote and start a process in the background on the remote server.
# File lib/simpleworker/ssh_worker.rb, line 27 def on_start(jobid) @dirname ||= jobid @jobid = jobid sync_to_remote async_cmd end
on_stop()
click to toggle source
Rsync from remote.
# File lib/simpleworker/ssh_worker.rb, line 36 def on_stop sync_from_remote end
Private Instance Methods
async_cmd()
click to toggle source
# File lib/simpleworker/ssh_worker.rb, line 50 def async_cmd `ssh -p #{port} "#{user}@#{host}" "/bin/bash -lc 'cd ~/#{dirname}; export JOBID=#{@jobid}; #{cmd}' </dev/null >/dev/null 2>&1 &"` end
sync_from_remote()
click to toggle source
# File lib/simpleworker/ssh_worker.rb, line 46 def sync_from_remote `rsync -a -e "ssh -p #{port}" "#{user}@#{host}:~/#{dirname}/" "${PWD}"` end
sync_to_remote()
click to toggle source
# File lib/simpleworker/ssh_worker.rb, line 42 def sync_to_remote `rsync -a --delete -e "ssh -p #{port}" "${PWD}/" "#{user}@#{host}:~/#{dirname}"` end